A decoding method for incremental encoder

By detecting the edge interrupt and level status of the output of incremental encoders A and B, and updating the AB count data, high real-time and accurate steering detection is achieved, solving the inaccurate steering detection and data instability in the prior art. The problem.

CN112117994BActive Publication Date: 2024-12-13QINGDAO CCS ELECTRIC CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010996649.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-21
Publication Date
2024-12-13
Estimated Expiration
2040-09-21

AI Technical Summary

Technical Problem

The existing incremental encoder has low real-time performance during steering detection and the data is not accurate enough, making it difficult to quickly lock the rotation direction and rotation position, and it is easy to frequently update data due to the small swing of the encoder.

Method used

Use the detection of edge interrupts of A and B outputs, and judge the steering according to the level state of B/A output when the edge interrupts A/B outputs. The accumulated AB count data is updated based on the judged steering. When the accumulated data meets the set magnification value. Output rotation direction and position information, real-time steering judgment and data accumulation are achieved through edge interruption and level detection.

Benefits of technology

It improves the real-time and accuracy of incremental encoder steering detection, reduces cumulative errors, avoids the problem of frequent data updates, and adjusts the detection accuracy and output stability by setting the magnification value.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112117994B_ABST
    Figure CN112117994B_ABST
Patent Text Reader

Abstract

The present invention discloses a decoding method for an incremental encoder, which detects edge interruptions of A and B outputs, judges the direction of the incremental encoder according to the level state of the B / A output when the A / B output edge is interrupted, and updates the accumulated AB count data based on the judged direction of rotation, and when the accumulated AB count data meets the specified relationship of the set magnification value, updates the rotation direction and rotation position information output by the incremental encoder to the outside; wherein the set magnification value is the number of data updates for one rotation of the incremental encoder. This method of edge interruption detection + accumulated counting + data output when the specified relationship of the set magnification value is met for both A and B outputs has a faster speed of judging the direction of rotation, high real-time detection, more accurate detection data, and can ensure that the subsequent accumulated count is more accurate, reduce the accumulated error, and can avoid the problem of frequent data updates in the final collected data due to the small swing of the encoder's direction of rotation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of electronic control technology, and in particular relates to an incremental encoder decoding method. Background Art

[0002] The incremental encoder is a widely used rotary measuring tool. Its output signals generally have three groups of signals, such as Figure 1 As shown, it includes A-channel output, B-channel output and Z-channel output, among which, A and B-channels output a set number of pulses every time the incremental encoder rotates one circle, and the output pulse of A-channel differs from the output pulse of B-channel by 90 degrees. The specific number of output pulses per circle is determined by the number of internal gratings; Z-channel outputs one pulse every time the incremental encoder rotates one circle, which is used to determine the counting zero point or mark the number of rotations. Summary of the invention

[0003] The purpose of the present invention is to provide an incremental encoder decoding method, which uses a technical means to judge the direction of rotation once when any output of A or B is interrupted + output based on the accumulated AB count data of the direction of rotation + when the AB count data meets the set multiplier value, so as to achieve the technical effect of high real-time steering detection and more accurate detection data for the incremental encoder.

[0004] The present invention is implemented by the following technical solutions:

[0005] A decoding method for an incremental encoder is proposed, which is applied to an incremental encoder. The incremental encoder has three outputs, A, B and Z, wherein A and B output a set number of pulses per rotation of the incremental encoder, and the output pulse of A differs from the output pulse of B by 90 degrees; Z outputs a pulse per rotation of the incremental encoder; the method comprises: detecting edge interrupts of A and B outputs; judging the direction of rotation of the incremental encoder according to the level state of B / A output when the A / B output edge is interrupted, and updating the accumulated AB count data based on the judged direction of rotation; when the accumulated AB count data satisfies the specified relationship of the set magnification value, updating the rotation direction and rotation position information outputted by the incremental encoder; wherein the set magnification value is the number of data updates per rotation of the incremental encoder.

[0006] Furthermore, the direction of the incremental encoder is determined according to the level state of the B / A output when the A / B output edge is interrupted, and the accumulated AB count data is updated based on the determined direction, specifically: when the A output edge interrupt is detected, the level state of the B output is detected, and the direction of the incremental encoder is determined according to the level state of the B output; and, when the B output edge interrupt is detected, the level state of the A output is detected, and the direction of the incremental encoder is determined according to the level state of the A output; when the direction of rotation is positive, the AB count data is accumulated according to the addition operation, and when the direction of rotation is negative, the AB count data is accumulated according to the subtraction operation.

