Searching \ for 'encoder question' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/io/sensors.htm?key=encoder
Search entire site for: 'encoder question'.

Truncated match.
PICList Thread
'encoder question'
1999\03\23@205015 by Robert M. Bailey

flavicon
face
Hello everyone,
Does anyone know of any published projects that use a differential encoder
with a PIC?
Any tips or hints for the same would be helpful as well.
Thanks in advance
Bob Bailey

1999\03\23@210925 by Wagner Lipnharski

picon face
This is quite easy if you mean rotation encoders,  where there is two
signals one 90 degrees from another...

Just look for signal #1 going up, then check signal #2.
If signal #2 is also up, the rotation is towards one side,
if signal #2 is down, the rotation is towards the other side.
So you can increment or decrement a counter easily.
Wagner

Robert M. Bailey wrote:
>
> Hello everyone,
> Does anyone know of any published projects that use a differential encoder
> with a PIC?
> Any tips or hints for the same would be helpful as well.
> Thanks in advance
> Bob Bailey

1999\03\23@220536 by Peter Homann

picon face
Below are segments of code for reading an encoder. It's written in C using
the CCS compiler (BTW: I think the compiler its great value, even with its
faults).

I'm using the RTCC to generate an interrupt when the encoder is turned, in
addition to using it to debounce the encoder inputs. Initially the RTCC is
set up to be clocked externally, (from the encoder A line ENC_A) and the
RTCC is preloaded with 255 (FFh). When the encoder A line goes from Hi to
low, the RTCC is incremented from 255 to 0 and an interrupt is generated.

The ISR then reads the state of the other encoder line ENC_B and
increments/decrements a variable (current_data). The ISR then changes the
mode of the RTCC to be internally clocked. This stops the encoder lines
bouncing and generating false interrupts. Once the RTCC overflows, an
interrupt is generated and a counter is decremented.  When this counter
reaches 0 the debounce delay has expired and the ISR changes the RTCC mode
back to being clocked externally, etc...

I hope this helps.

Peter



#define ENC_A           a_port.a4   // Pin used to read the encoder A output
#define ENC_B           b_port.b3   // Pin used to read the encoder B output

byte    current_data;      // This variable will be incremented or
                          // decremented by the encoder ISR as the encoder
is
                          // rotated.
byte    encoder_timer;     // Used by the encoder ISR for debouncing the
                          //encoder inputs.
boolean encoder_intrpt;    // Indicates whether the RTCC interrupt is caused
                          // by an encoder change (external) or from the
RTCC
                          // counter overflowing (internal).


// Setup the RTCC to clock from the internal clock
#inline
void
set_rtcc_internal_clock()       // CCS compiler workaround
{
   #asm
       movlw 0x81
       movwf 0x04
       bcf   0x00,5
   #endasm
}

// Process the RTCC interrupt.
#int_rtcc
encoder_isr()
{
   if (encoder_intrpt)             // If the interrupt was generated by the
   {                               // ENC_A input, test the ENC_B input to
       if (ENC_B)                  // determine the direction the encoder
has
       {                           // been  rotated. Update the current
data
           current_data--;         // accordingly.
       }
       else
       {
           current_data++;
       }
       set_rtcc_internal_clock();  // Setup the RTCC to perform encoder
input
       set_rtcc(0);                // debouncing.
       encoder_timer  = 50;
       encoder_intrpt = FALSE;     // Indicate that the next RTCC interrupt
   }                               // will be from the debouncing function
   else
   {
       encoder_timer--;            // Debounce the encoder input.
       if (!encoder_timer)
       {
           set_rtcc_ext_h_to_lo(); // Set the next interrupt to be from
           encoder_intrpt = TRUE;  // the ENC_A input.
           set_rtcc(255);
       }
   }
}

---
Peter Homann    Email:  spam_OUTpeterhTakeThisOuTspamadacel.com.au
Adacel Technologies Ltd _/_/_/ _/_/_/ _/ Phone:   +61 3 9596 2991
250 Bay St, Brighton   _/  _/   _/   _/  Fax:     +61 3 9596 2960
Victoria  3186        _/_/_/   _/   _/   Home:    +61 3 9555 5603
AUSTRALIA            _/  _/   _/   _/_/_/Mobile:      0414-494578
------------------------------------------------------------------------


|-----Original Message-----
|From: pic microcontroller discussion list
|[.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU]On Behalf Of Robert M. Bailey
|Sent: Wednesday, 24 March 1999 11:44
|To: PICLISTspamKILLspamMITVMA.MIT.EDU
|Subject: encoder question
|
|
|Hello everyone,
|Does anyone know of any published projects that use a
|differential encoder
|with a PIC?
|Any tips or hints for the same would be helpful as well.
|Thanks in advance
|Bob Bailey
|

1999\03\23@225325 by Rob

