Quadrature decoder Detailed quadrature decoder on the stm32

 

 

Encoder

  Encoder definition:

In digital systems, there is often a need for the information (input) into a specific code (output). The binary code arrangement according to certain rules, for example, 8,421 yards, Gray code, so that each set of tags having a particular meaning (or on behalf of a digital control signal) is called encoding. 
A logic circuit having a coding function called an encoder. Encoder has a plurality of inputs, at a time only one input signal is converted into a binary code. If an encoder has N inputs and n outputs, the output should satisfy the relationship between the terminal and the input terminal N≤2n.
8, for example, wire line encoder -3 and 10 -4 wire line encoder 8 respectively input, and the 3-bit binary code output 10 input 4-bit binary code output.

  working principle:

  Applied to the speed control or position control system conventional detecting element . Divided into incremental encoders and absolute encoders .

  We introduce here only A rotary encoder is an incremental encoder, a rotary encoder is used to measure the speed of the apparatus. It is divided into single and dual output two kinds of output. The main technical parameters of pulses per revolution has (have tens to thousands), and the power supply voltage. Single-output refers to the output of the rotary encoder is a set of pulses, and the dual output pulses from the rotary encoder outputs two phase difference of 90 degrees, by two sets of pulses which not only can measure the speed, direction of rotation may also be determined.

A photoelectric encoder has a central axis, through which the annular dark scorelines, a photoelectric reading device transmitting and receiving, to obtain four sine wave signals into A, B, C, D, each sine wave a phase difference of 90 degrees (with respect to a cycle of 360 degrees), the C, D reverse signal, superimposed on a, B on the two phases can enhance the stabilization signal; each of the other revolution output pulse Z to represent zero phase reference bit.
Since A, B two-phase difference of 90 degrees, the former by comparing the relative phases A or B front to discriminate encoder positive rotation and reverse rotation, through zero pulse is obtained with reference to the zero encoder position.

Number of lines :
  Resolution - encoder provides 360 degrees of rotation of each of the through much or dark scorelines called resolution, name resolution indexing, or said direct line number, typically every 5 to 10,000 rpm of the line. If the encoder is a line 512, indicating that the revolution of the encoder outputs a corresponding signal line 500 pulses. This is quite useful if we want to get rotation angle: pulse count / 512.

Different connection :

  • Single-phase coupled to count in one direction, speed in one direction.
  • AB two coupled, for positive and negative counts, forward and reverse and speed determination.
  • A, B, Z-phase coupled with the reference bit for correcting position measurements.

 

Quadrature decoder

I use four lines in the lab: VCC, GND, A-line, Dir line. Taobao address

The following sources: quadrature decoder on the stm32

About quadrature decoder, let me explain ,,,, I would first say encoder quadrature decoder ,,,, what is actually pricey big name on it

I used to look at an encoder

The number of line encoder, is that the number of revolution of the encoder output pulses,, if a 500 line encoder is the encoder described ,,, revolution corresponding signal line 500 outputs pulses ,,,, Why is the corresponding ,,, above for the encoder is such that there ,,,, but there are a lot encoder signal line is some line ,,, revolution pulse outputs corresponding to the number of lines, ,, some signal line is a revolution on the output of the encoder pulse ,,,, that depends on the information ......

See I used above, and by using this encoder A, B, VCC, GND which four wires ,,

A revolution of the encoder signal line 500 is output pulse ,,,, B signal line 500 is also output pulses, however ,,

Forward time

Reverse time

Forward the signal line when the first output signal A, the output signal line B

When the inverted signal to the output signal line B, the A line output

Suppose measured simply forward pulses or reverse pulses simply measured, then just use a microcontroller arbitrarily selected signal line is on the line, and then the pulse count ,,,,

If both said that if a motor forward reverse there ,,,, I want to know how much the motor is definitely forward laps

那么就需要用正转的圈数减去反转的圈数了,,,,,,那么问题来了,,,怎么测正转圈数和反转圈数

其实传统的做法

关于D触发器,,,,当clk引脚来一个上升沿,D引脚是什么电平,,那么Q就输出什么电平,,Q非,,与Q相反

现在如果说电机正转

可以看到每当B来上升沿的时候,A信号总为高电平,,,所以Q会输出高电平

设置A为上升沿进入其,,,中断函数

然后判断一下Q是否为高电平,如果为高电平正转变量自加一

如果电机反转

 

可以看到每当B来上升沿的时候,A信号总为低电平,,,所以Q会输出低电平

设置B为上升沿进入其,,,中断函数

然后判断一下Q是否为低电平,如果为低电平反转变量自加一

 然后 正转变量减去反转变量就能得到电机到底正转了多少圈......这样就会得到一个相对的变量,,这个变量呢,就是单片机正交解码的值

说白了单片机的正交解码功能就是得到一个正反转,,,相对的变量,,,,这个变量呢,,你正转的时候他会加,你反转的时候他会减,

 

Guess you like

Origin www.cnblogs.com/-wenli/p/11482316.html