Incremental encoder speed measurement method and device and computer readable storage medium

By calculating the number of pulses and time deviations, combining timer clock frequency and pulse width compensation, the problem of the incremental encoder speed measurement method is solved, and high-precision speed measurement is achieved.

CN119224365APending Publication Date: 2024-12-31CHANGSHA SUNYE ELECTRIC CO LTD +1
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202310787714.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-29
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

The existing incremental encoder speed measurement methods reduce accuracy within the full speed range, especially at low and high speeds, due to the timer accuracy and maximum time duration.

Method used

By obtaining the number of captured pulses and pulse times at the current and last speed calculation time, the pulse number deviation and time deviation are calculated, and the actual speed is calculated using the timer clock frequency. The formula N_m=60*(ΔCapPulsCnt/PPR_single)/(ΔCapTimCnt/ F_cap) determines the actual speed of the motor, and combines pulse width compensation and speed compensation to achieve high-precision speed measurement within the full speed range.

Benefits of technology

High-precision speed measurement in the full speed range is achieved, ensuring accurate speed measurement at low speeds and high speeds, reducing the impact of signal jitter on measurements, and improving the speed measurement accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119224365A_ABST
    Figure CN119224365A_ABST
Patent Text Reader

Abstract

The invention discloses an incremental encoder speed measurement method and device and a computer readable storage medium, and the method comprises the steps: obtaining the number of captured pulses and the time of capturing pulses at the current rotating speed calculation time, and obtaining the number of captured pulses and the time of capturing pulses at the last rotating speed calculation time; according to the number of captured pulses at the current rotating speed calculation moment and the number of captured pulses at the last rotating speed calculation moment, pulse number deviation is determined, and according to the capture pulse moment at the current rotating speed calculation moment and the capture pulse moment at the last rotating speed calculation moment, pulse time deviation is determined; acquiring a pulse number and a timer clock frequency corresponding to each circle; determining a first ratio of the pulse number deviation to the pulse number corresponding to each circle, and determining a second ratio of the pulse time deviation to the clock frequency of the timer; according to the product of the first ratio and the second ratio, the actual rotating speed of the motor is determined, and the speed measurement precision in the full speed range is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of motor speed measurement, and in particular to an incremental encoder speed measurement method, device and computer-readable storage medium. Background Art

[0002] At present, the main methods of motor speed measurement include tachometer generators, rotary transformers, linear grating scales and encoders. Among them, incremental encoders have the advantages of simple structure, convenient and accurate measurement, and long life, and are widely used in the field of modern control.

[0003] When using an incremental encoder to measure speed, the encoder is coaxial with the motor being measured, and the motor's rotation direction and speed are determined by detecting the output pulse sequence. The most typical methods of pulse speed measurement are frequency measurement method (M method speed measurement), period measurement method (T method speed measurement) and frequency period adaptive method (MT method speed measurement). The frequency measurement method calculates the speed based on the number of pulses within a certain period of time. At low speeds, the number of pulses in the speed calculation period is small, and the time corresponding to the error of a single pulse is relatively large relative to the speed period. The calculation accuracy will be significantly reduced, so it is only suitable for high-speed speed measurement. The period measurement method measures the time of a single pulse to calculate the speed. At high speeds, the single pulse moment is small, and the measurement error cannot be ignored relative to the single pulse moment, so the speed measurement accuracy will be significantly reduced. At present, the frequency period adaptive method is widely used in the industrial field. This method combines the advantages of the M method and the T method and belongs to the full speed range measurement method. However, due to the limitations of the timer accuracy and the maximum timing duration, the speed measurement accuracy of the M / T method is reduced. Summary of the invention

[0004] The embodiments of the present application aim to improve the speed measurement accuracy of an incremental encoder by providing an incremental encoder speed measurement method, device, and computer-readable storage medium.

[0005] The embodiment of the present application provides a method for measuring speed of an incremental encoder, the method comprising:

[0006] Obtain the number of captured pulses and the captured pulse time at the current speed calculation moment, and obtain the number of captured pulses and the captured pulse time at the last speed calculation moment;

[0007] Determine the pulse number deviation according to the captured pulse number at the current speed calculation moment and the captured pulse number at the previous speed calculation moment, and determine the pulse time deviation according to the captured pulse time at the current speed calculation moment and the captured pulse time at the previous speed calculation moment;

[0008] Get the number of pulses and timer clock frequency corresponding to each circle;

[0009] Determine a first ratio of the pulse number deviation to the pulse number corresponding to each revolution, and determine a second ratio of the pulse time deviation to the timer clock frequency;

[0010] The actual rotation speed of the motor is determined according to the product of the first ratio and the second ratio.

[0011] Optionally, the step of determining the actual rotation speed of the motor according to the product of the first ratio and the second ratio comprises:

[0012] The actual speed calculation formula of the motor is used to determine the actual speed of the motor. The actual speed calculation formula of the motor is:

[0013] N_m=60*(ΔCapPulsCnt / PPR_single) / (ΔCapTimCnt / F_cap);

[0014] Among them, ΔCapPulsCnt is the pulse number deviation, PPR_single is the number of pulses corresponding to each circle, ΔCapTimCnt is the pulse time deviation, F_cap represents the timer clock frequency for recording the moment of capturing the pulse, the first ratio of the pulse number deviation to the number of pulses corresponding to each circle is ΔCapPulsCnt / PPR_single, and the second ratio of the pulse time deviation to the timer clock frequency is ΔCapTimCnt / F_cap.

