Searching \ for '[OT]: Quadrature Encoder Interrupts' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/sensors.htm?key=quadrature
Search entire site for: 'Quadrature Encoder Interrupts'.

Exact match. Not showing close matches.
PICList Thread
'[OT]: Quadrature Encoder Interrupts'
2000\12\11@132950 by JB

flavicon
face
Just looking for a little advice on how to detect (in a way that would trigger an interrupt) the transition of multiple quadrature encoders. For simplicity, let's say I have an X & Y axis I'm monitoring. I could hook the X-axis 'A' line to the PIC's external INT pin, and the 'B' line to another input pin. Thus, when X changes, I get an interrupt from the 'A' transition, and I can then look at the 'B' line to determine direction of travel.

How then would I add the Y-axis encoder in such a way that I could also detect state changes via interrupt as I can on the X-axis? I could use PORTB change interrupts, but I'm using that for other inputs as well, which would cause false triggers. In this case, I'm using a 16F873 for the project, but I would be willing to commit a 16F84 to the encoders if required, and communicate positions to the F873 using a serial protocol. There too, I would still be required to use interrupts for detection of travel, lest I loose position data while sending serial data.

And what about a third axis for Z travel?

On a related note, the encoder output is a simple photo transistor, which means a continuously varying sine voltage will be present on the input pins, rather than a digital logic level. I would be depending upon the thresholds of the PIC inputs for detection of the transitions. Will this suffice, or do I need external comparators? Isn't a Schmitt trigger input supposed to be able to deal with this?

Thanks,

JB

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@143558 by Lance Allen

picon face
JB wrote:

> Just looking for a little advice on how to detect (in a way that would trigger an interrupt) the transition of multiple quadrature encoders. For simplicity, let's say I have an X & Y axis I'm monitoring. I could hook the X-axis 'A' line to the PIC's external INT pin, and the 'B' line to another input pin. Thus, when X changes, I get an interrupt from the 'A' transition, and I can then look at the 'B' line to determine direction of travel.
>
> How then would I add the Y-axis encoder in such a way that I could also detect state changes via interrupt as I can on the X-axis?

The problem with the interrupt on one line and monitoring the other is you are only able to detect 1/4 of the information available since each transition (high or low) on either line is 'movement and direction' information.
If you could set up the interrupt pin to detect both high going or low going you would still only be able to detect half of the transitions.
The approach I would recommend (there are others) is to poll both inputs for a change, by comparing with the last stored poll result, if the previous results dont match what you have now there has been a movement and which pin changed to what level will tell you which direction you moved ( a few if-then type decisions will yield the desired results).
This method can be expanded to incorporate multiple encoder inputs.
Except for slow encoders or simple processing applications I often use a separate (cheap) microcontroller for this application.


Lance Allen
Embedded Systems Lab
CSE
Electronic and Electrical Engineering
School of Engineering
University of Auckland

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@144921 by David Kott

flavicon
face
> Just looking for a little advice on how to detect (in a way that would
trigger an interrupt) the transition of multiple quadrature encoders. For
simplicity, let's say I have an X & Y axis I'm monitoring. I could hook the
X-axis 'A' line to the PIC's external INT pin, and the 'B' line to another
input pin. Thus, when X changes, I get an interrupt from the 'A' transition,
and I can then look at the 'B' line to determine direction of travel.
>

Yah... that's pretty much what I did.  I only used one quadrature encoder.
I think, however, the method you are describing only gives you half of your
total resolution.  You might play with the following code, and it'll give
you your encoder's full resolution.   (Please direct coding style comments
to /dev/null :-) )

------------------------------------------
struct RotaryEncoderStruct {
     int unused:4;  // RB[0:3]
     int A:1;   // RB4
     int B:1;   // RB5
     int unused2:2;  // RB6-7
};

struct RotaryEncoderStruct RotaryEncoder;

#pragma BYTE PORTB = 0x06

#pragma BYTE RotaryEncoder = 0x06 // Place structure right over PORTB at
location 0x06


USHORT g_usEncoderCount = 0;