[0007] Furthermore, the direction of the incremental encoder is determined according to the level state of the B / A output when the A / B output edge is interrupted, and the accumulated AB count data is updated based on the determined direction. Specifically, the detection of one A output edge interruption and one B output edge interruption is regarded as a detection cycle. Within one detection cycle, when the A output edge interruption is detected, the level state of the B output is detected, and the direction of the incremental encoder is determined according to the level state of the B output and temporarily stored; when the B output edge interruption is detected, the level state of the A output is detected, and the direction of the incremental encoder is determined according to the level state of the A output and temporarily stored; at the end of one detection cycle, the direction of the incremental encoder is determined according to the temporarily stored direction, and the AB count data is accumulated according to the addition operation when the direction is positive, and the AB count data is accumulated according to the subtraction operation when the direction is negative.

[0008] Furthermore, the method also includes: when an edge interruption of the Z output is detected, determining the current direction of the incremental encoder based on the accumulated AB count data; accumulating the number of rotations of the incremental encoder based on the current direction; and clearing the accumulated AB count data.

[0009] Furthermore, the method also includes: when an interrupt request is received, receiving and updating a set magnification value.

[0010] Furthermore, the number of rotations of the incremental encoder is accumulated based on the current direction, specifically including: when the current direction is positive, the number of rotations is increased by 1; when the current direction is reverse, the number of rotations is decreased by 1.

[0011] Furthermore, when the accumulated AB count data satisfies the set multiplier value, the method also includes: determining the current direction of the incremental encoder based on the accumulated AB count data; clearing the accumulated AB count data; when the current direction is positive, re-accumulating the AB count data according to the addition operation; when the current direction is negative, re-accumulating the AB count data according to the subtraction operation.

[0012] Compared with the prior art, the advantages and positive effects of the present invention are as follows: in the incremental encoder decoding method proposed by the present invention, the edge interruptions of the A and B outputs are detected, and the direction of the incremental encoder is judged according to the level state of the B / A output when the A / B output edge is interrupted, and the AB count data is accumulated according to the judged direction of rotation. When the AB count data satisfies the specified relationship of the set magnification, the incremental encoder outputs the rotation direction and rotation position information once. The set magnification value here is the number of data updates set for the incremental encoder to rotate one circle, that is, the number of times the incremental encoder outputs the rotation direction and rotation position information; based on the decoding method proposed by the present invention, during the process of the incremental encoder rotating one circle, its direction of rotation and rotation position can be obtained according to the number of times limited by the set magnification value, the rotation direction of the incremental encoder can be quickly locked, the speed of judging the direction of rotation is fast, the real-time performance of the direction of rotation detection is high, the detection data is more accurate, and the subsequent cumulative counting can be guaranteed to be more accurate, reducing the cumulative error.

[0013] Moreover, based on the technical means of accumulating AB count data + clearing AB count data when the set multiplier value is met in the present invention, the problem of frequent data updates in the final collected data due to the small steering swing of the encoder can be avoided while reducing the cumulative error.

[0014] Furthermore, the set magnification value can be used in actual application to adjust the detection accuracy and optimize the stability of the output data.

[0015] Furthermore, the Z output can determine the current direction of rotation based on the accumulated AB count data, and can count the accumulated number of rotations.

[0016] Furthermore, when the edge interruption of the Z output is detected, the accumulated AB count data is cleared to eliminate the accumulated error, and automatic calibration of the A output and the B output can be achieved in each circle.

[0017] Other features and advantages of the present invention will become more apparent after reading the detailed description of the embodiments of the present invention in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 This is a schematic diagram of the A, B, and Z outputs of the incremental encoder;

[0019] Figure 2 A flowchart of the incremental encoder decoding method proposed by the present invention;

[0020] Figure 3 This is a flow chart of a specific embodiment of the incremental encoder decoding method proposed in the present invention. DETAILED DESCRIPTION

[0021] The specific implementation modes of the present invention will be further described in detail below in conjunction with the accompanying drawings.

[0022] The incremental encoder decoding method proposed by the present invention is applied to the incremental encoder, such as Figure 1 As shown, the incremental encoder has three outputs, A, B, and Z. Among them, A and B output a set number of pulses every time the incremental encoder rotates one circle, and the output pulse of A differs from the output pulse of B by 90 degrees; Z outputs one pulse every time the incremental encoder rotates one circle.

[0023] Based on the above, the incremental encoder decoding method proposed by the present invention is implemented by edge interruption, level detection and temporary storage of accumulated data. Figure 2 As shown, including:

[0024] Step S21: Detect edge detection interrupts of A and B outputs.

[0025] Use the microcontroller to detect the edge interrupts of the A output and B output.

[0026] In the present invention, the edge interrupts of both the A output and the B output are detected.

[0027] Step S22: judging the direction of the incremental encoder according to the level state of the B / A output when the A / B output edge is interrupted, and updating the accumulated AB count data based on the judged direction of rotation.

[0028] Combination Figure 1 As shown, since the phase difference between output A and output B is 90 degrees, when the incremental encoder rotates forward, when the output A is interrupted by an edge, the output B is high, and when the output B is interrupted by an edge, the output A is low; when the incremental encoder rotates reversely, when the output A is interrupted by an edge, the output B is low, and when the output B is interrupted by an edge, the output A is high.

[0029] Therefore, the rotation direction of the incremental encoder can be determined based on the level state of the B / A output during the A / B output. In the prior art, in order to determine the rotation direction of the incremental encoder, the edge interruption of the unidirectional output detector is usually used, and the level state of the other output is determined when one edge is interrupted, so as to determine the rotation direction of the encoder. Different from the prior art, in the present invention, both the edge interruption of the A output and the edge interruption of the B output are detected. When the edge interruption of the A output is detected, the level state of the B output is determined, and when the edge interruption of the B output is detected, the level state of the A output is determined.

[0030] After detecting edge interruption and determining the direction of rotation, the method of outputting data when the temporarily stored cumulative count meets the specified relationship of the set ratio value is adopted to improve the speed and accuracy of determining the rotation direction and the accuracy of the rotation position data.

[0031] Specifically, the present invention provides two data: AB count data and a set magnification value; wherein the AB count data is accumulated in the following manner: when the rotation direction of the encoder is positive, it is accumulated according to an addition operation; when the rotation direction of the encoder is negative, it is accumulated according to a subtraction operation.

[0032] The setting magnification value is the number of data updates during one rotation of the encoder, which can also be understood as the number of data outputs during one rotation of the encoder. The data here at least includes the rotation direction and rotation position information. The setting magnification value is less than or equal to the number of unidirectional output pulses. Setting, N is the number of pulses of unidirectional output. In practical applications, the number of external outputs can be modified by initiating an interrupt request and inputting a set multiplier value set according to actual needs to the microcontroller. The smaller the n value, the higher the output accuracy. n is an integer greater than or equal to zero.

[0033] The rotational position information is determined based on the AB count data. For example, when the encoder rotates one circle and outputs N pulses A or B, the unidirectional output outputs one pulse each time, that is, each time an edge interruption is detected for the unidirectional output, the encoder rotation angle changes by P=360 / N degrees. During the period when edge interruptions are detected for both A and B outputs, each time an edge interruption is detected, the encoder rotation angle changes by Q=360 / 2N degrees. It can be simply understood as follows: the accumulated AB count data implies the accumulated rotation angle of the incremental encoder. When the AB count data is accumulated each time an edge interruption is detected, the rotational position can be calculated based on the product of the accumulated AB count data and Q. When the AB count data is accumulated each time two edge interruptions are detected, the rotational position can be calculated based on the product of the accumulated AB count data and P.

[0034] Based on the above, in some embodiments of the present invention, taking the case where the AB count data is increased by 1 when the rotation direction is determined to be positive when an edge interrupt is detected, and the AB count data is decreased by 1 when the rotation direction is determined to be negative when an edge interrupt is detected as an example, when the A edge interrupt is detected and the rotation direction is determined to be positive according to the level state of the B output, the AB count data is accumulated and increased by 1 and temporarily stored, and when the B edge interrupt is detected and the rotation direction is determined to be positive according to the level state of the A output, the AB count data is accumulated and increased by 1 again and updated for temporary storage, conversely, when the A edge interrupt is detected and the rotation direction is determined to be negative according to the level state of the B output, the AB count data is accumulated and decreased by 1 and temporarily stored, and when the B edge terminal is detected and the rotation direction is determined to be negative according to the level state of the A output, the AB count data is accumulated and decreased by 1 and updated for temporary storage.

[0035] In some other embodiments of the present invention, detecting one A output edge interruption and one B output edge interruption is regarded as one detection cycle. Within one detection cycle, when an A output edge interruption is detected, the level state of the B output is detected, and the direction of the incremental encoder is determined based on the level state of the B output and temporarily stored; when an B output edge interruption is detected, the level state of the A output is detected, and the direction of the incremental encoder is determined based on the level state of the A output and temporarily stored; at the end of one detection cycle, the direction of the incremental encoder is determined based on the temporarily stored direction, and the AB count data is accumulated by 1 and temporarily stored when the direction is positive, and the AB count data is accumulated by 1 when the direction is negative.