[0015] Optionally, the step of determining the pulse time deviation according to the capture pulse time at the current speed calculation time and the capture pulse time at the last speed calculation time includes:

[0016] If the pulse width of a single pulse signal is less than the maximum capture period of the timer, a first compensation value is determined, and the pulse time deviation is determined according to the capture pulse time at the current speed calculation time, the capture pulse time at the last speed calculation time and the first compensation value;

[0017] If the pulse width of a single pulse signal is greater than the maximum capture period of the timer, a second compensation value is determined. The pulse time deviation is determined based on the capture pulse time of the current speed calculation moment, the capture pulse time of the last speed calculation moment and the second compensation value. The second compensation value is greater than the first compensation value.

[0018] Optionally, determining the second compensation value includes:

[0019] Calculate the period according to the maximum capture period and the current rotation speed, and determine the period multiple;

[0020] Determine the number of speed cycles without pulse number deviation, determine the number of timer cycles for capturing pulse moments, and determine the initial capture pulse time deviation between the capture pulse moment at the current speed calculation moment and the capture pulse moment at the previous speed calculation moment;

[0021] The second compensation value is determined according to the number of rotation speed cycles, the number of timer cycles, the cycle multiple and the initial capture pulse time deviation.

[0022] Optionally, the step of determining the second compensation value according to the number of rotation speed cycles, the number of timer cycles, the cycle multiple and the initial capture pulse time deviation comprises:

[0023] The second compensation value is determined by using a second compensation value calculation formula, and the second compensation value calculation formula is:

[0024]

[0025] Among them, CapCntComp is an integer, N no P u l s is the number of speed cycles, T_b is the maximum capture cycle, T_c is the current speed calculation cycle, CapARR is the number of timer cycles, N is the cycle multiple, ΔCapTimCnt is the initial capture pulse time deviation.

[0026] Optionally, the incremental encoder speed measurement method further includes:

[0027] If at the current speed calculation moment, the pulse width of a single pulse signal is less than the pulse width of a single pulse signal corresponding to a preset speed resolution, the actual speed is cleared.

[0028] Optionally, the incremental encoder speed measurement method further includes:

[0029] Get the current calculated speed and the last calculated speed;

[0030] Determining a speed difference between the currently calculated speed and the last calculated speed;

[0031] If the speed difference is greater than a preset speed, the preset speed is used to perform speed compensation on the last calculated speed.

[0032] Optionally, the incremental encoder speed measurement method further includes:

[0033] Obtaining the capture time of the rising edge of the pulse signal and the capture time of the falling edge adjacent to the rising edge, and obtaining the number of pulses corresponding to the rising edge and the number of pulses corresponding to the falling edge;

[0034] Establishing a first association relationship between the capture time of the rising edge and the number of pulses of the rising edge, and establishing a second association relationship between the capture time corresponding to the falling edge and the number of pulses corresponding to the falling edge;

[0035] The first association relationship and the second association relationship are stored in a data cache area to obtain the number of captured pulses and the captured pulse time at the current speed calculation moment, and the number of captured pulses and the captured pulse time at the last speed calculation moment from the data cache area.

[0036] In addition, to achieve the above-mentioned purpose, the present invention also provides an incremental encoder comprising: a memory, a processor, and an incremental encoder speed measurement program stored in the memory and executable on the processor, wherein the incremental encoder speed measurement program implements the steps of the above-mentioned incremental encoder speed measurement method when executed by the processor.

[0037] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, which stores an incremental encoder speed measurement program, and when the incremental encoder speed measurement program is executed by a processor, the steps of the above-mentioned incremental encoder speed measurement method are implemented.

[0038] The technical solution of an incremental encoder speed measurement method, device and computer-readable storage medium provided in the embodiment of the present application, the present application first obtains the number of captured pulses and the captured pulse moment at the current speed calculation moment, and obtains the number of captured pulses and the captured pulse moment at the last speed calculation moment; then, according to the number of captured pulses at the current speed calculation moment and the number of captured pulses at the last speed calculation moment, the pulse number deviation is determined, and according to the captured pulse moment at the current speed calculation moment and the captured pulse moment at the last speed calculation moment, the pulse time deviation is determined; finally, the number of pulses corresponding to each circle and the timer clock frequency are obtained; the first ratio of the pulse number deviation and the number of pulses corresponding to each circle is determined, and the second ratio of the pulse time deviation and the timer clock frequency is determined; according to the product between the first ratio and the second ratio, the actual speed of the motor is determined. Compared with the related art that separately captures the rising edge or the falling edge to calculate the speed, the present application obtains the number of captured pulses and the captured pulse moment at the current speed calculation moment, and obtains the number of captured pulses and the captured pulse moment at the last speed calculation moment, and calculates the pulse number deviation and the pulse time deviation to accurately calculate the speed. The accurate pulse number and corresponding pulse time deviation measurement in the full speed range are realized, ensuring high-precision speed measurement in the full speed range. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1It is a flow chart of the first embodiment of the incremental encoder speed measurement method of the present invention;

[0040] Figure 2 It is a flow chart of a second embodiment of the incremental encoder speed measurement method of the present invention;

[0041] Figure 3 It is a structural schematic diagram of the incremental encoder of the present invention;

[0042] Figure 4 It is a schematic diagram of pulse changes when the motor of the present invention runs at high speed;

[0043] Figure 5 It is a schematic diagram of pulse changes when the motor of the present invention runs at a low speed.

[0044] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. The above-mentioned drawings are only an embodiment diagram, not the entire invention. DETAILED DESCRIPTION

