Darby Neh 4:21

 

 

Home
Christianity
Components
Software
Licenses
Links


Mercury Transit


TM logoTelescope Making
Web Ring
|Next | Previous | Random | List Sites| Next 5 | Previous 5 | Join|

PICAXE is a trademark of Revolution Education Ltd (www.picaxe.co.uk)

Excursion: Encoders

A prime component in GOTO mounts and digital setting circles is the optical encoder. There are two types - incremental and absolute. You will need incremental encoders. In my case I have two unknown incremental encoders attached to the back of the motors I plan to use. A better option is to separate the encoders from the motors. Encoders work by shining light - quite often infra red - through a disk with slots in it with a light sensor on the other side. When the slot is between the light source and the sensor the encoder puts out a logical high. When the light is blocked by the disk, it puts out a logical 0.  So as the disk turns the output moves from 0 to 1 and back again in a square wave.

You can then measure the speed of rotation or the amount of rotation by counting pulses. If you count the ones or zeros - also called level triggered - then you are doing x1 decoding. If you count the transitions from 0 to 1 and 1 to 0 - also called edge triggered - you are doing x2 decoding.

The problem with this is that while you can measure rotation by counting the pulses, you don't know which direction it is going in. In addition your precision is limited by how accurately you can create the disk and the limitations of light leakage. So they add a second set of sensors and light sources slightly offset from the others. This gives you two square-waves on what are called channel A and channel B.  If A leads B in pattern then it is going in one direction and if B leads A it is going in the other direction. In addition the second channel increases the highest possible precision to x4.

Finally in some cases they are worried that the electronics counting these things will get out of step . They add a third set of light sources and sensors. These are generally toward the center, solid area of the disk. There is in this case a single hole. This produces a pulse once per revolution and is called the Z channel or the index channel. My encoders have the hole in the disk but there don't seem to be any wires to support the z channel.

Identifying the direction

You tell the direction of rotation by comparing the current values on the two channels with the previous state.

Now
01 11 10 00
Previous 01 S 1 E -1
11 -1 S 1 E
10 E -1 S 1
00 1 E -1 S

In this table, S stands for the same or no change in state, E stands for error ie it is theoretically impossible to get here, and the 1 and -1 are the two directions.

One way of programming this is to create a table and use the current value and the previous state as a 4 bit offset into the table.

Encoders and the Picaxe

Originally I had intended to decode the encoders in software on the picaxe. This was until I read with interest the admiration of the hot picaxe programmers on the picaxe forum for someone who had managed to decode around 300Hz. I estimated that my encoders would run at about 13KHz. I began looking for a hardware solution.

Estimating decoding frequency.

You can estimate the frequency by simply multiplying it out. I plan to run my motors on 12v and according to their datasheet they will run at 2000rpm at 12v. I counted the pulses from the encoders and got 80 per revolution. I know this is probably inaccurate so say it is 100.  Using x4 decoding gives me 400 events per revolution that I need to decode.  So the frequency is:

            f= 2000 x 400  / 60
             =  13,333Hz

This is all fairly rough so I will need to allow plenty of margin for error.

Hardware Decoders

Darby Jer 32:17You can build a decoder out of hardware. I found a logic diagram and looked at what it would take to build it. When I had identified 20 to 30 discrete chips for two encoders, I gave up. BTW the logic design comes from fpga4fun.

There are three sets of ICs that will do this job for you. There are no doubt others but I found only three. The UK firm Genapta make some ICs that will do everything including the counting. They appeared to be the most expensive and hard to get. LSI in the US also make encoder interface ICs. However they are designed to interface with either counter ICs or microcontrollers. So they would need more chips than the other two options. Having said that even with the extra chips they are probably the cheapest option. They also seem to be very common. The third is a set of chips made by Avago that also do all the work including counting. These are expensive but not as expensive as the Genapta offering. They are also in common use among the robotics fraternity.

Depending on where you are will depend on what is best for you. I could neither afford nor get the Genapta chips. I had trouble getting the LSI chips and found only one source for the Avago chips locally. Considering my skill level and my wounds from the uLCD experience I paid the $AUS32 for an Avago HCTL-2032. This will be the most expensive chip in the whole unit.