[0036] In the embodiment of the present invention, each time an edge interrupt is detected and the rotation direction is determined, the currently determined rotation direction is temporarily stored, and when an edge interrupt is detected and the rotation direction is determined next time, the temporarily stored rotation direction is updated.

[0037] In the embodiment of the present invention, positive and negative are relative, that is, when positive is clockwise, negative is counterclockwise, and when positive is counterclockwise, negative is clockwise.

[0038] Step S23: When the accumulated AB count data satisfies the specified relationship of the set magnification value, the rotation direction and rotation position information output by the incremental encoder is updated.

[0039] When the accumulated AB count data satisfies the specified relationship of the set multiplier value, the rotation direction and rotation position information are outputted externally. The rotation direction can be determined according to the rotation direction data temporarily stored in step S22, or according to the AB count data. Based on the principle of adding 1 to the positive direction and subtracting 1 to the negative direction, if the AB count data is greater than zero, the rotation direction when outputted externally is positive; if the AB count data is less than zero, the rotation direction when outputted externally is negative.

[0040] The setting ratio value designation relationship here means that if the AB count data is accumulated once each time an edge interruption is detected, then when the accumulated AB count data meets twice the setting ratio value, the rotation direction and rotation position information are output once; if the AB count data is accumulated once each time two edge interruptions are detected, that is, the AB count data is accumulated once at the end of a detection cycle, then when the accumulated AB count data is equal to the setting ratio value, the rotation direction and rotation position information are output once.

[0041] The rotational position information is calculated based on the product of the accumulated AB count data and P or Q.

[0042] When outputting the rotation direction and rotation position information of the incremental encoder, the accumulated AB count data is cleared, and when the currently stored direction is positive, the AB count data is re-accumulated according to the addition operation. When the currently stored direction is negative, the AB count data is re-accumulated according to the subtraction operation, and the next external output judgment and accumulation cycle is entered.

[0043] Below Figure 3 Taking the illustrated embodiment as an example, the incremental encoder decoding method proposed by the present invention is described in detail.

[0044] In this embodiment, the encoder rotates one circle and A and B output 1024 pulses. The multiplication value is set to 256, so that detecting the edge interruption of A output to determine the level state of B output + detecting the edge interruption of B output to determine the level state of A output is one detection cycle.

[0045] In one detection cycle, with the edge interrupt of A output as the base point, the level state of B output is judged when the edge interrupt of A output occurs. When the level state of B output is low, the temporarily stored steering is set to positive, and when the level state of B output is high, the temporarily stored steering is set to negative. The next edge interrupt, that is, the edge interrupt of B output occurs, the level state of A output is judged. When the level state of A output is low, the temporarily stored steering is set to negative, and when the level state of A output is high, the temporarily stored steering is set to positive.

[0046] At the end of a detection cycle, the AB count data is accumulated and temporarily stored. When the temporary storage direction is positive, the AB count data is accumulated plus 1, and when the temporary storage direction is negative, the AB count data is accumulated minus 1.

[0047] When the encoder rotates continuously forward, the AB count data is greater than zero, and when the encoder rotates continuously reverse, the AB count data is less than zero.

[0048] In this embodiment, the absolute value of the AB count data is calculated. After the AB count data is accumulated after each detection cycle, it is determined whether the absolute value of the AB count data is equal to the set multiplier value. If it is less than the absolute value, the next detection cycle is entered to repeat the above steps. If it is equal to the set multiplier value, the steering and rotation position information is output once, and the accumulated AB count data is cleared. The cleared AB count data is accumulated again by adding 1 or subtracting 1 according to the temporarily stored steering direction, and the next output accumulation is entered.

[0049] In this embodiment, every 256 detection cycles, the AB counting data is equal to the set magnification value, and the rotation direction and rotation position information is output once. The encoder outputs data four times in total when it rotates one circle.

[0050] In this embodiment, based on the real-time direction judgment temporary storage and the accumulation of AB count data, the detection speed of the incremental encoder's steering and rotational position is faster, the real-time performance is high, the detection data is more accurate, and the zeroing operation after each rotation can ensure that the subsequent cumulative count is more accurate, reduce the cumulative error, and avoid the problem of frequent data updates due to the small swing of the encoder's steering direction in the final collected data.