[0045] At present, when using incremental encoders for speed measurement, the encoder is coaxial with the motor being measured, and the rotation direction and speed of the motor are determined by detecting the output pulse sequence. The most typical methods of pulse speed measurement are frequency measurement method (M method speed measurement), period measurement method (T method speed measurement) and frequency period adaptive method (MT method speed measurement). The frequency measurement method calculates the speed based on the number of pulses within a certain period of time. At low speeds, the number of pulses at the time of speed calculation is small, and the time corresponding to the error of a single pulse is relatively large relative to the speed period. The calculation accuracy will be significantly reduced, so it is only suitable for high-speed speed measurement. The period measurement method measures the time of a single pulse to calculate the speed. At high speeds, the time of a single pulse is small, and the measurement error cannot be ignored relative to the time of a single pulse, so the speed measurement accuracy will be significantly reduced. At present, the frequency period adaptive method is widely used in the industrial field. This method combines the advantages of the M method and the T method and belongs to the full speed range measurement method. However, due to the limitations of the timer accuracy and the maximum timing duration, the speed measurement accuracy of the M / T method is reduced.

[0046] Therefore, in order to solve the above technical problems, the present application first obtains the number of captured pulses and the moment of captured pulses at the current speed calculation moment, and obtains the number of captured pulses and the moment of captured pulses at the last speed calculation moment; then, according to the number of captured pulses at the current speed calculation moment and the number of captured pulses at the last speed calculation moment, the pulse number deviation is determined, and according to the captured pulse moment at the current speed calculation moment and the captured pulse moment at the last speed calculation moment, the pulse time deviation is determined; finally, the number of pulses corresponding to each circle and the timer clock frequency are obtained; the first ratio of the pulse number deviation and the number of pulses corresponding to each circle is determined, and the second ratio of the pulse time deviation and the timer clock frequency is determined; the actual speed of the motor is determined according to the product between the first ratio and the second ratio. Compared with the related art that separately captures the rising edge or the falling edge to calculate the speed, the present application obtains the number of captured pulses and the moment of captured pulses at the current speed calculation moment, and obtains the number of captured pulses and the moment of captured pulses at the last speed calculation moment, and calculates the pulse number deviation and the pulse time deviation to accurately calculate the speed. The accurate pulse number and corresponding pulse time deviation measurement in the full speed range are realized, ensuring high-precision speed measurement in the full speed range.

[0047] In addition, by capturing pulse data multiple times and caching the captured pulse data in the data cache area, by accurately caching the number of pulses and the corresponding time, the speed calculation is performed at the low speed calculation moment, so that fast speed update can be achieved.

[0048] In addition, the present application compensates for the low speed condition during the incremental encoder speed measurement process, and can accurately measure the rotation speed of the motor when it runs at a low speed.

[0049] Finally, the present application also adopts a technical solution of obtaining the speed of the current speed calculation cycle and the speed of the previous speed cycle; determining the speed difference between the speed of the current speed calculation cycle and the speed of the previous speed cycle; if the speed difference is greater than the preset speed, using the preset speed to compensate the speed of the previous speed cycle. Through software signal anti-shake processing, the influence of signal jitter on speed measurement is reduced without increasing hardware filtering costs and calculation delays.

[0050] In order to better understand the above technical solution, exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0051] like Figure 1As shown, in the first embodiment of the present application, the incremental encoder speed measurement method of the present application is used to measure the motor speed, and the incremental encoder speed measurement method of the present application includes the following steps:

[0052] Step S110, obtaining the number of captured pulses and the captured pulse time at the current speed calculation moment, and obtaining the number of captured pulses and the captured pulse time at the last speed calculation moment;

[0053] Optionally, the speed cycle refers to a sampling period of a set time length, and therefore, all pulses received within the speed cycle refer to all pulses received within the sampling period of the set time length. Figure 4 and Figure 5 As shown, assuming that the speed cycle is T_c and its set time length is 500us, the valid pulses obtained in this speed cycle are all pulses received within 500us from the start of timing, and the pulses received after 500us of timing are invalid pulses and are not counted in the pulses received in this speed cycle.

[0054] Alternatively, if Figure 4 and Figure 5 As shown in the figure, the pulse capture time refers to the time when the pulse edge is captured. The number of captured pulses refers to the number of edges of the pulse signal captured within the speed cycle, which can be the number of rising edges, the number of falling edges, or the total number of rising and falling edges of the pulse signal captured within the speed cycle. For example, Figure 4 and Figure 5 As shown, the speed cycle is T_c. Regardless of the current speed calculation cycle or the previous speed cycle, each edge has a corresponding capture time and a corresponding number of pulses. The capture time corresponding to the rising edge and the capture time corresponding to the falling edge are counted. There is a corresponding number of pulses at the capture time of each rising edge, and there is also a corresponding number of pulses at the capture time of each falling edge, that is, Figure 4 The pulse count value in .

[0055] Optionally, during the operation of the motor, the incremental encoder will store the collected pulse signal in a data buffer in real time. Specifically, the capture time of the rising edge of the pulse signal and the capture time of the falling edge adjacent to the rising edge are obtained, and the number of pulses corresponding to the rising edge and the number of pulses corresponding to the falling edge are obtained; a first association relationship is established between the capture time of the rising edge and the number of pulses of the rising edge, and a second association relationship is established between the capture time corresponding to the falling edge and the number of pulses corresponding to the falling edge; the first association relationship and the second association relationship are stored in the data buffer. Among them, the number of pulses refers to the number of pulse edges captured, the pulse moment refers to the moment when the pulse edge is captured, the number of pulses and the pulse moment recorded at the same time are saved as a pair of data, and the cache needs to store the number of pulses and the pulse moment in pairs, that is, the number of pulses and the pulse moment captured are stored cyclically through the data cache. By capturing the pulse data cache multiple times, the number of pulses and the corresponding pulse moment are accurately cached, and the speed calculation is performed within the low-speed speed calculation cycle, so that fast speed updates can be achieved.

[0056] Optionally, when the data buffer is full, the latest data is used to overwrite the earliest data. The setting constraint of the data buffer size is the bandwidth of the encoder AB signal input channel, and the calculation formula is as follows:

[0057] Buff>=F_bw*T_c*K.

[0058] Among them, F_bw represents the bandwidth of the encoder pulse signal, K represents the frequency multiplication coefficient of the pulse rising and falling edges and the original pulse signal, and when the rising and falling edges of a single pulse signal, such as the A-channel pulse signal or the B-channel pulse signal, are captured at the same time, K is 2, and when the rising and falling edges of the AB orthogonal signal are captured at the same time, K is 4, Buff represents the size of the data buffer area, and T_c represents the speed cycle.

[0059] The present application stores the number of pulses and the capture time in pairs in a data cache in real time, so that when the motor speed is subsequently calculated, the number of captured pulses and the capture pulse time at the current speed calculation time, and the number of captured pulses and the capture pulse time at the last speed calculation time can be obtained from the data cache for calculation.

[0060] Step S120, determining a pulse number deviation according to the number of captured pulses at the current speed calculation moment and the number of captured pulses at the previous speed calculation moment, and determining a pulse time deviation according to the captured pulse time at the current speed calculation moment and the captured pulse time at the previous speed calculation moment;

[0061] Optionally, since the number of pulses and the capture time corresponding to each rising edge and falling edge are stored in the data buffer, the number of capture pulses required for the current speed calculation, the number of capture pulses required for the previous speed calculation, the capture pulse time for the current speed calculation, and the capture pulse time for the speed calculation can be obtained from the data buffer. The speed cycle can be set according to actual conditions. The number of capture pulses at the speed calculation time can be one or more.

[0062] Optionally, the pulse number deviation can be determined based on the difference between the number of captured pulses at the current speed calculation moment and the number of captured pulses at the previous speed calculation moment. The pulse time deviation can be determined based on the difference between the captured pulse time at the current speed calculation moment and the captured pulse time at the previous speed calculation moment.

[0063] Specifically, according to the number of captured pulses and the captured pulse time of each speed cycle, the pulse number deviation and the corresponding pulse time deviation are calculated. The specific calculation formula is as follows:

[0064] ΔCapPulsCnt=CapPulsCnt-postCapPulsCnt;

[0065] ΔCapTimCnt=CapTimCnt-postCapTimCnt;

[0066] Among them, CapPulsCnt indicates the number of pulses captured during the current speed calculation, postCapPulsCnt indicates the number of pulses captured during the last speed calculation, CapTimCnt indicates the pulse capture time during the current speed calculation, and postCapTimCnt indicates the pulse capture time during the last speed calculation.

[0067] Optionally, each pulse signal has a corresponding rising edge and falling edge. The pulse number deviation can be determined based on the number of pulses corresponding to the rising edge and the number of pulses corresponding to the falling edge. Among them, the pulse number deviation can be determined based on the difference between the number of pulses corresponding to the rising edge and the number of pulses corresponding to the falling edge. Similarly, each pulse signal has a corresponding capture moment for the rising edge and the falling edge, and the pulse time deviation can be determined based on the difference between the capture moment corresponding to the rising edge and the capture moment corresponding to the falling edge. Thus, the pulse number deviation and pulse time deviation at the current speed calculation moment can be calculated.

[0068] Step S130, obtaining the number of pulses corresponding to each circle and the timer clock frequency;

[0069] Optionally, after the pulse number deviation and the pulse time deviation are determined, the actual speed of the motor is determined. The actual speed of the motor may be determined based on the product of the pulse number deviation and the pulse time deviation.

[0070] Optionally, the number of pulses per revolution represents the number of single A / B pulse edges per revolution, and is represented by PPR_single. The timer clock frequency represents the timer clock frequency for recording the capture pulse moment, and is represented by F_cap. The number of pulses per revolution and the timer clock frequency are known parameters and can be directly obtained.

[0071] Step S140, determining a first ratio of the pulse number deviation to the pulse number corresponding to each circle, and determining a second ratio of the pulse time deviation to the timer clock frequency;

[0072] Step S150, determining the actual rotation speed of the motor according to the product of the first ratio and the second ratio.

[0073] Optionally, the actual speed of the motor can be calculated at each speed calculation moment. Optionally, after obtaining the number of pulses corresponding to each revolution and the timer clock frequency, according to the pulse number deviation, the number of pulses corresponding to each revolution, the pulse time deviation and the timer clock frequency. Specifically, it includes: determining a first ratio of the pulse number deviation and the number of pulses corresponding to each revolution, and determining a second ratio of the pulse time deviation and the timer clock frequency; determining the actual speed according to the product of the first ratio and the second ratio.

[0074] Optionally, the motor speed calculation formula within the full speed range is as follows:

[0075] N_m=60*(ΔCapPulsCnt / PPR_single) / (ΔCapTimCnt / F_cap);

