Quadrature encoder interface. Build Quadrature Decoder with 32 bit counter from low-cost AVR controller


Quadrature decoders are used to determine the angle of rotation of an axis. The rotation direction, rotation speed and position of the rotor is important for many applications. Most industry available decoders chips have 16 or 24 bit counters, what usually are not big enough for some applications. Position count of this Quadrature Decoder can be easily extended from 32 till 64 bits. The idea is employed on site: http://www.mcselec.com/an_115.htm. We added controller software with implemented simple digital filter and fast parallel communication interface.

Schematics

Communication protocol

Data are synchronized using PD0 and PD1 pins in handshaking mode. By default PD0 and PD1 are set to 1.

Command : "Reset Counter" (00).
1. External controller sets pins PD5, PD6 to 0. (Command: reset counter )
2. External controller sets Enable pin to 0. (Synchronization. Low level is active)
3. AT90S2313 detects Enable signal low level , resets internal Counter to zero, and sets Data_Ready pin to 0 (command is done).
4. External controller detects Data_Ready signal low level and sets Enable pin to 1.
5. AT90S2313 detects high Enable signal and sets Data_Ready pin to 1.

Command: "Read first (lowest) byte" (10).
1. External controller sets pins PD5 to 0, PD6 to 1. (Command: read lowest byte)
2. External controller sets Enable pin to 0. (Synchronization. Low level is active)
3. AT90S2313 detects Enable signal low level, sends Lowest Counter data byte to PB port and sets Data_Ready pin to 0 (command is done).
4. External controller detects Data_Ready signal low level, reads data byte from PB output and sets Enable pin to 1.
5. AT90S2313 detects high Enable signal and sets Data_Ready signal to 1.

Command: "Read second or next byte" (01).
1. External controller sets pins PD5 to 1, PD6 to 0. (Command: read next byte)
2. External controller sets Enable pin to 0. (Synchronization. Low level is active)
3. AT90S2313 detects Enable signal low level, sends next Counter data byte to PB port and sets Data_Ready pin to 0 (command is done).
4. External controller detects Data_Ready signal low level, reads data byte from PB output and sets Enable pin to 1.
5. AT90S2313 detects high Enable signal and sets Data_Ready signal to 1.

Command: "Reserved" (11). The command is employed to make any response.
1. External controller sets pins PD5 to 1, PD6 to 1. (Reserved command: do nothing)
2. External controller sets Enable pin to 0. (Synchronization. Low level is active)
3. AT90S2313 detects Enable signal low level and sets Data_Ready pin to 0 (command is done).
4. External controller detects Data_Ready signal low level and sets Enable pin to 1.
5. AT90S2313 detects high Enable signal and sets Data_Ready signal to 1.

Instruction, how to read signed long integer (4 bytes = 32bits: Range -2147483648 to 2147483647) from AT90S2313 chip.The sequence of commands is: "Read lowest byte", "Read second or next byte", "Read second or next byte", "Read second or next byte". Actually, external controller can read only 1 byte (lowest), or only 2 bytes, or only 3 bytes, if more significant bits are no more important.

Software

Note: The Freeware is tested on prototype board and supplied as it is. The author disclaims all warranties of any kind.

Every AVR flash controller needs embedded software. Download open code C project for CodeVisionAVR Standard. The compiler available on HP InfoTech. Noncommercial size limited version works as well. Download compiled Hex file, ready to load into AT90S2313 chip

AT90S2313 chip programmer PG302 is available from Iguana Labs.