View Single Post
  #9   Spotlight this post!  
Unread 22-03-2004, 16:36
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
Re: counting digital input

Quote:
Originally Posted by Astronouth7303
None of that is going to work if you're going at any resonable speed. It's going to miss ticks. Use interupts.
If you use a quadrature encoder you don't need the state machine to decode its output. Connect channel A to an interrupt configured to fire on the rising edge. Connect channel B to a regular digital input (input 10 in the example). Your ISR becomes one line:
Code:
void Int_1_Handler()
{
     Distance += (rc_dig_in10) ? 1 : -1;
}
The outputs follow the pattern AB = 00-10-11-01-00... If you look at the rising edges for channel A, going from left to right, channel B is 0. Looking at the rising edge of A from the other direction and channel B is 1. If the direction is reversed you can swap the inputs or change the signs in the ISR.

Last edited by seanwitte : 22-03-2004 at 16:45.