#pragma INT_RB
void
PortBInterrupt (void)
{

     static BYTE OldPortB;
     BYTE byTemp;
     static struct RotaryEncoderStruct OldEncoder;


     if (OldPortB != (byTemp=(PORTB & 0x30))) {


     OldPortB = byTemp;

     if (RotaryEncoder.A == OldEncoder.A) {
    if (RotaryEncoder.B == RotaryEncoder.A)
   --g_usEncoderCount;
    else
   ++g_usEncoderCount;
     } else {
    OldEncoder.A = RotaryEncoder.A;
    if (RotaryEncoder.B == RotaryEncoder.A)
   ++g_usEncoderCount;
    else
   --g_usEncoderCount;
     }



    }

  // Handle more PORTB stuff here, like a button, or something.


}
------------------------------------------


> How then would I add the Y-axis encoder in such a way that I could also
detect state changes via interrupt as I can on the X-axis? I could use PORTB
change interrupts, but I'm using that for other inputs as well, which would
cause false triggers. In this case, I'm using a 16F873 for the project, but
I would be willing to commit a 16F84 to the encoders if required, and
communicate positions to the F873 using a serial protocol. There too, I
would still be required to use interrupts for detection of travel, lest I
loose position data while sending serial data.
>
> And what about a third axis for Z travel?
>
> On a related note, the encoder output is a simple photo transistor, which
means a continuously varying sine voltage will be present on the input pins,
rather than a digital logic level. I would be depending upon the thresholds
of the PIC inputs for detection of the transitions. Will this suffice, or do
I need external comparators? Isn't a Schmitt trigger input supposed to be
able to deal with this?
>

Erf... I would suggest looking at a different encoder.  There are a plethora
of genuine totem pole style output devices.  http://www.usdigital.com makes
several that are reasonably priced.  I ultimately went with some from
Agilent.  HRPG series, if memory serves.

But, you are correct, Schmitt trigger inputs are meant to absorb this sort
of signal and digitize it.  Naturally, you'll want to closely scrutinize the
potentials in your system and verify that the parts you propose to use are
rated for this range.

Driving an analog signal directly into your PIC's digital inputs may not be
very wise.  If you bias a CMOS input at about 1/2 of its reference voltage,
the FETs in that input will both bias and your PIC will draw large currents.
If your encoder is going to stop at a particular position for very long,
you'll have to consider what will happen if it biases your inputs at their
halfway(ish) point, and handle the largish currents that develop.

-d

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@150354 by Eisermann, Phil [Ridg/CO]

flavicon
face
how about a OR gate? feed all the encoder interrupts into the OR gate.
Output of the OR gate is the input into the PIC interrupt.

As for the comparator, I'd definitely try to incorporate one (unless there
is a compelling reason not to).

{Original Message removed}

2000\12\11@154119 by Robert Rolf
picon face
A previous poster said use an OR gate. This won't work since a
non-moving axis would prevent other axis from being detected if
it was outputting a H state.

Use an XOR gate on A @ B to get an interrupt on EVERY edge transition.

