Signal frequency measurement method, device and distance detection equipment based on FPGA chip
By using FPGA chips in electronic design systems for signal frequency measurement, the problems of MCU resource consumption and low accuracy are solved, high-precision distance detection is achieved, and hardware wiring and control systems are simplified.
Patent Information
- Application Number
- CN202410764300.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-14
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-06-14
AI Technical Summary
In the existing technology, the frequency calculation used for detection devices in electronic design systems consumes a large amount of MCU resources and has low accuracy, making it impossible to achieve high-precision distance detection.
Using the signal frequency measurement method based on FPGA chip, the waveform to be measured of the detection signal is received through the FPGA chip, multiple sampling measurements are performed based on the FPGA sampling clock, multiple measurement frequencies are obtained, and the frequency of the detection signal is calculated through mean filtering, which improves Measurement accuracy.
There is no need to occupy controller resources, which improves the accuracy of the waveform to be measured, realizes high-precision distance detection, simplifies the wiring of the hardware measurement circuit, and improves the control accuracy of integrated detection.
Smart Images

Figure CN118348970B
Abstract
Description
Technical Field
[0001] The present application belongs to the field of industrial control technology, and more specifically, relates to a signal frequency measurement method, device and distance detection equipment based on FPGA chip. Background Art
[0002] In the electronic design system, the detection device will eventually be reflected in the processing chip in the form of a digital frequency signal through circuit conversion. The frequency value reflects the distance between the detection device and the workpiece. When the frequency value is relatively small, the metal probe of the detection device is close to the workpiece. When the frequency value is relatively large, the metal probe of the detection device is far away from the workpiece. In the electronic system, the MCU timer is used to calculate the frequency of the hardware detection signal, which consumes a lot of MCU resources and the calculated frequency value has low accuracy. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a signal frequency measurement method, device and distance detection equipment based on an FPGA chip, aiming to solve the technical problem of insufficient detection accuracy in the prior art.
[0004] To achieve the above-mentioned purpose, according to one aspect of the present application, a signal frequency measurement method based on an FPGA chip is provided, comprising: receiving a waveform to be measured of a detection signal of a detection device detected by a hardware measurement circuit through an FPGA chip; performing multiple sampling measurements on the waveform to be measured based on the FPGA sampling clock to obtain multiple measurement frequencies of the detection signal; and obtaining the frequency of the detection signal based on mean filtering of the multiple measurement frequencies.
[0005] Optionally, the sampling and measuring of the waveform to be measured multiple times based on the FPGA sampling clock to obtain multiple measurement frequencies of the detection signal includes: synchronizing the waveform to be measured with the FPGA sampling clock; and sampling and measuring the synchronized waveform to be measured multiple times based on the FPGA sampling clock to obtain multiple measurement frequencies of the detection signal.
[0006] Optionally, the synchronization processing of the waveform to be measured and the FPGA sampling clock includes: taking the rising edge of the FPGA sampling clock as a reference, synchronizing the rising edge and falling edge of the waveform to be measured to the rising edge of the closest FPGA sampling clock to obtain the synchronized waveform to be measured.
[0007] Optionally, the waveform to be measured after synchronization is sampled multiple times based on the FPGA sampling clock to obtain multiple measurement frequencies of the detection signal, including: obtaining a capture enable signal; counting the waveform to be measured and the FPGA sampling clock respectively within a valid period of the capture enable signal, and calculating the measurement frequency of the detection signal according to the counting result; repeating the measurement multiple times to obtain the multiple measurement frequencies of the detection signal.
[0008] Optionally, the waveform to be measured and the FPGA sampling clock are counted respectively within a valid period of the capture enable signal, and the measurement frequency of the detection signal is calculated based on the counting results, including: using a measurement waveform counter to count the rising edges of the synchronized waveform to be measured within a valid period of the capture enable signal to obtain first counting data; using a sampling counter to count the rising edges of the FPGA sampling clock within a valid period of the capture enable signal to obtain second counting data; and calculating the measurement frequency of the detection signal based on the frequency of the FPGA sampling clock, the first counting data and the second counting data.
[0009] Optionally, calculating the measurement frequency of the detection signal according to the frequency of the FPGA sampling clock, the first count data, and the second count data includes: calculating the measurement frequency of the detection signal according to the frequency of the FPGA sampling clock, the first count data, and the second count data by applying the following relationship:
[0010]
[0011] in, For the second counting data, is the first counting data.
[0012] Optionally, obtaining the frequency of the detection signal by mean filtering based on the multiple measurement frequencies includes: comparing the multiple measurement frequencies, removing the maximum value, the second largest value, the minimum value and the second smallest value among the multiple measurement frequencies; and performing mean filtering on the remaining multiple measurement frequencies to obtain the frequency of the detection signal.
[0013] Optionally, after obtaining the frequency of the detection signal by filtering the multiple measured frequencies, the method further comprises: feeding back the frequency of the detection signal to a numerical control system to determine the distance between the detection device and the workpiece to be cut according to the frequency of the detection signal.
[0014] To achieve the above-mentioned purpose, according to another aspect of the present application, a detection signal frequency measurement device based on an FPGA chip is provided, comprising: a hardware measurement circuit and at least one FPGA chip, the FPGA chip comprising a sampling measurement circuit and a mean filtering circuit; wherein the hardware measurement circuit is used to detect the waveform to be measured of the detection signal of the detection device; the sampling measurement circuit is used to perform multiple sampling measurements on the waveform to be measured based on the FPGA sampling clock to obtain multiple measurement frequencies of the detection signal; the mean filtering circuit is used to perform mean filtering according to the multiple measurement frequencies to obtain the frequency of the detection signal.
[0015] To achieve the above-mentioned purpose, according to another aspect of the present application, a distance detection device is provided, including a detection device, a numerical control system and the aforementioned FPGA chip-based detection signal frequency measurement device.
[0016] The beneficial effect of the signal frequency measurement method based on FPGA chip provided by the present application is that: compared with the prior art, the signal frequency measurement method based on FPGA chip provided by the present application adopts the architecture of FPGA chip, does not need to occupy the resources of the controller, and synchronizes the waveform to be measured based on the sampling clock of FPGA chip, thereby improving the accuracy of the waveform to be measured and realizing the integration of control and detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical features of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0018] Figure 1 A schematic diagram of a flow chart of a signal frequency measurement method based on an FPGA chip provided in an embodiment of the present application;
[0019] Figure 2 A schematic diagram of synchronous processing of a waveform to be measured provided in an embodiment of the present application;
[0020] Figure 3 A waveform counting schematic diagram of a waveform to be measured provided in an embodiment of the present application;
[0021] Figure 4 An example diagram of frequency measurement of a waveform to be measured provided in an embodiment of the present application;
[0022] Figure 5 A schematic diagram of the structure of a detection signal frequency measurement device based on an FPGA chip provided in an embodiment of the present application;
[0023] Figure 6A schematic diagram of the structure of a distance detection device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0024] In order to have a clearer understanding of the technical features, purposes and effects of the present application, the specific implementation methods of the present application are further described in detail below in conjunction with the accompanying drawings and Examples. The following examples are only used to illustrate the present application, but are not used to limit the scope of protection of the present application. Based on the embodiments of the present application, other embodiments obtained by those skilled in the art without paying creative work should all belong to the scope of protection of the present application.
[0025] In the description of the present application, it should be noted that the terms "upper", "lower", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present application.
[0026] In the description of this application, it should be understood that the numbers in this document, such as "first", "second", etc., are only used to distinguish the objects described, have no sequential or technical meaning, and cannot be understood as stipulating or implying the importance of the objects described.
[0027] In the description of this application, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to specific circumstances.
[0028] In the description of this application, the term "plurality" refers to two or more than two. In addition, the term "and / or" is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0029] In the description of this application, it should be noted that, unless otherwise defined, all technical and scientific terms used in this application have the same meaning as those commonly understood by those skilled in the art. The terms used in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application. For those of ordinary skill in the art, the specific meanings of the above terms in this application can be understood by specific circumstances.
[0030] Reference Figure 1 In order to solve the above problems, according to one aspect of the present application, an embodiment of the present application provides a signal frequency measurement method based on an FPGA chip, which is applied to an FPGA chip. The signal frequency measurement method based on an FPGA chip includes:
[0031] Step S11: receiving the waveform to be measured of the detection signal of the detection device detected by the hardware measurement circuit through the FPGA chip.
[0032] In the embodiment of the present application, the hardware measurement circuit is a hardware measurement sensor circuit, which includes a sensor for detecting the waveform to be measured of the detection signal of the detection device, such as a follow-up sensor. After signal conversion, the hardware measurement circuit obtains a regular square wave with a duty cycle of 60%, which is the waveform to be measured, and the frequency is about 1.4~2.5MHZ.
[0033] Step S12: performing multiple sampling measurements on the waveform to be measured based on the FPGA sampling clock to obtain multiple measurement frequencies of the detection signal.
[0034] In the embodiment of the present application, the Field-Programmable Gate Array (FPGA) is a device for parallel data calculation, and the standard for parallel data processing is based on the rising edge of each clock cycle. There are different BANKs (processing groups) on the FPGA, and each BANK can process data independently. In the hardware design of the FPGA chip, the waveform to be measured is input through the FPGA global clock network pin. This design is to ensure that the path length of the waveform to be measured to reach the corresponding BANK is the shortest and equal during the chip processing process. In this way, no matter how complex the designed circuit is, the data obtained by the FPGA algorithm is relatively accurate.
[0035] In step S12, optionally, the waveform to be measured is first synchronized with the FPGA sampling clock. Figure 2As shown, taking the rising edge of the FPGA sampling clock as the reference, the rising edge and falling edge of the waveform to be measured are synchronized to the rising edge of the closest FPGA sampling clock, and the time of the rising edge of the closest FPGA sampling clock is later than the time of the rising edge and falling edge of the corresponding waveform to be measured, so as to obtain the synchronized waveform to be measured (this can effectively improve the distinction between different bands in the synchronized waveform to be measured, and the spacing between adjacent bands of the waveform to be measured is greater than the single sampling time of the FPGA sampling clock, so as to improve the identifiability of the synchronized waveform to be measured). Since the rising edge of the clock is used as the reference in the FPGA, the waveform to be measured after FPGA synchronization will be inconsistent with the actual waveform. Although the waveform to be measured will be shaped and the duty cycle of the waveform will change, it does not affect the frequency value of the waveform to be measured. By converting the waveform to be measured of the detection signal according to the FPGA sampling clock, the recognition rate of the FPGA chip for the level change of the converted detection signal waveform can be improved.
[0036] Since the rising edge of the waveform to be measured may be missed during the synchronization process, this may cause errors in the calculation of the frequency value of the subsequent detection signal. In this embodiment, the rising edge and the falling edge of the signal to be measured are synchronously processed at the same time, and the positions of the rising edge and the falling edge of the waveform to be measured after synchronization in the waveform to be measured are confirmed. If the rising edge and the falling edge of the waveform to be measured appear alternately, it is confirmed that the waveform to be measured after synchronization is accurate, otherwise it is confirmed that the rising edge or the falling edge of the waveform to be measured has missed synchronization.
[0037] Furthermore, the change in the duty cycle of the waveform to be measured after synchronization can also be detected here. If the duty cycle of the waveform to be measured changes by more than 100%, such as the original 2:1 changes to 5:1, it is possible that there is a synchronization omission on the rising edge or falling edge of the waveform to be measured. The system can mark the abnormal duty cycle area of the waveform to be measured to facilitate the user to check for synchronization omissions.
[0038] After the waveform to be measured is synchronized, the synchronized waveform to be measured is sampled and measured multiple times based on the FPGA sampling clock to obtain multiple measurement frequencies of the detection signal. Optionally, a capture enable signal is obtained; the waveform to be measured and the FPGA sampling clock are counted respectively within a valid period of the capture enable signal, and the measurement frequency of the detection signal is calculated according to the counting result; the measurement is repeated multiple times to obtain multiple measurement frequencies of the detection signal.
[0039] When performing a single measurement, the rising edge of the synchronized waveform to be measured is counted using the measurement waveform counter within a valid period of the capture enable signal to obtain the first count data; the rising edge of the FPGA sampling clock is counted using the sampling clock counter within a valid period of the capture enable signal to obtain the second count data; the measurement frequency of the detection signal is calculated according to the frequency of the FPGA sampling clock, the first count data and the second count data. Figure 3 As shown, the FPGA generates a capture enable signal of about 800us in a period of 1ms. When the capture enable signal is valid, a sampling clock counter is set to add one to the sampling clock. When the capture enable signal fails, a data X is obtained. At the same time, a measurement waveform counter is set to add one to the rising edge of the waveform to be measured. When the capture enable signal fails, a data Y is obtained.
[0040] Since the frequencies of data X and data Y are measured synchronously by the sampling clock of the FPGA, it avoids the mis-collection or missed collection caused by the asynchronism between data Y and the sampling clock of the FPGA, so the measurement frequency of data Y is calculated with high accuracy.
[0041] Furthermore, a measurement waveform counter can also be used here to count the falling edges of the synchronized waveform to be measured within a valid period of the capture enable signal to obtain third counting data. In principle, the difference between the third counting data and the first counting data within a valid period of the capture enable signal should be less than or equal to 1. If the difference between the third counting data and the corresponding first counting data is greater than 1, the user needs to review the first counting data and the third counting data to avoid missed operations of the measurement waveform counter.
[0042] In this implementation, for the sake of measurement stability, 8 such calculation methods are built inside the FPGA. In actual design, these 8 modules are not started at the same time, but each module is started at intervals to facilitate filtering by subsequent modules. Figure 4 As shown, the calculation modules 1-8 start the frequency measurement of the waveform to be measured at intervals to obtain 8 measurement frequencies.
[0043] In this embodiment, the enable signal is captured in order to determine the time area where the detection signal waveform needs to be calculated. The sampling clock counter is a standard timer generated by the FPGA sampling clock. The frequency of the standard timer is the standard frequency of the FPGA sampling clock or its multiples, 200Mhz or 100Mhz, etc., and then a measurement waveform counter is used to obtain the number of waveform changes of the detection signal waveform after conversion in the enable signal area. Since the detection signal waveform is converted here, the level change points calculated by the measurement waveform counter are all located at the electrical frequency change points of the sampling clock counter, so that the subsequent frequency calculation will be more accurate.
[0044] By counting the above-mentioned frequency change points, the sampling clock data X and the waveform data Y to be measured are obtained, and the frequency F of the clock to be measured is calculated using the following equation. Specifically, the measurement frequency of the detection signal is calculated using the following relationship based on the frequency of the FPGA sampling clock, the first count data, and the second count data:
[0045]
[0046] in, is the second counting data, is the first counting data.
[0047] Through this equation, the measurement frequency of the waveform to be measured can be obtained. At the same time, the measurement frequencies calculated by different calculation modules in different time periods can be used to calculate the accurate measurement frequency of the detection signal.
[0048] Step S13: Filter the multiple measured frequencies by average value to obtain the frequency of the detection signal.
[0049] At the same time, in the FPGA code design, each calculation module calculates the measurement frequency and starts the following process to obtain the real-time frequency value: compare multiple measurement frequencies, remove the maximum value, the second largest value, the minimum value and the second smallest value among the multiple measurement frequencies; perform mean filtering on the remaining multiple measurement frequencies to obtain the frequency of the detection signal. For example, 8 measurement frequencies are obtained, the 8 measurement frequencies are compared, the maximum value, the second largest value, the minimum value and the second smallest value are removed, and the remaining 4 measurement frequencies are average filtered to obtain the actual measurement frequency value. After obtaining the real-time frequency value, the FPGA feeds the frequency back to the CNC system CNC through the internal bus. The frequency of the detection signal is fed back to the CNC system to determine the distance between the detection device and the cut workpiece according to the frequency of the detection signal.
[0050] In summary, the embodiment of the present invention realizes a module with the function of detecting distance and feedback through hardware optimization. Moreover, the FPGA chip architecture is adopted, which does not need to occupy the resources of the controller, and at the same time improves the accuracy of the detected waveform. In addition, the numerical control system and the hardware measurement circuit are integrated, and the control and detection are integrated without changing the old system architecture, and the wiring is simpler than the hardware measurement circuit on the market.
[0051] In order to solve the above problem, according to another aspect of the present application, an embodiment of the present application provides a detection signal frequency measurement device based on an FPGA chip, such as Figure 5As shown, the detection signal frequency measurement device includes: a hardware measurement circuit and at least one FPGA chip, and the FPGA chip includes a sampling measurement circuit and a mean filter circuit. Among them, the hardware measurement circuit is used to detect the waveform to be measured of the detection signal of the detection device; the sampling measurement circuit is used to perform multiple sampling measurements on the waveform to be measured based on the FPGA sampling clock to obtain multiple measurement frequencies of the detection signal; the mean filter circuit is used to perform mean filtering according to the multiple measurement frequencies to obtain the frequency of the detection signal.
[0052] In order to solve the above problem, according to another aspect of the present application, an embodiment of the present application provides a distance detection device, such as Figure 6 As shown, the distance detection equipment includes a detection device, a numerical control system and the aforementioned detection signal frequency measurement device based on the FPGA chip. After signal conversion, the hardware measurement circuit obtains a regular square wave with a duty cycle of 60%, and a waveform to be measured with a frequency of approximately 1.4~2.5MHZ. The FPGA chip is responsible for calculating the real-time frequency value of the waveform to be measured, and at the same time, the data is transmitted to the numerical control system CNC by filtering. The algorithm used in the embodiment of the present application to calculate the frequency value of this waveform is a median equal precision measurement algorithm. In the numerical control system CNC, the calculated frequency value is subjected to a linear relationship between the distance between the plates and the frequency. After obtaining the relationship expression, the real-time frequency value can be used as a feedback height value as the distance between the detection device and the workpiece to be cut.
[0053] The above is only a preferred implementation of the present application, but the protection scope of the present application is not limited thereto. It should be pointed out that for those skilled in the art, several equivalent obvious variations and / or equivalent replacements can be made without departing from the technical principles of the present application. These obvious variations and / or equivalent replacements should also be regarded as the protection scope of the present application.
Claims
1. A signal frequency measurement method based on FPGA chip, characterized in that: The method comprises: Receiving the waveform to be measured of the detection signal of the detection device detected by the hardware measurement circuit through the FPGA chip; Taking the rising edge of the FPGA sampling clock as a reference, the rising edge and the falling edge of the waveform to be measured are synchronized to the rising edge of the closest FPGA sampling clock, and the time of the rising edge of the closest FPGA sampling clock is later than the time of the rising edge and the falling edge of the corresponding waveform to be measured, so as to obtain the synchronized waveform to be measured; the synchronized waveform to be measured will be inconsistent with the actual waveform; the level change points calculated by the subsequent measurement waveform counter are all located at the electrical frequency change points of the sampling clock counter; Get the capture enable signal; Using a measurement waveform counter to count rising edges of the synchronized waveform to be measured within a valid period of the capture enable signal to obtain first counting data; Using a sampling counter to count rising edges of the FPGA sampling clock within a valid period of the capture enable signal to obtain second counting data; Calculating the measurement frequency of the detection signal according to the frequency of the FPGA sampling clock, the first counting data and the second counting data; Repeating the measurement multiple times to obtain multiple measurement frequencies of the detection signal; The frequency of the detection signal is obtained by filtering the multiple measured frequencies by average value.
2. The signal frequency measurement method according to claim 1, characterized in that: The calculating the measurement frequency of the detection signal according to the frequency of the FPGA sampling clock, the first counting data and the second counting data comprises: The measurement frequency of the detection signal is calculated by applying the following relationship according to the frequency of the FPGA sampling clock, the first counting data, and the second counting data: in, For the second counting data, is the first counting data.
3. The signal frequency measurement method according to claim 1, characterized in that: The step of obtaining the frequency of the detection signal according to the mean filtering of the plurality of measurement frequencies comprises: Comparing the plurality of measurement frequencies, and removing the maximum value, the second largest value, the minimum value, and the second smallest value among the plurality of measurement frequencies; The remaining multiple measurement frequencies are subjected to mean filtering to obtain the frequency of the detection signal.
4. The signal frequency measurement method according to claim 1, characterized in that: After obtaining the frequency of the detection signal by filtering the plurality of measured frequencies by average, the method includes: The frequency of the detection signal is fed back to the numerical control system to determine the distance between the detection device and the workpiece to be cut according to the frequency of the detection signal.
5. A detection signal frequency measurement device based on FPGA chip, characterized in that: The detection signal frequency measurement device comprises: a hardware measurement circuit and at least one FPGA chip, wherein the FPGA chip comprises a sampling measurement circuit and a mean filter circuit; wherein, The hardware measurement circuit is used to detect the waveform to be measured of the detection signal of the detection device; The sampling measurement circuit is used to synchronize the rising edge and falling edge of the waveform to be measured to the rising edge of the closest FPGA sampling clock with the rising edge of the FPGA sampling clock as a reference, so as to obtain the synchronized waveform to be measured; the synchronized waveform to be measured will be inconsistent with the actual waveform; the level change points calculated by the subsequent measurement waveform counter are all located at the electrical frequency change points of the sampling clock counter; obtain a capture enable signal; use the measurement waveform counter to count the rising edge of the synchronized waveform to be measured within a valid period of the capture enable signal to obtain first counting data; use the sampling counter to count the rising edge of the FPGA sampling clock within a valid period of the capture enable signal to obtain second counting data; calculate the measurement frequency of the detection signal according to the frequency of the FPGA sampling clock, the first counting data and the second counting data; repeat the measurement multiple times to obtain multiple measurement frequencies of the detection signal; The mean filter circuit is used for performing mean filtering according to the plurality of measurement frequencies to obtain the frequency of the detection signal.
6. A distance detection device, characterized in that: The distance detection device comprises a detection device, a numerical control system and the detection signal frequency measurement device based on the FPGA chip as claimed in claim 5.
