Optical quadrature encoder decoder/counter
jfischer
Posts: 2
I have an application that I have developed and·integrated a PLC to perform the functions.
The PLC is not precise enough for the job, the period and frequency of the PLC output varies.......
I need to change to a different type of controller.
The application·uses an optical quadrature encoder to provide direct position feed back from a physical, process by incrementing or decrementing a counter.
(Quadrature encoder is·a device that produces two square wave signals,·90 degrees out of phase, each with a 50% duty cycle)
A single event will·occur with each revolution of the quadrature encoder.
The encoder will turn about 300 RPM.
The encoder has a resolution of 1000 pulses per revolution.
The event will be triggered by a comparator that compares the encoder count with a preset value.
When·the preset value in·the comparator equals the counter value of the quadrature encoder, one square wave pulse will be generated on an output line to trigger the event. (Once for each true compare cycle)
The·encoder counter will be compared·counting up or down.
The compare frequency will be about 5hz
Using one of·the SX·products, A·chip like an HCTL-2032 decoder/counter·could·be·interfaced with the controller or code will have to be written for a decoder/counter using the standard inputs.
Has any one used an SX for a quadrature counter/comparator application?
jfischer·
Notes on the HCTL-2032 decoder/counter IC
The HCTL-2032 is a CMOS IC that perform the quadrature decoder, counter, and bus interface function. The HCTL-2032 is designed to improve system performance in digital closed loop motion control systems and digital data input systems. It does this by shifting time intensive quadrature decoder functions to a cost effective hardware solution. The HCTL-2032 consists of 4x/2x/1x-quadrature decoder, a binary up/down state counter, and an 8-bit bus interface. The HCTL-2032 has the dual-axis capability and index channel counter. The use of Schmitt-triggered CMOS inputs and input noise filters allows reliable operation in noisy environments. The HCTL-2032 contains 32-bit counter. It also contains quadrature decoder output signals and cascade signals for use with many standard computer ICs. The HCTL-2032 provides LSTLL compatible tri-state output buffers. Operation is specified for a temperature range from -40 degrees C to +100 degrees C at clock frequencies up to 33MHz.
Comments
There is a quadrature example in the SX/B help file.
How is the "preset count value" put into the system ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
"One experiment is worth a thousand theories"
·
I have interfaced a quadrature encoder directly to an SX28 without external decoder/counter chip. If I read your specs correctly, the encoder will turn at a maximum of 300 RPM which is 5 revolutions/s. With a resolution of 1000 pulses/revolution, the pulse width is 200µs (I hope I did not mess up "revolution" and "resolution" ). Considering an SX clocked at 50 MHz with an average execution speed of 50 MIPS, it should be possible to handle decoding, counting and comparing with the SX alone (no external components).
It is important to note that port B of all SXes has an additional, so-called WKPNDB (wakeup pending) register. This register is not only useful for wakeup control but also for detecting pulses. Port B can be configured that either rising or falling edges occuring at port B pins set the associated bit in the WKPNDB register. In oder to detect the encoder pulses you would run within a fast loop. Instead of polling the pulse inputs directly, you would poll the status of the WKPNDB register instead. This makes sure that no pulses are lost which might be the case when polling the inputs at the "wrong time".
Note that there is no instruction for reading the WKPNDB register. Instead, the following seqzence should be executed:
mov M, #$09 ; Selects the WKPNDB register for subsequent mov !RB, w instructions
mov w, #0
mov !RB, w
The mov !RB, w instruction actually exchanges the contents of w and WKPNDB. After execution, w contains the status of the WKPNDB bits, and WKPNDB is cleared.
As Bean noted, there must be a way to transfer some "preset count value" into the SX. One option would be using a serial protocol, either RS-232, SPI, or I²C. In my SX projects I normally use RS-232 or I²C. All three protocols can be handled by the SX just by software.
One more question: Is it necessary to detect the direction of rotation? If not, the program could be a bit simpler but I don't see any problems handling both encoder outputs with the SX.
BTW, your name sounds "pretty German". As I don't want to bother the forum by using German language here, please feel free sending me a private message in German - if you like. On the other hand, this is an intersting thread, so we should keep it alive here on the forum.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
Günther
The·goal of this device·is to electronically·offset·an event around the axis of the encoder by 1/16, 1/8, 1/4, 1/2, or 3/4 of a rotation of the encoder.
The quadrature counter will have 2X multiplication or will increment the counter by 2000 each turn.
Each time the encoder reaches the count 1999, the counter will reset to 0.
By clearing the quadrature counter, we establish a "Zero" position that will be used as a numerical reference point for the compare function.
The compare function·will produce a trigger for the event by comparing the current counter value with a preset value. (CJE op1, op2, addr Compare op1 to op2 and jump if equal instruction??
When the compare is true, a one shot pulse will be executed and output from the SX.
The SX·will be connected to an industrial·PLC that will provide 3 BCD coded lines and one strobe line·to the SX.
Five·preset values will be stored in·non-volatile memory addresses of the SX: 125, 250, 500, 1000, and 1500
The preset values and operation modes will be·selected by the SX, by·decoding the·3 bit·BCD value.
A BCD number will be presented on 3 inputs of the SX controller each with·a numerical·weight of·4 and·2 and 1·respectively.
When the three BCD bits are output by the·PLC, a "strobe" signal input to the SX will be activated to prompt the·SX to decode the BCD inputs.
When the·SX has completed decoding the BCD inputs, a finish signal will be output to the PLC from the SX controller to cancel the strobe signal and also indicating the BCD number has been successfully decoded.
These are the functions of each BCD values used.
BCD 0 disable or passivate·the SX·device.
BCD 1 enable the clear line for the counter and enable the SX device.
BCD 2 compare the counter with the address location that contains the value 125
BCD 3 compare the counter with the address location that contains the value 250
BCD 4 compare the counter with the address location that contains the value 500
BCD 5 compare the counter with the address location that contains the value 1000
BCD 6 compare the counter with the address location that contains the value 1500
This device is being developed to enable electronic alignment of a mechanical system quickly versus cumbersome mechanical alignment of the mechanical system.
The PLC system does work but only at very low speeds.........not effective.
Thank you so much for your interest in my project!
I am self taught and I do not have ANY experience in programming C or basic but I will learn!
I have used PLCs that use·"ladder" programming and motion controllers that use a basic language for many years.
I am exited to start learning how to use microcontrollers. This will greatly increase flexibility for my ideas!
Jfischer
·
I am adopted and I do not know the origin of my parents, my adopted father does have roots from Germany but I do not speak German, but I would like to learn the language.