Thread: Interrupts
View Single Post
  #2   Spotlight this post!  
Unread 14-01-2006, 12:43
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Interrupts

Quote:
Originally Posted by JSonntag
Could anyone help us with Interrupt Code for use with optical encoders? We are placing two of the small, yellow banner sensors next to the wheel, which will be covered in a sheet of paper with alternating black and white stripes. As the wheel turns we plan on detecting the change between black and white, and by comparing the counts for both the left and right wheels, we should be able to program precise turns and straight lines.

I am aware of some of the problems with Interrupts, therefore I only want to increment a counter when the state changes. The Optical sensors are plugged into rc_dig_in03 and 04.

Anyone have any ideas.
I should work if you use this code for the interrupt handlers:

Code:
void Encoder_3_Int_Handler(unsigned char state)
{
// Encoder 3's phase a signal just changed logic level, causing this 
// interrupt service routine to be called.
if(state == 1)
{
Encoder_3_Count += ENCODER_3_TICK_DELTA;
}
}
 
 
void Encoder_4_Int_Handler(unsigned char state)
{
// Encoder 4's phase a signal just changed logic level, causing this 
// interrupt service routine to be called.
if(state == 1)
{
Encoder_4_Count += ENCODER_4_TICK_DELTA;
}
}



Adjust ENCODER_3_TICK_DELTA and ENCODER_4_TICK_DELTA per the instructions in encoder.h to get the counts to go in the proper direction.


-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org