[0051] Based on the characteristics that the setting ratio value can be set and updated, the decoding of the incremental encoder can adjust the detection accuracy according to the actual application and optimize the stability of the output data.

[0052] In some embodiments of the present invention, continue as Figure 3 As shown, the detection of whether one rotation is completed is realized by edge interrupt detection of Z output. Specifically, real-time edge interrupt detection of Z output is performed. When edge interrupt of Z output is detected, the current direction of the incremental encoder can be determined based on the temporarily stored direction or AB count data before clearing, and the number of rotations is counted by adding 1 in a positive direction and subtracting 1 in a negative direction based on the current direction.

[0053] In this embodiment, when an edge interruption of the Z output is detected, that is, when one revolution of the encoder ends, the accumulated AB direction data is cleared. This clearing operation can eliminate the accumulated error and realize automatic calibration of the A output and the B output after each revolution.

[0054] It should be pointed out that the above description is not a limitation of the present invention, and the present invention is not limited to the above examples. Changes, modifications, additions or substitutions made by ordinary technicians in this technical field within the essential scope of the present invention should also fall within the protection scope of the present invention.

Claims

1. A decoding method for an incremental encoder, applied to an incremental encoder, wherein the incremental encoder has three outputs A, B, and Z. in, A and B channels output a set number of pulses every time the incremental encoder rotates one circle, and the output pulse of A channel differs from the output pulse of B channel by 90 degrees; The Z circuit outputs one pulse per rotation of the incremental encoder; Characterized in that the method comprises: Detect edge interrupts on A and B outputs; The direction of the incremental encoder is determined according to the level state of the B / A output when the A / B output edge is interrupted, and the accumulated AB count data is updated based on the determined direction; When the accumulated AB count data meets the specified relationship of the set magnification value, the rotation direction and rotation position information output by the incremental encoder are updated; the rotation direction is determined according to the AB count data, and the rotation position information is calculated according to the product of the accumulated AB count data and P or Q, P=360 / N, Q=360 / 2N, N is the number of pulses output by A or B when the encoder rotates one circle; Wherein, the set magnification value is the number of data updates for one rotation of the incremental encoder; when the accumulated AB count data meets the set magnification value, the method further includes: Determine the current direction of rotation of the incremental encoder based on the accumulated AB count data; Clearing the accumulated AB counting data; When the current direction is positive, the AB count data is re-accumulated according to the addition operation; when the current direction is negative, the AB count data is re-accumulated according to the subtraction operation; The direction of the incremental encoder is determined according to the level state of the B / A output when the A / B output edge is interrupted, and the accumulated AB count data is updated based on the determined direction, specifically: When an edge interruption of the A output is detected, the level state of the B output is detected, and the direction of the incremental encoder is determined according to the level state of the B output; and, When the B output edge interrupt is detected, the level state of the A output is detected, and the direction of the incremental encoder is determined according to the level state of the A output; When the steering direction is positive, the AB count data is accumulated according to the addition operation, and when the steering direction is negative, the AB count data is accumulated according to the subtraction operation.

2. The incremental encoder decoding method according to claim 1, It is characterized in that The direction of the incremental encoder is determined according to the level state of the B / A output when the A / B output edge is interrupted, and the accumulated AB count data is updated based on the determined direction, specifically: One detection cycle is to detect one A output edge interruption and one B output edge interruption. In one detection cycle, when an A output edge interruption is detected, the level state of B output is detected, and the direction of the incremental encoder is determined and temporarily stored according to the level state of B output. When the B output edge interrupt is detected, the level state of the A output is detected, and the direction of the incremental encoder is determined and temporarily stored according to the level state of the A output; At the end of a detection cycle, the direction of the incremental encoder is determined based on the temporarily stored direction, and the AB count data is accumulated according to the addition operation when the direction is positive, and the AB count data is accumulated according to the subtraction operation when the direction is negative.

3. The incremental encoder decoding method according to claim 1, It is characterized in that The method further comprises: When an edge interruption of the Z output is detected, determining the current direction of the incremental encoder based on the accumulated AB count data; The number of revolutions of the incremental encoder is accumulated based on the current direction of rotation; The accumulated AB counting data is cleared.

4. The incremental encoder decoding method according to claim 1, It is characterized in that The method further comprises: When an interrupt request is received, the set magnification value is received and updated.

5. The incremental encoder decoding method according to claim 3, It is characterized in that The number of revolutions of the incremental encoder based on the current direction of rotation, including: When the current direction is positive, the number of rotations is increased by 1; when the current direction is negative, the number of rotations is decreased by 1.