flavicon
face
im working on the code for one right now..
Ill let u know..
BTW, its not as easy as you would think..
rob

-----Original Message-----
From: Robert M. Bailey <.....baileysKILLspamspam.....KTIS.NET>
To: EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU <PICLISTspamspam_OUTMITVMA.MIT.EDU>
Date: Tuesday, March 23, 1999 7:50 PM
Subject: encoder question


>Hello everyone,
>Does anyone know of any published projects that use a differential encoder
>with a PIC?
>Any tips or hints for the same would be helpful as well.
>Thanks in advance
>Bob Bailey

1999\03\23@233238 by Ravi Pailoor

flavicon
face
Bob,

Use channel A as a negative edge clock input to a counter, Count up or count
down will be based on the B input. If B is high after receiving clock, count
up, if B is low after receiving clock, count down.

Try this.

Pailoor

Robert M. Bailey wrote:

> Hello everyone,
> Does anyone know of any published projects that use a differential encoder
> with a PIC?
> Any tips or hints for the same would be helpful as well.
> Thanks in advance
> Bob Bailey

--
================================================
For Embedded Controls Solutions and Custom Designs
------------------------------------------------------------------------
CHIP TECHNOLOGIES - Member, Microchip Consultant Program
Bangalore
INDIA
Email   : @spam@chiptechKILLspamspamvsnl.com
Webpage : http://business.vsnl.com/chiptech ( updated 16th Feb 1999 )
================================================

1999\03\24@060316 by Stefan Sczekalla-Waldschmidt

flavicon
face
"Robert M. Bailey" wrote:
>
> Hello everyone,

> Any tips or hints for the same would be helpful as well.
> Thanks in advance
> Bob Bailey

I've done it once in Hardware ( xilinx fpga ) with a clocked
statemachine.

I drawed a state diagram and added the appropriate transitions.

I boiled it down with Karnough-maps to plain logic.
worked very well in a very noisy enviroment.

Drawing a state diagram ( 00 01 10 11 ) may also give you the clue
in howto do it in software.

Using one line as Clock an the other as direction did not work
for me. This may work in a enviroment without or with less noise.

Kind regards,

       Stefan

1999\03\29@101946 by paulb

flavicon
face
Stefan Sczekalla-Waldschmidt wrote:

> Using one line as Clock an the other as direction did not work
> for me. This may work in a enviroment without or with less noise.

 The concept is flawed.  If the "clock" line senses one edge only,
then a "jitter" which would toggle this line back and forth would quite
wrongly produce an apparent continuous rotation in one direction.

 For this to work, the "clock" must be processed on both edges, with
the sense of the "data" being considered opposite in each case.  Even
so, this approach loses half the definition of the encoder.  You
really need to detect *any* change, possibly by cross-clocking hardware
on both inputs.
--
 Cheers,
       Paul B.

1999\03\29@182954 by Rob

flavicon
face
>> Using one line as Clock an the other as direction did not work
>> for me. This may work in a enviroment without or with less noise.
>
>  The concept is flawed.  If the "clock" line senses one edge only,
>then a "jitter" which would toggle this line back and forth would quite
>wrongly produce an apparent continuous rotation in one direction.
>
>  For this to work, the "clock" must be processed on both edges, with
>the sense of the "data" being considered opposite in each case.  Even
>so, this approach loses half the definition of the encoder.  You
>really need to detect *any* change, possibly by cross-clocking hardware
>on both inputs.
>--


The logic is as follows (BTW, I built a DISCRETE version of this circuit, no
easy task!)

A = Left
B = Right
A*B=output pulse
Ao=left output
Bo=right output

Read first positive edge
null all variables and output ports
Loop till
positive edge = A, then R= 0, goto output pulse subroutine
postive edge = B, then R=1, goto output pulse subroutine

Output pulse subroutine
count=n+1, next n
Loop till A*B=1, goto Direction subroutine
If count = 58, goto Read first positive edge

Direction subroutine
IF R=0, Bo=1 while A*B=1,
IF A*B=0, goto Read first postive edge
IF R=1, Ao=1 while A*B=1,
IF A*B=0, goto Read first postive edge

This is the simplest way I could think to do it with a micro.. this is
merely what I could scrub up from truth tables..
WHATEVER you do, do NOT use delays to set your output pulse width... It will
completely hamper the operation of the unit and make the interface
glitchy...

I may not be right.. someone correct me if Im not... But so far this is the
most foolproof way..,
If you do not do it this way, the leading edge of one of the phase inputs
will always be teetering on triggering the chip to read a direction... This
is the main problem I had to solve when building it discretely...
It will cause it to glitch quite a bit...
You could actually have a time-out in the output pulse subroutine, where if
the output pulse condition is not met within x number of counts, you could
return to Read first positive edge. This would keep the pic from holding a
rotation direction too long...

Hope this helps..
Rob

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