gary
What are you trying to do? As it happens I'm working on the
same thing right now,a two phase encoder with index on a
shaft, belt driven by a variable speed motor (over 1HP). I
connect each phase input to one of the 8051 interrupts (I
use the Atmel 89C51 variant) and the index to an extra P3
pin.
As long as you aren't using this for any type of gaming
device (slot machine, paycheck wheel, big 6, etc.),
convention exhibit, or animated sign I can supply some
source code for you. It's all in 8051 assembly...after all,
real embedded programmers work at the bit level, none of
that high level C language stuff.
Jack Peacock
: What are you trying to do? As it happens I'm working on the
: same thing right now,a two phase encoder with index on a
: shaft, belt driven by a variable speed motor (over 1HP). I
: connect each phase input to one of the 8051 interrupts (I
: use the Atmel 89C51 variant) and the index to an extra P3
: pin.
If though what you want is a routine to read out an absolute encoded angular
position encoder, we are using a couple of Haidenhain ROC 417. Those are
angular encoders with 17 bits resolution (of which we only use 16) and they
shift out one bit for each clock pulse. We use them to position several
detectors with stepping motors. To read out one 16 bit word between any two
motorsteps is easily done.
Rolf
>need to interface a rotary encoder to a 8051
>anyone have a subroutine that does this ?
>thanks in advance
>
>gary
Take one of the quad outputs and connect it to an edge interrupt input
the other to any normal input pin
During your interrupt routine...
Read the normal pin first.. if hi, inc your counters+1, if low dec
your counters -1
That it
If the direction of count is wrong just swap the quad outputs or in
the software
If you have a speed problem ..ie reading wrong direction
put one of the quad outputs into the D input of a D type flipflop and
the other into the clock of the same chip .The Q output of the
flipflop will latch the direction bit for you, till your routine can
get to it
Tap
>Tap
Hi Tap,
do you have any great idea, how to increase resolution in a similar
way ? idea is to increase resolution by 4, like it is possible with
hardware.
If one has not enough interrupts, it is possible to poll A and B in
your main timer-isr and do direction detection and step detection in
software, because it is gray-code.
already done with the Atmel AvR and 4 encoders.
Werner
Best regards,
Werner
remove .XXX in e-mail-adress
* Opinions expressed herein are my own and may
* not represent those of my employer
Yes... you can count all edges to increase the count per spin from
both quad outputs
You will need a Pic 84 or any other chip that has Int on change
.....ie Rb <7:4> Hook up one quad output to.. say rb7
the other to rb6.and rb0 .Set up isr's on rb0, rb6 and rb7
and make rb0 isr a rising edge type
On isr rb0 read rb7's input and use its state to set /clear a
direction bit in ram.. then exit to rb6 isr and +1 or -1 the counters
according to the direction bit
On any rb6 or rb7 irs... +1or -1 counters according to the direction
bit..then exit ..
rb0 isr must have priorty over rb6,rb7
You can also make a both edge circut with a Xor gate ..
quad output to one input and an r-c feed back on the other input
this will make a pulse on every edge
Tap
...
>You can also make a both edge circut with a Xor gate ..
>quad output to one input and an r-c feed back on the other input
>this will make a pulse on every edge
>
>Tap
>
Tap, thanks. I am impressed.
I have done stuff like this, and if you don't take account of direction
you will get cumulative errors, because even in a system which you think
is uni-directional, you will get some jitter, or uncertainty in the
position. If direction is taken into account then the count will just
flick up and back down by one count occasionally - no problem, but if
you are just counting changes-of-state the count will go on creeping up
whilst the encoder stays still.
--
Chris Wright
Colt International Licensing Ltd
if A is hi, then falling B is a + count, rising B is a - count.
if A is lo, then the counts are reversed
and
if B is hi then rising A is a + count, falling A is a - count
if B is lo, then the counts are reversed
so, to implement, build edge detector pulse generators for A and
B, route the pulses to + or - based on the logic above, and use
+ and - to step a counter up and down.
make the pulse width much smaller than the max speed.
use hysteresis/Schmidt trigger on the A and B signals (very important)
Rick Sharpe
Chris Wright wrote in message ...
Rick Sharpe's comments remind me of the days when ,that if I had two
nickels to rub together only one of them was mine. I was making my own
optical rotary encoders with PCB layout tape for use in Disco lighting
systems . The edges from the phototransistors were way too soft and
noisy and I used 555 timers in some oddball way to get a schmidt
trigger effect to clean up the signal .From there one "quad"(well sort
of anyway) would connect to the direction pins on a cmos up/dn
counters and the other quad straight into the clock inputs. I had
magnitude comparitors tied between the counters and shift register
outputs which provided the data for the stop /reverse points. Up at
other end of serial data lines was a joystick and a whole raft of
analog and digital chips that I somehow converted audio into a sway
distance and allowed the user to point an array of spotlights.
In the end and after a lot of work..it all worked..I got paid
Tap
--
--
Regards,
Adrian Jansen aja...@ozemail.com.au
Design Engineer J & K Micro Systems
Ph (07) 4639 4676 Microcomputer solutions for industrial control
Rick Sharpe wrote in message <35d06...@aedes.isd.net>...
.. connect the sine signal to the D-input of a D-FF and the cosine to its
clock and to the clock of an up/down counter. The output of the D-FF goes to
the U/D input of the counter.
--
Stefan Wimmer Cellware Broadband
Email s...@cellware.de Rudower Chaussee 5
WWW http://www.cellware.de/ 12489 Berlin, Germany
Visit my private Homepage: Love, Electronics, Rockets, Fireworks!
http://www.geocities.com/CapeCanaveral/6368/
Maybe this will turn into a war stories thread!
Rick
Tap wrote in message <35d08aa1.164289780@news>...
>My remark about the xor gate was intended to provide a means to
>generate interrupt pulses for a mcu chip without interrupt on change
>inputs. What Chris Wright says about the direction stuff is
>correct.but I though I covered that in the software description before
>the remark...obviously not well enough
>
>Rick Sharpe's comments remind me of the days when ,that if I had two
>nickels to rub together only one of them was mine. I was making my own
>optical rotary encoders with PCB layout tape for use in Disco lighting
>systems . The edges from the phototransistors were way too soft and
>noisy and I used 555 timers in some oddball way to get a schmidt
>trigger effect to clean up the signal .From there one "quad"(well sort
>of anyway) would connect to the direction pins on a cmos up/dn
>counters and the other quad straight into the clock inputs. I had
>magnitude comparitors tied between the counters and shift register
>outputs which provided the data for the stop /reverse points. Up at
>other end of serial data lines was a joystick and a whole raft of
>analog and digital chips that I somehow converted audio into a sway
>distance and allowed the user to point an array of spotlights.
> In the end and after a lot of work..it all worked..I got paid
>Tap
>
>
>
>
>
>
>
>On Tue, 11 Aug 1998 10:22:37 -0500, "Rick Sharpe"
><rsh...@beckman.com> wrote:
>
>>The two signals are like a sine and cosine wave, 90 degrees
>>out of sync.
>>
>>if A is hi, then falling B is a + count, rising B is a - count.
>>if A is lo, then the counts are reversed
>>
>>and
>>
>>if B is hi then rising A is a + count, falling A is a - count
>>if B is lo, then the counts are reversed
>>
>>so, to implement, build edge detector pulse generators for A and
>>B, route the pulses to + or - based on the logic above, and use
>>+ and - to step a counter up and down.
>>
>>make the pulse width much smaller than the max speed.
>>use hysteresis/Schmidt trigger on the A and B signals (very important)
>>
>>Rick Sharpe
>>
>>
pc
Gary M. Belcaster wrote in message ...