1. Encoder - determine the angle of rotation:

An encoder intended to manage the angular position of a rotating disk, rotating disk may be a wheel, a motor shaft, or any rotating device that needs to locate the angle.

Encoders are divided into two types, absolute encoder and incremental encoder. The translation is absolute encoder and relative encoder. Absolutely encoded encoded text, but because Vietnamese themselves have two types, the other type is translated back to the other. So the translation is relative encoder for incremental encoder.

If we translate the mean, when we read the absolute encoder, it means that the absolute encoder, ie, the signal we receive, clearly indicates the position of the encoder, we do not need any further processing, know exactly the location of encoder.

An incremental encoder, which is an encoder of only 1, 2, or a maximum of 3 loops. Imagine, if you now punch a hole in a spinning disk, you get a signal every spin, and you know the spinning disc. If you now have more holes, you will get more detailed information, which means that the disk rotates 1/4, 1/8, or 1 / n, depending on the number of holes on the incremental encoder. .

Every time we go through a hole, we have to program the device to measure up to 1. Thus, this encoder is called incremental encoder (encoder increased to 1 unit).

b. Operational principle of encoders, leds and holes:

The basic principle of the encoder is that it rotates around the axis. On the disk there are holes (grooves). People use a led light to project on the disk. When the disc is rotating, the hole is not visible (the groove), the luminaire does not penetrate it, the hole (the groove), the luminaire will penetrate through. Then, on the other side of the disc, one puts a collecting eye. With the signals there, or no light shining through, people will notice whether the light is projecting through the hole or not.

When the spindle is rotated, assume that the disk has only one hole, and each time the eye receives a luminous signal, it means that the disk has rotated one round.

This is a very basic principle of the encoder.

However, the question is, how to determine more accurately the position of the spinning disk (smooth) and how to determine which disk is rotating in which direction? That is the problem for us to learn about encoder.

The following figure illustrates the basic principle of encoder operation.

As you can see in the figure, there is a mask disk, which is not rotated, which is a fixed disk, in fact, to mask the light passing through, which makes encoder reading more accurate. We do not mention this mask plate here.

c. Absolute encoder:

The problem we're going to be concerned about here is that it's a matter of finer encoder, which means knowing how the disc was spinning 1/2 loop, 1/4 loop, 1/8 loop or 1 / n loop, Not just a spinning disc.

Back to the basic problem of bits and bits, let's look at the problem in a completely mathematical way:

With a 2-digit binary number, we will have 00, 01, 10, 11, ie 4 states. That means that with 2 digits, we can split the encoder disk into 4 equal parts. And when we turn, we will determine the accuracy to 1/4 round.

Similarly, if for an n-digit number, we will determine the precision to 1 / (2 ^ n) loops.

So how to determine 2 ^ n this state of the encoder disk?

See below:

Here, I give an example with a disk encoder with 2 loops. You will find that, in the innermost ring, there is a half-width groove. Outside the ring, there will be two grooves opposite each other.

So, we need two LEDs to play through the two holes, and two lights.

Suppose that in the first (in the first) loop, the reading lamp is in the open position, the received signal from the receiving eye will be 1. And in the second loop, we are in position There is no hole, so the eye taking ring 2 will read the value 0.

And so, with the number 10, we determine which encoder is lying in the quadrant, which means that we can manage the accuracy of the spin disk to a quarter of a ring. In the example above, if the LED reads 10, the position of the LED must be in the second, upper and left quadrant.

As a result, if the encoder disk has up to 10 loops, we will manage up to 1 / (2 ^ 10) or 1/1024 loops. Or it is said that the resolution of the encoder is 1024 pulse per revolution (ppr).

Here is an example abosulte encoder 8 loops:

So how to design the absolute encoder?

You always pay attention that, to design absolute encoder, one always draws that the N bit (for encoders with N round holes) is in the innermost, which means the largest hole has a 180 degree wide angle, which lies in the same. Because we see that, bit0 (if considered a binary number) will change continuously every 1/2 ^ N rotation, so we need lots of holes. If placed in the can not be painted, because in the smaller radius. In addition, if placed in, the mechanical structure, too close to the axis, and too many holes, will be very weak. Because of these two points, bit0 is always outmost, and bit N-1 is always in the same position as shown above.

d. Incremental encoder:

Seeing that, absolute encoder is very beneficial for cases where the angle of rotation is small, and the motor does not rotate much. Then, absolute encoder processing becomes easier for the user, since the read only value is that we know at the right angle of rotation.

However, if the motor rotates many rounds, this is not beneficial, because then, we have to handle to count the rotation of the shaft.

Also, as you can see, if you design an absolute encoder, you need too many loops, and that leads to a limit on the size of the encoder, because precision machining of holes is too small. is now Not to mention that the design of a range of leds and ear buds also greatly influences this size limit.

In my personal experience, I found the 8 bit encoder is very detailed, and at the DHBKHCM school has a 12bit encoder is the best I know. I have not seen the absolute encoder 16 bits at all, nor do I intend to find it on the internet.