If your firmware is fast enough (relative to your pulse rate) you would
XOR -all- the A & B lines for your encoders, and then read a port to get
the individual statuses and figure out which bits have changed.
This has the down side of giving you 4x the interrupt rate per axis,
but then you also get 4x the resolution. With 3 channels you're looking
at 4x4x4 or 4096x rate interrupts, and possible race conditions
(although
you'd see the changes in the status bits).

Robert

Lance Allen wrote:
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@155757 by stouchton

flavicon
face
Wow... this is taxing some brain cells... I did a phase indicator about 15
years ago where I used a nand gate and a J-K flip-flop to give me a clock
pulse on each step of the encoder and a high signal for clockwise rotation,
and a low for counterclockwise.  I used it with LED's, but a PIC could use
the info... interupt on the clock, check status for direction.

In one application, my signals were also sinusoidal (and varied in amplitude
from 10mV to 600V).  I used a clamped op-amp input to boost to logic levels.
The phase indicator was used on the residual magnetism of a motor (just spin
the shaft to see the phase orientation) and on the powerline mains.  This
was a 3 phase application, but should implement into a 2 phase system.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@183419 by Morgan Olsson

picon face
JB wrote:
>'A' line to the PIC's external INT pin, and the 'B' line to another input pin. Thus, when X changes, I get an interrupt from the 'A' transition, and I can then look at the 'B' line to determine direction of travel.

If you have a noisy transition, or vibration, or just small travels back and forth so 'A' flickers, bot movement is not enough to make 'B' hange, then you will get multiple interrupt, and count "movement" without real movement!

You get four times th eresolution, and no errors, if you decode both signal´s every change.

It is possible to use interrupt on port B change to generate interrupt on any change on any phase from two decoders.  The service routine then evaluates which decoder (or both) changed from before (old state saved in some reg) and call a decode routine for relevant decoder.

The decode routine to decode the movement can be a table combining two bits from oldstate, and two bits from new sample.

If it alows for decoding no-change then both encoders, decode tables can be run each time any change on port B occours.

/Morgan

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2000\12\12@055118 by Graham

flavicon
face
quadratures......

I have just been through this....where are the interupts ?, which has
priority serial comms, encoder(s) ?? ....use another PIC, ?? .... etc etc

I concluded that by the time you impliment a really watertight encoder count
in two axis, then you spent nearly as much money, and much more time, than
just interfacing a dedicated quadrature decoder chip....

you obviously need to first clean up your encoder outputs into
digital.....some of these solutions I list here also have good input noise
filtering with varying degrees of sophistication......

Agilent 4016 is very easy to hook to a pic, bit pricey....16 bit solution

US DIGITAL 7266  (24 bit. at www://us digital.com, this is a two axis in one
chip) I now have in hand, development board done, but no control code done
yet, too busy working on the battery backup for pulse count preservation and
other bits of my system.....this chip may be too complex/expensive depending
on your application.....but they also have some real cheap simple quadrature
to  pulse decoders, WITH up/down pin AND still x1, x4 switching available,
these might be interesting......and easier to manage interupts in some
configurations.

this choice all depends how complex your system is overall ?, is it 'mission
critical' ?,  need index ??, budget constraint ??, time constraint ?, pcb
real estate constraint ?, pic pins available etc...

however a few pointers.....

Graham



-Need *high IP3* AND good N/F ?? try this- http://www.rfham.com

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2000\12\12@083255 by Morgan Olsson

picon face
Graham, you sure seem to have investigated existing chips :)

Can you tell if you have seen a chip that can count movement from two sensors, into *one common counter*, so on the counter output i have continous reading of the *difference* in movement.

I need continous difference value, not two counter and subtract them later.  (Or that has to be made quick and with correct behaviour at rollover)

I have an upcoming project where the cycle frequenxy will be about 500kHz from each sensor, so all four signals (2sensors x 2phase) change state (up/down) total 4 million times per second.  And it may peak over six million

I need at least 10 bit resolution of the difference, some means to load it to a preset value, and some inbuilt mechanism to sample it for reading so it can be safely read by both a D/A and a microcontroller.

I recon this is on the limit solvable by a Scenix at 100MIPS runnig a tight loop using table lookup.  Better would be to program hardware an FPGA.

I have never used either.

So an readily available chip would be nice.

>US DIGITAL 7266  (24 bit. at www://us digital.com

Sorry, there are at least two errors in that URL, and I cant get it to work, can you fix it please?

Thanks
/Morgan

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2000\12\12@104140 by Graham

flavicon
face
>>US DIGITAL 7266  (24 bit. at www://us digital.com
>
>Sorry, there are at least two errors in that URL, and I cant get it to
work, can you fix it please?

well yes, pretty obvious really but sorry anyway, typed in a great hurry ....

http://www.usdigital.com

then look about....

as for your application, I have no experience of reading that fast nor
looking only for the difference....my application is real slow, but noisy
and needs to be reliable , tracking in a high RF environment.

the world appears very short of quadrature decoder chips, there are very few
to choose from, which is presumably why us digital and several other folks
who are primarily in the encoder hardware business commissioned their
own...unfortunately most do not sell them individually in low volumes....

A quadrature decoder with filtered inputs to rs-232/485 count output on
demand, battery backup, 24 bit, sure would be a dandy thing.......if anyone
finds it let me know !

Graham


-Need *high IP3* AND good N/F ?? try this- http://www.rfham.com

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspamBeGonespammitvma.mit.edu


More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...