[0076] Among them, N_m represents the mechanical speed (in rpm), ΔCapPulsCnt is the pulse number deviation, PPR_single is the number of pulses corresponding to each circle, ΔCapTimCnt is the pulse time deviation, and F_cap represents the timer clock frequency at the time of recording the captured pulse. It should be noted that when ΔCapPulsCnt=0, it means that there is no change in the number of pulse signals at the time of speed calculation, indicating that there is no speed change within two calculation cycles, and the speed value of the previous beat should be maintained. Among them, the first ratio of the pulse number deviation and the number of pulses corresponding to each circle is ΔCapPulsCnt / PPR_single. The second ratio of the pulse time deviation and the timer clock frequency is ΔCapTimCnt / F_cap.

[0077] This embodiment is based on the above technical solution. This application can accurately calculate the speed by obtaining the number of captured pulses and the captured pulse time at the current speed calculation moment, and obtaining the number of captured pulses and the captured pulse time at the last speed calculation moment, and calculating the pulse number deviation and pulse time deviation. The measurement of the precise number of pulses and the corresponding pulse time deviation in the full speed range is achieved, ensuring high-precision speed measurement in the full speed range. In addition, by capturing pulse data multiple times and caching the captured pulse data in the data cache area, by accurately caching the number of pulses and the corresponding time, the speed calculation is performed at the low-speed speed calculation moment, and a fast speed update can be achieved.

[0078] Further, refer to Figure 2 Based on the first embodiment, in the second embodiment of the present application, step S120 further includes the following steps:

[0079] Step S121, if the pulse width of a single pulse signal is less than the maximum capture period of the timer, determine a first compensation value, and determine the pulse time deviation according to the capture pulse time of the current speed calculation moment, the capture pulse time of the last speed calculation moment and the first compensation value.

[0080] Optionally, at high speed, that is, the pulse width of a single A / B pulse signal is less than the maximum capture period of the capture timer, since the pulse width calculated by capture at high speed can accurately reflect the actual pulse width, no compensation is required, that is, at high speed, the first compensation value is 0.

[0081] Step S122, if the pulse width of a single pulse signal is greater than the maximum capture period of the timer, determine a second compensation value, and determine the pulse time deviation based on the capture pulse time of the current speed calculation moment, the capture pulse time of the previous speed calculation moment and the second compensation value, and the second compensation value is greater than the first compensation value.

[0082] Optionally, determining the second compensation value also includes: determining a cycle multiple based on the maximum capture cycle and the current speed calculation cycle; determining the speed cycle number without pulse number deviation, determining the timer cycle number for determining the capture pulse moment, and determining the initial capture pulse time deviation between the capture pulse moment at the current speed calculation moment and the capture pulse moment at the previous speed calculation moment; determining the second compensation value based on the speed cycle number, the timer cycle number, the cycle multiple and the initial capture pulse time deviation.

[0083] Optionally, at low speed, that is, the pulse width of a single A / B pulse signal is greater than the maximum capture period of the capture timer, the pulse width of the capture calculation needs to be compensated to accurately reflect the actual pulse width, which can be obtained by counter N noPulsThe number of speed calculation cycles without pulse increment is counted, and the compensation value of the captured pulse width is calculated as follows:

[0084]

[0085] It should be noted that CapCntComp should be an integer. noPuls Pulse width compensation is only required when > N / 2. CapARR represents the number of timer cycles at the moment of capturing the pulse, T_b represents the maximum capture cycle, T_c represents the current speed calculation cycle, N represents the cycle multiple of T_b and T_c, N is an integer, N noPuls Indicates the speed calculation time ΔCapCnt=0 The continuous cumulative number of times, that is, the number of speed cycles without pulse number deviation; ΔCapTimCnt Indicates the initial capture pulse time deviation between the capture pulse time of the current speed calculation moment and the capture pulse time of the previous speed calculation moment.

[0086] This embodiment is based on the above technical solution. If the pulse width of a single pulse signal is less than the maximum capture period of the timer, the first compensation value is determined, and the pulse time deviation is determined according to the capture pulse moment of the current speed calculation moment, the capture pulse moment of the last speed calculation moment and the first compensation value; if the pulse width of a single pulse signal is greater than the maximum capture period of the timer, the period multiple is determined according to the maximum capture period and the current speed calculation period; the number of speed cycles without pulse number deviation is determined, the number of timer cycles for determining the capture pulse moment, and the initial capture pulse time deviation between the capture pulse moment of the current speed calculation moment and the capture pulse moment of the last speed calculation moment are determined; the second compensation value is determined according to the number of speed cycles, the number of timer cycles, the period multiple and the initial capture pulse time deviation, and the pulse time deviation is determined according to the capture pulse moment of the current speed calculation moment, the capture pulse moment of the last speed calculation moment and the second compensation value, and the second compensation value is greater than the first compensation value. This application compensates for the low speed situation during the incremental encoder speed measurement process, and can accurately measure the speed of the motor when it is running at a low speed.

[0087] Further, based on any embodiment of the first embodiment to the second embodiment, in a third embodiment of the present application, the incremental encoder speed measurement method of the present application includes the following steps:

[0088] Step S210: if the pulse time deviation of a single pulse signal within the speed calculation period is greater than the pulse time deviation of a single pulse signal corresponding to a preset speed resolution, the actual speed is cleared.