The accuracy of the 12 bit encoder is already 1/4096.

However, this is overcome by the incremental encoder quite simply. So today, most people use incremental encoders in modern applications.

Simply, an incremental encoder will increment by 1 when the pulse is up or down.

You see the following encoder:

You see, every time you rotate through a hole, the encoder increments one unit in the counter.

However, one problem is how to know if the encoder rotates a loop? If we count infinitely like this, we can not know when it's going to end. If you now count the encoder holes to know if it has turned a loop, then with the 1000-hole encoder you will count to the light always.

Not to mention, every time there is some vibration that we can not manage, the encoder will get a pulse. As such, if long-term operation, this error will accumulate, today wrong one impulse, the next day wrong one impulse. In the end, maybe the motor turns two rounds and then you count the first round.

To avoid this harm, an additional positioning hole is included to count the rotations of the encoder.

So, despite the impulse, we see that the encoder goes through the positioning hole, and we know that the encoder has been counted wrong somewhere. If for some vibration, we do not see the encoder going through the positioning hole, then from the pulses, and going through the positioning holes, we will know the encoder's wrong phenomena.

This is a positioning encoder:

However, another big problem is, how do we know which encoder is rotating in what direction? Because regardless of the direction of rotation, the encoder signal is just a single pulse and the two-way rotation is the same.

Therefore, a hole is placed in the middle of the first hole and the positioning hole as follows:

Note that the angular positions of the round holes 1 and the round holes 2 differ. The edges of the hole 2 are located in the middle of the holes 1 and vice versa.

We will look at the encoder in the pulse signal to better understand the encoder. However, you will find that, instead of making two encoders, and using two aligned LEDs, one just needs to make a round hole, and put two LEDs apart.

As a result, you will often find encoders of the form:

e. Signal encoder:

The image above is a pulsed incremental encoder.

(Source: falleaf)

2. Bridge theory H:

a. The structure of the bridge H:

As far as I know, the H-bridge is made up of two major types that I've encountered:

Type 1: Is composed of four transistors (Fet) Same channel N. The circuit diagram is composed of the following:

For this, it is made up of transistors with the same N channel and only two control signals enable the transistors

Type 2: Is composed of two pairs of P, N or FET transistors. Structure diagram of its structure is as follows:

For this design the result is quite stable for small input voltage of about 24V. For high-power circuits, high-power FETs usually do not have a P-channel, so we can not use it this way, but we have to use it in a way.

b. Operating principle of bridge H:

Here I just look at the principle of operation and operation of the H bridge. So I take BJT as an example and Fet is almost the same.

Let's analyze a form of H-bridge as above. These two types have the same principle of operation, only the components that make up the H-bridge and the opening and closing of the transistors or FETs. For type 1 when using the same Fet channel, it is necessary to use the circuit for high power and large voltage. The type 2 is used with small capacity with small input voltage.

We analyze the principle of operation of the circuit 2 as follows:

This H-bridge is controlled by four signals that open and close the valves, which are signals 1 and 2 (as shown). Consider each pros and cons.

As we have bit conditions to collapse to the unity transistor is:

For channel N open, Ube> 0 and open the transistor with current.

+ For P-channel transistor to open, Ube * Controls with forward mode.

In this mode, four control signals are applied to the four transistors and the condition for the current to pass through the load at one time is:

+ Signal 1 = 0 (ie open transistor Q1).

Signal 2 = 0 (That is close transistor Q2).

Signal 3 = 1 (ie close transistor Q3).

Signal 4 = 1 (ie open transistor Q4).

And the path is described in the following figure:

This is the form of forward direction: The current from the source through Q1 then passes through the load and passes Q2 to GND.

* Control in reverse mode

In this mode, we also assign four control signals to four transistors.

And these 4 control signals must satisfy the following:

Signal 1 = 1 (ie transistor lock Q1).

Signal 2 = 1 (ie open transistor Q2).

Signal 3 = 0 (ie open transistor Q3).

Signal 4 = 0 (That is close transistor Q4).

And their form is shown in the following figure:

3. Control logic circuit:

To make it easier to control the H-bridge we should design a logic circuit with two PWM pins and a DIR.

The logic table for the H-bridge is as follows

 PWM DIR Thuận Nghịch 0 0 0 0 0 1 0 0 1 0 1 0 1 1 0 1

4. PID algorithm:

The AT-COM PID algorithm has been introduced to you in the article "PID temperature control using PID algorithm using PIC 16F877A and PT100 temperature sensor", you can review here:

http://at-sky.com.vn/nghien-cuu/vi-dieu-khien-pic/25-dieu-khien-nhiet-do-lo-nhiet-bang-thuat-toan-pid-su-dung-pic-16f877a-va-cam-bien-nhiet-pt100.html#.UfXdxqzebBM

5. System diagram:

a. Microcontroller circuit:

b. H-bridge:

c.  Logic circuit:

d. Max232 circuit:

e. Source circuit: