A filtering method and a pulse width measurement method for pulse width measurement
By determining the frequency stability of pulse signals through filtering methods, correcting the pulse width, and outputting it in real time, the problems of accuracy and timeliness in pulse signal measurement in motor control are solved, and accurate measurement of high-frequency, high-duty-cycle signals is realized.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUADA SEMICON CO LTD
- Filing Date
- 2021-12-10
- Publication Date
- 2026-06-12
Smart Images

Figure CN116260432B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to pulse width capture technology, and particularly to a filtering method and a pulse width measurement method for pulse width measurement. Background Technology
[0002] In motor control, PWM (Pulse Width Modulation) is commonly used for speed regulation, such as in refrigerators, air conditioners, and fans where speed control is required. The principle of PWM speed regulation lies in capturing the width of the speed regulation pulse using Pulse Width Capture (PWC) technology. This captured pulse width is then converted into a speed command to control the motor to run at the specified speed. Pulse Width Capture is a method for measuring the width and period of an externally input pulse. It uses a microcontroller to capture the width information of the input pulse signal. During PWM speed regulation, when the width of the input pulse signal changes, the pulse width captured by the microcontroller changes accordingly. Converting different pulse widths into corresponding speed information achieves PWM speed regulation. Therefore, the accuracy of PWC is particularly important for PWM speed regulation. However, limited by microcontroller performance and noise, when the speed regulation pulse has characteristics of high frequency, high duty cycle, or low duty cycle, it is often difficult to accurately determine the pulse width without replacing it with a higher-performance microcontroller, thus affecting the system's speed control.
[0003] To address this issue, filtering is currently the most common method used to process the measured pulse width data and reduce the impact of noise. The most frequently used filtering method is averaging. Averaging filters calculate the arithmetic mean of pulse widths measured over a period of time. This method is fast, efficient, and computationally inexpensive, and can reduce the impact of noise to some extent. However, when a measurement is severely affected by noise, the pulse width value obtained through arithmetic averaging will also be affected, resulting in a large error and thus an incorrect speed control signal. Furthermore, the arithmetic averaging method filters data over a period of time, which presents a time-sensitivity issue. Summary of the Invention
[0004] To address all or part of the problems in existing technologies, and in order to eliminate the influence of noise on pulse width measurement, this invention provides a filtering method for pulse width measurement, comprising:
[0005] Determine whether the frequency of the pulse signal is stable within the first specified time period:
[0006] If stable, the pulse width value is corrected based on the real-time period width, real-time high-level width, and real-time low-level width obtained from the real-time measurement of the pulse signal. The signal state of the pulse signal is then determined based on the corrected pulse width value, where the signal state includes three types: all high, all low, and normal. The number of these three signal states within a second specified time period is then counted, and the state with the most occurrences is determined as the real-time signal state.
[0007] If unstable, the real-time signal state is determined based on the level of the input pin used to capture the signal within the third specified time period; and
[0008] The output pulse width value is determined based on the real-time signal status.
[0009] Furthermore, the filtering method also includes setting two arrays of the same length:
[0010] The first array is used to store real-time signal states; and
[0011] The second array is used to store the corrected pulse width value corresponding to the real-time signal state.
[0012] Further, determining whether the frequency of the pulse signal is stable within the first specified time period includes:
[0013] For each measurement, the difference between the real-time cycle width obtained from the previous measurement and the real-time cycle width obtained from the current measurement is calculated;
[0014] Compare the difference with a preset error threshold:
[0015] If the difference is less than the preset error threshold, the signal frequency stability count is incremented by one; and
[0016] If the difference is greater than or equal to the preset error threshold, the signal frequency stability count value is decremented by one.
[0017] If the signal frequency stability count value is greater than the specified value within the first specified time period, then the frequency of the pulse signal is stable; otherwise, the frequency of the pulse signal is unstable.
[0018] Furthermore, the preset error threshold is determined based on the real-time cycle width obtained from this measurement and the preset frequency stability error coefficient.
[0019] Furthermore, the pulse width correction includes:
[0020] If the average low-level width is less than the average period width minus the measurement error, and the average high-level width is greater than the average period width plus the measurement error, then the corrected pulse width is equal to the real-time period width minus the real-time low-level width.
[0021] If the average low-level width is greater than the average period width plus the measurement error, and the average high-level width is less than the average period width minus the measurement error, then the corrected pulse width is equal to the real-time high-level width.
[0022] If the average low-level width is greater than or equal to the average period width minus the measurement error, and less than or equal to the average period width plus the measurement error, then the corrected pulse width is equal to the real-time period width minus the real-time low-level width.
[0023] If the average high-level width is greater than or equal to the average period width minus the measurement error, and less than or equal to the average period width plus the measurement error, then the corrected pulse width is equal to the real-time high-level width; and
[0024] If none of the above conditions are met, then continuously read the capture pulse width level a specified number of times:
[0025] If all are high, the corrected pulse width value is equal to the average high-level width.
[0026] as well as
[0027] If all are low, the corrected pulse width value is equal to 0.
[0028] Furthermore, the measurement error value is determined based on the average value of the period width and a preset measurement error coefficient.
[0029] Furthermore, determining the signal state of the measured pulse based on the corrected pulse width value includes:
[0030] If the corrected pulse width value is less than the minimum measurement width, the signal state is all low;
[0031] If the corrected pulse width value is greater than the maximum measurement width, the signal state is full height; and
[0032] If the corrected pulse width value is greater than or equal to the minimum measurement width and less than or equal to the maximum measurement width, then the signal status is normal.
[0033] Furthermore, the minimum measurement width is determined based on the average low-level width and the minimum measurement width coefficient; and
[0034] The maximum measurement width is determined based on the average high-level width and the maximum measurement width coefficient.
[0035] Furthermore, determining the real-time signal state based on the level of the input pin used to capture the signal within the third specified time period includes:
[0036] If the level of the input pin used for capturing is high throughout the third specified time period, then the real-time signal state is all high; otherwise...
[0037] The real-time signal status is all low.
[0038] Further, determining the output pulse width value based on the real-time signal state includes:
[0039] If the real-time signal status is all low, the output pulse width value is 0;
[0040] If the real-time signal state is all high, the output pulse width value is the average of the period width; and
[0041] If the real-time signal status is normal, the output pulse width value is the average of the pulse width values after correction for all pulses with normal signal status within the fifth specified time period.
[0042] Based on the above filtering method, another aspect of the present invention provides a method for pulse width measurement, comprising:
[0043] Real-time measurement of pulse period width, low-level width, and high-level width; and
[0044] The output pulse width value is obtained by filtering according to the aforementioned filtering method.
[0045] Furthermore, the period width, low-level width, and high-level width of the real-time measurement pulse include:
[0046] Set the microcontroller's pulse width measurement mode to period width measurement and measure the real-time period width;
[0047] Set the microcontroller's pulse width measurement mode to high-level width measurement and measure the real-time high-level width; and
[0048] Set the microcontroller pulse width measurement mode to low-level width measurement and measure the real-time low-level width.
[0049] Furthermore, the present invention also provides a microcontroller capable of performing the pulse width measurement method and filtering method as described above.
[0050] This invention provides a filtering method and a pulse width measurement method for pulse width measurement. Employing a purely software approach, it primarily uses pulse signal width data obtained from chip measurements. Based on the signal state within a specified time period, it corrects the real-time pulse signal width data. Then, it determines the signal state and uses a queue to record the pulse signal state information and corresponding corrected pulse width values over a continuous period. Finally, it determines the true state of the signal based on the recorded state information and uses the corrected pulse width data corresponding to that signal state in the queue to calculate the current pulse width, thus achieving signal filtering and pulse width measurement. This filtering method improves measurement accuracy and enhances anti-interference capabilities without requiring a higher-performance microcontroller, making it particularly suitable for pulse width measurement of high-frequency, high-duty-cycle, and low-duty-cycle pulse signals. Furthermore, the pulse width measurement method provides real-time output, offering superior timeliness. Simultaneously, the filtering method is computationally simple, resulting in minimal memory and time consumption during the calculation process. Attached Figure Description
[0051] To further illustrate the above and other advantages and features of the various embodiments of the present invention, a more specific description of the various embodiments of the present invention will be presented with reference to the accompanying drawings. It is to be understood that these drawings depict only typical embodiments of the invention and are therefore not intended to limit its scope. In the drawings, identical or corresponding parts will be indicated by identical or similar reference numerals for clarity.
[0052] Figure 1 A flowchart illustrating a filtering method for pulse width measurement according to an embodiment of the present invention is shown; and
[0053] Figure 2 The diagram shows a flowchart of a pulse width measurement method according to an embodiment of the present invention. Detailed Implementation
[0054] In the following description, the invention is described with reference to various embodiments. However, those skilled in the art will recognize that the embodiments may be practiced without one or more specific details or in conjunction with other alternatives and / or additional methods. In other instances, well-known methods or operations are not shown or described in detail so as not to obscure the inventive points of the invention.
[0055] In this specification, references to "an embodiment" or "this embodiment" mean that a particular feature, structure, or characteristic described in connection with that embodiment is included in at least one embodiment of the invention. The phrase "in one embodiment" appearing throughout this specification does not necessarily refer to the same embodiment in all instances.
[0056] Furthermore, the numbering of the steps in the methods of the present invention does not limit the execution order of the method steps. Unless otherwise specified, the method steps may be executed in different orders.
[0057] Furthermore, in this invention, each “specified time period” includes: the end point of the first specified time period, the second specified time period, the third specified time period, the fourth specified time period, and the fifth specified time period is the current time, and the start point can be, for example, the start time of the first measurement, or any specified time set according to requirements.
[0058] Based on the inventor's insight that the accuracy of pulse width measurement in existing PWM speed control is low due to: 1. Low microcontroller performance; 2. Significant noise impact. Therefore, improving the accuracy of pulse width measurement can be achieved in two ways: 1. Replacing with a higher-performance microcontroller chip; 2. Reducing noise impact. Replacing the microcontroller chip has a certain impact on surrounding circuits and inevitably increases the overall system cost, thus this method cannot be widely used. For noise, filtering is often used to eliminate it. Existing PWM speed control often uses average filtering, which is effective when noise is low. Since it uses the average pulse width over a period of time as the final output value, to avoid large errors, the calculation period should ideally be lengthened to reduce the impact of noise-affected pulses on the average value. However, an excessively long calculation period leads to lower timeliness of the measurement data. Based on this, the inventor provides a real-time filtering method that can output the filtered pulse width value in real time. Furthermore, a pulse width measurement method and a microcontroller capable of running the pulse width measurement method are provided. The following description, in conjunction with the accompanying drawings, further illustrates the solution of this invention.
[0059] Figure 1 This diagram illustrates a filtering method for pulse width measurement according to an embodiment of the present invention. Figure 1 As shown, a filtering method for pulse width measurement includes:
[0060] First, in step 101, it is determined whether the pulse signal frequency is stable. It is determined whether the pulse signal frequency is stable within a first specified time period. If stable, proceed to step 1211; otherwise, proceed to step 1221. In one embodiment of the present invention, the determination of whether the pulse signal frequency is stable is based on a signal frequency stability count value within the first specified time period. Specifically, in each measurement, the difference between the real-time period width obtained from the previous measurement and the real-time period width obtained in the current measurement is calculated, and then the difference is compared with a preset error threshold.
[0061] If the difference is less than the preset error threshold, the signal frequency stability count is incremented by one; and
[0062] If the difference is greater than or equal to the preset error threshold, the signal frequency stability count value is decremented by one.
[0063] If the signal frequency stability count value is greater than a specified value within the first specified time period, the frequency of the pulse signal is determined to be stable; otherwise, the frequency of the pulse signal is determined to be unstable. The preset error threshold is determined based on the real-time period width obtained from this measurement and the preset frequency stability error coefficient. Specifically, it is equal to the real-time period width obtained from this measurement and the preset frequency stability error coefficient. The preset frequency stability error coefficient refers to the maximum allowable fluctuation range coefficient of the measurement result for each measurement, and can be set according to actual needs; for example, it is preferably set to 0.1. The specified value is mainly used to determine whether there are significant fluctuations in the signal width over a continuous period of time. It can be used to preliminarily identify whether the signal is noise or a valid signal, and it has a noise suppression effect. The larger the value, the stronger the suppression capability. The specified value can be set according to actual needs; for example, it is preferably set to 8. Furthermore, the length of the first specified time period can be set according to the pulse signal frequency.
[0064] In step 1211, pulse width correction. When the frequency of the pulse signal is stable, the pulse width value can be corrected based on the real-time period width, real-time high-level width, and real-time low-level width obtained from real-time measurements. In one embodiment of the present invention, pulse width correction includes:
[0065] If the average low-level width is less than the average period width minus the measurement error, and the average high-level width is greater than the average period width plus the measurement error, then the corrected pulse width is equal to the real-time period width minus the real-time low-level width.
[0066] If the average low-level width is greater than the average period width plus the measurement error, and the average high-level width is less than the average period width minus the measurement error, then the corrected pulse width is equal to the real-time high-level width.
[0067] If the average low-level width is greater than or equal to the average period width minus the measurement error, and less than or equal to the average period width plus the measurement error, then the corrected pulse width is equal to the real-time period width minus the real-time low-level width.
[0068] If the average high-level width is greater than or equal to the average period width minus the measurement error, and less than or equal to the average period width plus the measurement error, then the corrected pulse width is equal to the real-time high-level width; and
[0069] If none of the above conditions are met, then continuously read the capture pulse width level a specified number of times:
[0070] If all levels are high, the corrected pulse width value is equal to the average high-level width; and
[0071] If all are low, the corrected pulse width value is equal to 0.
[0072] in,
[0073] The average low-level width is the average of all real-time low-level widths measured within the fourth specified time period;
[0074] The average high-level width is the average of all real-time high-level widths measured within the fourth specified time period;
[0075] The average cycle width is the average of all real-time cycle widths measured within the fourth specified time period; and
[0076] The measurement error value is determined based on the average value of the period width and a preset measurement error coefficient. Specifically, it can be equal to the product of the average value of the period width and the preset measurement error coefficient. The duration of the fourth specified time period can be equal to or not equal to the first specified time period. For example, it can be set according to the signal frequency or set to the time period from the start time of the first measurement to the current time. The preset measurement error coefficient can be set according to the measurement accuracy of the normal duty cycle of the pulse signal in actual application. For example, if a measurement accuracy greater than 1% is required, the measurement error coefficient is set to 0.01.
[0077] In one embodiment of the present invention, the corrected pulse width value is stored in a second array, the length of which is N. The value of N mainly affects the accuracy of the filtering result of the pulse signal at high frequencies. The larger the value of N, the more accurate the measurement result of each duty cycle of the high-frequency pulse signal. For example, when the pulse signal frequency is greater than 20KHz, the value of N is preferably greater than 20; when the pulse signal frequency is 10K to 20K, the value of N is preferably greater than 10; and when the pulse signal frequency is 0 to 10K, the value of N is preferably greater than 5. It should be understood that the value of N can be set according to actual needs and is not limited to the preferred values mentioned above. The method for storing data in an array of length N is as follows: starting from the index record value 0, data is stored sequentially. Each time data is stored, the array index record value is incremented until the index record value is N-1. When the index record value reaches N after incrementing, the array index record value is reset to 0, and the sequential storage starts again from the position of index 0.
[0078] Next, in step 1212, the signal state of this measurement is determined. The signal state of the measured pulse is determined based on the corrected pulse width value, wherein the signal state includes three types: full high, full low, and normal. In one embodiment of the present invention, determining the signal state includes:
[0079] If the corrected pulse width value is less than the minimum measurement width, the signal state is all low. The minimum measurement width is determined based on the average low-level width and the minimum measurement width coefficient. Specifically, it can be equal to the product of the average low-level width and the minimum measurement width coefficient. The minimum measurement width coefficient can be determined based on the lower limit of the normal operating duty cycle of the pulse signal. For example, when the requirement is that the pulse signal can meet the normal operating duty cycle of 3% to 97% at all frequencies from 200Hz to 25KHz, the minimum measurement pulse width coefficient is preferably 0.03. It should be understood that the minimum measurement width coefficient can be set according to actual needs and is not limited to the preferred value mentioned above.
[0080] If the corrected pulse width value is greater than the maximum measurement width, the signal state is full high. The maximum measurement width is determined based on the average high-level width and a maximum measurement width coefficient. Specifically, it can be equal to the product of the average high-level width and the maximum measurement width coefficient. The maximum measurement width coefficient can be determined based on the upper limit of the normal operating duty cycle of the pulse signal. For example, when the requirement is that the pulse signal can meet a normal operating duty cycle of 3% to 97% at all frequencies from 200Hz to 25kHz, the maximum measurement pulse width coefficient is preferably 0.97. It should be understood that the maximum measurement width coefficient can be set according to actual needs and is not limited to the preferred value mentioned above.
[0081] If the corrected pulse width value is greater than or equal to the minimum measurement width and less than or equal to the maximum measurement width, then the signal status is normal.
[0082] In one embodiment of the present invention, the corrected pulse width value is stored in a first array, the length of the first array is equal to that of the second array, the signal states stored therein correspond one-to-one with the corrected pulse width values stored in the second array, and the data storage method is the same as that of the second array.
[0083] Next, in step 1213, the real-time signal state is determined. The number of the three signal states within the second specified time period is counted, and the one with the most counts is taken as the real-time signal state. The duration of the second specified time period may be equal to or not equal to the first specified time period. For example, it can be set according to the signal frequency, or set to the time period from the start time of the first measurement to the current time, or it can be determined by directly counting all the values stored in the first array.
[0084] In step 1221, the real-time signal state is determined. When the pulse signal frequency is unstable, the real-time signal state is determined based on the level of the input pin used for capturing within a third specified time period: if the level of the input pin used for capturing is high within the third specified time period, the real-time signal state is determined to be all high; otherwise, the real-time signal state is determined to be all low. The duration of the third specified time period may be equal to or not equal to the first specified time period; for example, it can be set according to the signal frequency, or set to the time period from the start time of the first measurement to the current time.
[0085] Finally, in step 103, the output pulse width value is determined. Based on the real-time signal state determined in steps 1213 or 1221, the output pulse width value is determined, specifically including:
[0086] If the real-time signal status is all low, the output pulse width value is 0;
[0087] If the real-time signal state is all high, the output pulse width value is the average of the period width; and
[0088] If the real-time signal status is normal, the output pulse width value is the average of the pulse width values after correction for all pulses with normal signal status within the fifth specified time period. The duration of the fifth specified time period may be equal to or not equal to the first specified time period. For example, it can be set according to the signal frequency, or set to the time period from the start time of the first measurement to the current time, or the average of all values in the second array that are greater than or equal to the minimum measurement width and less than or equal to the maximum measurement width can be directly used as the output pulse width value.
[0089] Based on the aforementioned filtering method, Figure 2 This diagram illustrates a flowchart of a pulse width measurement method according to an embodiment of the present invention. Figure 2 As shown, a pulse width measurement method includes:
[0090] First, in step 201, real-time measurement is performed. This involves measuring the pulse period width, low-level width, and high-level width in real time. Since most microcontrollers do not support simultaneous measurement of these three widths, in one embodiment of the invention, the three widths must be measured sequentially, specifically including:
[0091] First, the microcontroller pulse width measurement mode is set to the period width measurement mode, and the real-time period width is measured. The period width measurement mode can be, for example, triggered by the rising edge and terminated by the rising edge, or triggered by the falling edge and terminated by the falling edge.
[0092] Next, the microcontroller's pulse width measurement mode is set to high-level width measurement mode, and the real-time high-level width is measured. This high-level width measurement mode can be, for example, triggered by a rising edge and terminated by a falling edge; and
[0093] Finally, the microcontroller pulse width measurement mode is set to low-level width measurement mode, and the real-time low-level width is measured. This low-level width measurement mode can be, for example, triggered by a falling edge and terminated by a rising edge; and
[0094] Finally, in step 202, filtering is performed. The filtering is performed according to the aforementioned method to obtain the output pulse width value. In this embodiment of the invention, real-time measurement is performed simultaneously with filtering to ensure continuous output of pulse width values. Since the filtering algorithm proposed in this invention consumes time on the order of O(n), it can effectively guarantee real-time performance. However, it should be understood that because the filtering process requires the average value of the period width, the average value of the low-level width, and the average value of the high-level width, a certain period of time must be waited before real-time pulse width output can be performed.
[0095] This invention provides a filtering method and a pulse width measurement method for pulse width measurement. Using pulse signal width data obtained from chip measurement, the real-time pulse signal width data is corrected based on the signal state within a specified time period. The signal state is then determined, and a queue is used to record the pulse signal state information and corresponding corrected pulse width values for a continuous period. Finally, the true state of the signal is determined based on the recorded state information, and the current pulse width is calculated using the corrected pulse width data corresponding to that signal state in the queue. This achieves signal filtering and pulse width measurement. It is entirely implemented in software, without relying on hardware performance, and can improve measurement accuracy and achieve better anti-interference capabilities without replacing the microcontroller. It is particularly suitable for pulse width measurement of high-frequency, high-duty-cycle, and low-duty-cycle pulse signals. Furthermore, the pulse width measurement method provides real-time output, offering superior timeliness. Simultaneously, the filtering method is computationally simple; therefore, the overall memory and time consumption during the operation are both on the order of O(n).
[0096] Although various embodiments of the invention have been described above, it should be understood that they are presented by way of example only and not as limitations. It will be apparent to those skilled in the art that various combinations, modifications, and alterations can be made without departing from the spirit and scope of the invention. Therefore, the breadth and scope of the invention disclosed herein should not be limited by the exemplary embodiments disclosed above, but should be defined solely by the appended claims and their equivalents.
Claims
1. A filtering method for pulse width measurement, characterized in that, Including the following steps: Determine whether the frequency of the pulse signal is stable within a first specified time period, wherein: If stable, proceed with the following steps: The pulse width value is corrected based on the real-time period width, real-time high-level width, and real-time low-level width obtained from the real-time measurement of the pulse signal. The signal state of the pulse signal is determined based on the corrected pulse width value. The signal states mentioned include all high, all low, and normal; and Determine the number of all-high, all-low, and normal signal states within a second specified time period, and identify the state with the most occurrences as the real-time signal state; and If unstable, perform the following steps: The real-time signal state is determined based on the level of the input pin used to capture the signal within a third specified time period; and The output pulse width value is determined based on the real-time signal status.
2. The filtering method as described in claim 1, characterized in that, It also includes setting two arrays of the same length, including: The first array is configured to store real-time signal states; and The second array is configured to store the corrected pulse width values corresponding to the real-time signal state.
3. The filtering method as described in claim 1, characterized in that, Determining whether the frequency of the pulse signal is stable within the first specified time period includes: For each measurement, the difference between the real-time cycle width obtained from the previous measurement and the real-time cycle width obtained from the current measurement is calculated; Compare the difference with a preset error threshold: If the difference is less than the preset error threshold, the signal frequency stability count is incremented by one; and If the difference is greater than or equal to the preset error threshold, the signal frequency stability count is decremented by one; and If the signal frequency stability count value is greater than the specified value within the first specified time period, then the frequency of the pulse signal is stable; otherwise, the frequency of the pulse signal is unstable.
4. The filtering method as described in claim 3, characterized in that, The preset error threshold is equal to the product of the real-time cycle width obtained in this measurement and the preset frequency stability error coefficient.
5. The filtering method as described in claim 1, characterized in that, The corrected pulse width values include: If the average low-level width is less than the average period width minus the measurement error, and the average high-level width is greater than the average period width plus the measurement error, then the corrected pulse width is equal to the real-time period width minus the real-time low-level width. If the average low-level width is greater than the average period width plus the measurement error, and the average high-level width is less than the average period width minus the measurement error, then the corrected pulse width is equal to the real-time high-level width. If the average low-level width is greater than or equal to the average period width minus the measurement error, and less than or equal to the average period width plus the measurement error, then the corrected pulse width is equal to the real-time period width minus the real-time low-level width. If the average high-level width is greater than or equal to the average period width minus the measurement error, and less than or equal to the average period width plus the measurement error, then the corrected pulse width is equal to the real-time high-level width; otherwise... Read the capture pulse width level continuously a specified number of times: If all levels are high, the corrected pulse width value is equal to the average high-level width; and If all are low, the corrected pulse width value is equal to 0; in, The average low-level width is the average of all real-time low-level widths measured within the fourth specified time period; The average high-level width is the average of all measured real-time high-level widths within the fourth specified time period; and The average cycle width is the average of all real-time cycle widths measured within the fourth specified time period.
6. The filtering method as described in claim 5, characterized in that, The measurement error value is equal to the product of the average period width and the preset measurement error coefficient.
7. The filtering method as described in claim 1, characterized in that, The signal state of the measured pulse is determined based on the corrected pulse width value, including: If the corrected pulse width value is less than the minimum measurement width, the signal state is all low; If the corrected pulse width value is greater than the maximum measurement width, the signal state is full height; and If the corrected pulse width value is greater than or equal to the minimum measurement width and less than or equal to the maximum measurement width, then the signal status is normal.
8. The filtering method as described in claim 7, characterized in that, The minimum measurement width is equal to the product of the average low-level width and the minimum measurement width coefficient, wherein the average low-level width is the average of all real-time low-level widths measured within the fourth specified time period; and The maximum measurement width is equal to the product of the average high-level width and the maximum measurement width coefficient, wherein the average high-level width is the average of all real-time high-level widths measured within the fourth specified time period.
9. The filtering method as described in claim 1, characterized in that, The real-time signal state is determined based on the level of the input pin used to capture the signal during the third specified time period, including: If the level of the input pin used for capturing is high throughout the third specified time period, then the real-time signal state is all high; otherwise... The real-time signal status is all low.
10. The filtering method as described in claim 1, characterized in that, Determining the output pulse width value based on the real-time signal state includes: If the real-time signal status is all low, the output pulse width value is 0; If the real-time signal state is all high, the output pulse width value is the average of the period width; and If the real-time signal status is normal, the output pulse width value is the average of the pulse width values after correction for all pulses with normal signal status within the fifth specified time period.
11. A method for measuring pulse width, characterized in that, Including the following steps: Real-time measurement of pulse period width, low-level width, and high-level width; and The output pulse width value is obtained by filtering according to any one of the filtering methods described in claims 1-10.
12. The method as described in claim 11, characterized in that, The period width, low-level width, and high-level width of the real-time measurement pulse include: Set the microcontroller's pulse width measurement mode to period width measurement mode and measure the real-time period width; Set the microcontroller's pulse width measurement mode to high-level width measurement mode and measure the real-time high-level width; and Set the microcontroller pulse width measurement mode to low-level width measurement mode and measure the real-time low-level width.
13. A microcontroller, characterized in that, It is configured to perform the pulse width measurement method as described in any one of claims 11 to 12.