[0089] In this embodiment, if a pulse increment, i.e., ΔCapPulsCnt=1, or a pulse time deviation ΔCapTimCnt corresponding to less than a pulse increment, i.e., ΔCapPulsCnt=0, is very large, resulting in the calculated speed being less than the designed speed resolution, the speed can be considered to be 0. The judgment method is that when the pulse time deviation of a single pulse signal is greater than the pulse time of a single pulse signal corresponding to a preset speed resolution, such as 0.6rpm, the actual speed is cleared to zero.

[0090] The theoretical speed calculation result has no fluctuation. In practice, there may be speed calculation errors caused by high-speed clock errors and hardware pulse filtering delays. The speed calculation result does not need to be smoothed and can be used for closed-loop control to ensure the speed feedback bandwidth.

[0091] Further, based on any embodiment of the first embodiment to the third embodiment, in a fourth embodiment of the present application, the incremental encoder speed measurement method of the present application includes the following steps:

[0092] Step S310, obtaining the current calculated rotation speed and the last calculated rotation speed.

[0093] The current calculated speed is the speed calculated at the current speed calculation time, and the last calculated speed is the speed calculated at the last speed calculation time.

[0094] Step S320, determining the speed difference between the currently calculated speed and the last calculated speed;

[0095] Step S330: If the speed difference is greater than a preset speed, the preset speed is used to perform speed compensation on the last calculated speed.

[0096] In this embodiment, when the speed difference between two consecutive calculations is greater than the preset speed, since the actual motor acceleration cannot be infinite, that is, the motor acceleration is greater than a certain value, it can be considered that the speed calculation is abnormal due to signal jitter, and the speed compensation is performed according to the preset speed based on the speed difference and the previous speed calculation result. Through software signal anti-shake processing, the influence of signal jitter on speed measurement is reduced without increasing hardware filtering costs and calculation delays.

[0097] In summary, the specific implementation methods of the present application are introduced below.

[0098] A capture module is selected to realize the rising and falling edge capture of the pulse signal, and a capture event or interrupt is triggered when the capture is successful; a timer 1 is selected to realize the timing count with a period of T_b, the maximum count value is CapARR, and the clock frequency is F_cap; a timer 2 is selected to realize the speed calculation task with a period of T_c; wherein, the periods of timer 1 and timer 2 should satisfy the relationship T_b≥N*T_c, where N is an integer and N≥2; a capture data buffer of a certain capacity is created according to the speed measurement data buffer design method described above.

[0099] Select the encoder line number PPR, the corresponding number of rising and falling edge captures of a single signal when the encoder rotates one circle is expressed as PPR_single, and a capture module is used to capture the rising and falling edges of the A signal or B signal, or the A and B orthogonal signals after the OR logic processing, and record the corresponding count value of timer 1 at the capture moment, and automatically store the number of each capture event and the corresponding count value of timer 1 in the data buffer. Read the pulse capture number CapPulsCnt and the corresponding count value CapTimCnt of timer 1 stored in the current data buffer within the calculation cycle T_c, as well as the pulse capture number postCapPulsCnt and the corresponding count value postCapTimCnt of timer 1 corresponding to the last calculation moment.

[0100] At low speed, there is no change in the number of pulses in the speed cycle, and the change in the number of pulses in the speed cycle is 0. At this time, the variables in the speed calculation formula need to be processed. The pulse increments of the two captures are 1. The deviation between the current calculated capture timer 1 and the previous count value is expressed as ΔCapTimCnt=CapTimCnt–postCapTimCnt. When the speed is further reduced, that is, the pulse width of a single A / B signal exceeds the maximum capture cycle of the capture timer, the second compensation value is:

[0101]

[0102] Finally, ΔCapTimCnt=ΔCapTmCnt+CapCntComp.

[0103] The speed calculation formula (not distinguishing between high and low speeds) is as follows:

[0104] N_m=60*(ΔCapPulsCnt / PPR_single) / (ΔCapTimCnt / F_cap), where N_m represents the mechanical speed of the motor (in rpm).

[0105] The embodiments of the present invention provide an embodiment of a method for measuring speed with an incremental encoder. It should be noted that, although a logical sequence is shown in the flow chart, in some cases, the steps shown or described may be executed in an order different from that shown here.

[0106] like Figure 3 As shown, Figure 3 The schematic diagram of the structure of the hardware operating environment of the incremental encoder involved in the embodiment of the present invention is shown in FIG. The incremental encoder may include: a processor 1001, such as a CPU, a memory 1005, a user interface 1003, a network interface 1004, and a communication bus 1002. The communication bus 1002 is used to realize the connection and communication between these components.

[0107] Those skilled in the art will understand that Figure 3 The incremental encoder structure shown in the figure does not constitute a limitation on the incremental encoder, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0108] like Figure 3 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and an incremental encoder speed measurement program. The operating system is a program that manages and controls the hardware and software resources of the incremental encoder, the incremental encoder speed measurement program, and the operation of other software or programs.

[0109] exist Figure 3 In the incremental encoder shown, the user interface 1003 is mainly used to connect to the terminal and communicate data with the terminal; the network interface 1004 is mainly used for the background server and communicates data with the background server; the processor 1001 can be used to call the incremental encoder speed measurement program stored in the memory 1005.

[0110] In this embodiment, the incremental encoder includes: a memory 1005, a processor 1001, and an incremental encoder speed measurement program stored in the memory and executable on the processor, wherein:

[0111] When the processor 1001 calls the incremental encoder speed measurement program stored in the memory 1005, the following operations are performed:

[0112] Obtain the number of captured pulses and the captured pulse time at the current speed calculation moment, and obtain the number of captured pulses and the captured pulse time at the last speed calculation moment;

[0113] Determine the pulse number deviation according to the captured pulse number at the current speed calculation moment and the captured pulse number at the previous speed calculation moment, and determine the pulse time deviation according to the captured pulse time at the current speed calculation moment and the captured pulse time at the previous speed calculation moment;

[0114] Get the number of pulses and timer clock frequency corresponding to each circle;

[0115] Determine a first ratio of the pulse number deviation to the pulse number corresponding to each revolution, and determine a second ratio of the pulse time deviation to the timer clock frequency;

[0116] The actual rotation speed of the motor is determined according to the product of the first ratio and the second ratio.

[0117] When the processor 1001 calls the incremental encoder speed measurement program stored in the memory 1005, the following operations are performed:

[0118] The actual speed calculation formula of the motor is used to determine the actual speed of the motor. The actual speed calculation formula of the motor is:

[0119] N_m=60*(ΔCapPulsCnt / PPR_single) / (ΔCapTimCnt / F_cap);

[0120] Among them, ΔCapPulsCnt is the pulse number deviation, PPR_single is the number of pulses corresponding to each circle, ΔCapTimCnt is the pulse time deviation, F_cap represents the timer clock frequency for recording the moment of capturing the pulse, the first ratio of the pulse number deviation to the number of pulses corresponding to each circle is ΔCapPulsCnt / PPR_single, and the second ratio of the pulse time deviation to the timer clock frequency is ΔCapTimCnt / F_cap.

[0121] When the processor 1001 calls the incremental encoder speed measurement program stored in the memory 1005, the following operations are performed:

[0122] If the pulse width of a single pulse signal is less than the maximum capture period of the timer, a first compensation value is determined, and the pulse time deviation is determined according to the capture pulse time at the current speed calculation time, the capture pulse time at the last speed calculation time and the first compensation value;

[0123] If the pulse width of a single pulse signal is greater than the maximum capture period of the timer, a second compensation value is determined. The pulse time deviation is determined based on the capture pulse time of the current speed calculation moment, the capture pulse time of the last speed calculation moment and the second compensation value. The second compensation value is greater than the first compensation value.

[0124] When the processor 1001 calls the incremental encoder speed measurement program stored in the memory 1005, the following operations are performed:

[0125] Calculate the period according to the maximum capture period and the current rotation speed, and determine the period multiple;

[0126] Determine the number of speed cycles without pulse number deviation, determine the number of timer cycles for capturing pulse moments, and determine the initial capture pulse time deviation between the capture pulse moment at the current speed calculation moment and the capture pulse moment at the previous speed calculation moment;

[0127] The second compensation value is determined according to the number of rotation speed cycles, the number of timer cycles, the cycle multiple and the initial capture pulse time deviation.

[0128] When the processor 1001 calls the incremental encoder speed measurement program stored in the memory 1005, the following operations are performed:

[0129] The second compensation value is determined by using a second compensation value calculation formula, and the second compensation value calculation formula is:

[0130]

[0131] Among them, CapCntComp is an integer, N no P u l s is the number of speed cycles, T_b is the maximum capture cycle, T_c is the speed cycle, CapARR is the number of timer cycles at the capture pulse moment, N is the cycle multiple, ΔCapTimCnt is the initial capture pulse time deviation.

[0132] When the processor 1001 calls the incremental encoder speed measurement program stored in the memory 1005, the following operations are performed:

[0133] If at the current speed calculation moment, the pulse width of a single pulse signal is greater than the pulse width of a single pulse signal corresponding to a preset speed resolution, the actual speed is cleared.

[0134] When the processor 1001 calls the incremental encoder speed measurement program stored in the memory 1005, the following operations are performed:

[0135] Get the current calculated speed and the last calculated speed;

[0136] Determining a speed difference between the currently calculated speed and the last calculated speed;

[0137] If the speed difference is greater than a preset speed, the preset speed is used to perform speed compensation on the last calculated speed.

[0138] When the processor 1001 calls the incremental encoder speed measurement program stored in the memory 1005, the following operations are performed:

[0139] Obtaining the capture time of the rising edge of the pulse signal and the capture time of the falling edge adjacent to the rising edge, and obtaining the number of pulses corresponding to the rising edge and the number of pulses corresponding to the falling edge;

[0140] Establishing a first association relationship between the capture time of the rising edge and the number of pulses of the rising edge, and establishing a second association relationship between the capture time corresponding to the falling edge and the number of pulses corresponding to the falling edge;

[0141] The first association relationship and the second association relationship are stored in a data cache area to obtain the number of captured pulses and the captured pulse time at the current speed calculation moment, and the number of captured pulses and the captured pulse time at the last speed calculation moment from the data cache area.

[0142] Based on the same inventive concept, an embodiment of the present application also provides a computer-readable storage medium, which stores an incremental encoder speed measurement program. When the incremental encoder speed measurement program is executed by a processor, it implements the various steps of the incremental encoder speed measurement method as described above and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0143] Since the storage medium provided in the embodiments of the present application is the storage medium used to implement the method of the embodiments of the present application, based on the method introduced in the embodiments of the present application, the person skilled in the art can understand the specific structure and deformation of the storage medium, so it is not repeated here. All storage media used in the methods of the embodiments of the present application belong to the scope of protection of this application.

[0144] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.

[0145] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0146] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, TV, or network device, etc.) to execute the methods described in each embodiment of the present invention.

[0147] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A method for measuring speed using an incremental encoder, characterized in that: The incremental encoder speed measurement method comprises: Obtain the number of captured pulses and the captured pulse time at the current speed calculation moment, and obtain the number of captured pulses and the captured pulse time at the last speed calculation moment; Determine the pulse number deviation according to the captured pulse number at the current speed calculation moment and the captured pulse number at the previous speed calculation moment, and determine the pulse time deviation according to the captured pulse time at the current speed calculation moment and the captured pulse time at the previous speed calculation moment; Get the number of pulses and timer clock frequency corresponding to each circle; Determine a first ratio of the pulse number deviation to the pulse number corresponding to each revolution, and determine a second ratio of the pulse time deviation to the timer clock frequency; The actual rotation speed of the motor is determined according to the product of the first ratio and the second ratio.

2. The incremental encoder speed measurement method according to claim 1, characterized in that: The step of determining the actual speed of the motor according to the product of the first ratio and the second ratio comprises: The actual speed calculation formula of the motor is used to determine the actual speed of the motor. The actual speed calculation formula of the motor is: N_m=60*(ΔCapPulsCnt / PPR_single) / (ΔCapTimCnt / F_cap); Among them, ΔCapPulsCnt is the pulse number deviation, PPR_single is the number of pulses corresponding to each circle, ΔCapTimCnt is the pulse time deviation, F_cap represents the timer clock frequency for recording the moment of capturing the pulse, the first ratio of the pulse number deviation to the number of pulses corresponding to each circle is ΔCapPulsCnt / PPR_single, and the second ratio of the pulse time deviation to the timer clock frequency is ΔCapTimCnt / F_cap.

3. The incremental encoder speed measurement method according to claim 1, characterized in that: The step of determining the pulse time deviation according to the capture pulse time at the current speed calculation time and the capture pulse time at the last speed calculation time comprises: If the pulse width of a single pulse signal is less than the maximum capture period of the timer, a first compensation value is determined, and the pulse time deviation is determined according to the capture pulse time at the current speed calculation time, the capture pulse time at the last speed calculation time and the first compensation value; If the pulse width of a single pulse signal is greater than the maximum capture period of the timer, a second compensation value is determined. The pulse time deviation is determined based on the capture pulse time of the current speed calculation moment, the capture pulse time of the last speed calculation moment and the second compensation value. The second compensation value is greater than the first compensation value.

4. The incremental encoder speed measurement method according to claim 3, characterized in that: Determining the second compensation value comprises: Calculate the period according to the maximum capture period and the current rotation speed, and determine the period multiple; Determine the number of speed cycles without pulse number deviation, determine the number of timer cycles for capturing pulse moments, and determine the initial capture pulse time deviation between the capture pulse moment at the current speed calculation moment and the capture pulse moment at the previous speed calculation moment; The second compensation value is determined according to the number of rotation speed cycles, the number of timer cycles, the cycle multiple and the initial capture pulse time deviation.

5. The incremental encoder speed measurement method according to claim 4, characterized in that: The step of determining the second compensation value according to the number of rotation speed cycles, the number of timer cycles, the cycle multiple and the initial capture pulse time deviation comprises: The second compensation value is determined by using a second compensation value calculation formula, and the second compensation value calculation formula is: Among them, CapCntComp is an integer, N no P u l s is the number of speed cycles, T_b is the maximum capture cycle, T_c is the current speed calculation cycle, CapARR is the number of timer cycles, N is the cycle multiple, ΔCapTimCnt is the initial capture pulse time deviation.

6. The incremental encoder speed measurement method according to claim 1, characterized in that: The incremental encoder speed measurement method further includes: If at the current speed calculation moment, the pulse width of a single pulse signal is greater than the pulse width of a single pulse signal corresponding to a preset speed resolution, the actual speed is cleared.

7. The incremental encoder speed measurement method according to claim 1, characterized in that: The incremental encoder speed measurement method further includes: Get the current calculated speed and the last calculated speed; Determining a speed difference between the currently calculated speed and the last calculated speed; If the speed difference is greater than a preset speed, the preset speed is used to perform speed compensation on the last calculated speed.

8. The incremental encoder speed measurement method according to claim 1, characterized in that: The incremental encoder speed measurement method further includes: Obtaining the capture time of the rising edge of the pulse signal and the capture time of the falling edge adjacent to the rising edge, and obtaining the number of pulses corresponding to the rising edge and the number of pulses corresponding to the falling edge; Establishing a first association relationship between the capture time of the rising edge and the number of pulses of the rising edge, and establishing a second association relationship between the capture time corresponding to the falling edge and the number of pulses corresponding to the falling edge; The first association relationship and the second association relationship are stored in a data cache area to obtain the number of captured pulses and the captured pulse time at the current speed calculation moment, and the number of captured pulses and the captured pulse time at the last speed calculation moment from the data cache area.

9. An incremental encoder, characterized in that: The incremental encoder comprises: a memory, a processor, and an incremental encoder speed measurement program stored in the memory and running on the processor. When the incremental encoder speed measurement program is executed by the processor, the steps of the incremental encoder speed measurement method as described in any one of claims 1 to 8 are implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores an incremental encoder speed measurement program, and when the incremental encoder speed measurement program is executed by a processor, the steps of the incremental encoder speed measurement method described in any one of claims 1 to 8 are implemented.

Citation Information

Cited By

  • Hardware-in-loop pulse frequency adaptive measurement simulation device and method

    CN121595951A

  • A hardware-in-the-loop pulse frequency adaptation measurement analog device and method

    CN121595951B