View Full Version : Optical Encoders
misterikkit
20-12-2003, 03:01
Does anyone know how to go about using the optical encoders (as in a mouse) w/interrupts in our new controllers?
I have two for each axis coming out of the mouse I got at the WRRF programming seminar, and I'd like to use them.
Thanks!
Along these lines...
a) What encoders from Digikey have teams had success with? What part numbers? Are these up for the rigors of competition?
b) Where do most teams mount encoders on the wheel shafts? on a special gear for encoding?
c) How counts per revolutoin (CPR) do most teams use? What design strategy do most teams use when seleteting CPR and encoders in general?
d) Custom circuits? Or us RC PIC interrupts directly? What the trade-offs?
Just curiuos.
Kevin Watson
20-12-2003, 14:26
Does anyone know how to go about using the optical encoders (as in a mouse) w/interrupts in our new controllers?
I have two for each axis coming out of the mouse I got at the WRRF programming seminar, and I'd like to use them.
Thanks!
You promted me to create some example code that should work with your mouse encoders. Details can be found in this thread (http://www.chiefdelphi.com/forums/showthread.php?t=23192). Enjoy.
-Kevin
The Lucas
22-12-2003, 03:41
Kevin, Great work on the interupt coding. You saved be a good deal of time looking for the names of the bits I needed to set. I think I noticed an error where the bits for timers 3 and 4 were polled in user_routines_fast.c:
else if (PIR1bits.TMR1IF) // timer 3 interrupt?
{
PIR2bits.TMR3IF = 0; // clear the timer 3 interrupt flag [93]
Timer_3_Int_Handler(); // call the timer 3 interrupt handler (in interrupts.c)
}
else if (PIR1bits.TMR2IF) // timer 4 interrupt?
{
PIR3bits.TMR4IF = 0; // clear the timer 4 interrupt flag [94]
Timer_4_Int_Handler(); // call the timer 4 interrupt handler (in interrupts.c)
}
Should it be "else if (PIR2bits.TMR3IF)" and "else if (PIR3bits.TMR4IF)"? I do things like that all the time after copying chunks of code. Thanks again.
misterikkit
22-12-2003, 11:08
So wait, I don't quite understand how to use interrupts. Are those macros you're using to refer to interrupt pins? Do I have to write code that invokes the handler?
Kevin Watson
22-12-2003, 13:28
I think I noticed an error where the bits for timers 3 and 4 were polled in user_routines_fast.c...
Brian,
Ugh, you're right and it does look like I just copied the lines above and forgot to change the if() statements. Thanks for catching that. I've updated the code on the website.
-Kevin
Kevin Watson
22-12-2003, 14:04
So wait, I don't quite understand how to use interrupts. Are those macros you're using to refer to interrupt pins?
No, I'm manipulating the memory-mapped bits directly. The bits are defined in ifi_picdefs.h.
Do I have to write code that invokes the handler? No, that's one of the cool things about interrupts: The hardware executes your code in the interrupt handler automatically when some event happens (e.g., a timer rolls-over or an interrupt pin changes from a 0 to a 1).
What you do need to do is configure the interrupt hardware so it knows how to behave (e.g., interrupt on the rising-edge or falling-edge of the signal on the interrupt pin). Have a look at the interrupt initialization routines for a description of the various ways to configure an interrupt. Also have a look at user_routines_fast.c because this is where the interrupt handlers are mapped to the different types of interrupts.
My goal is to get folks using interrupts, so if you have additional questions, ask away.
-Kevin
misterikkit
22-12-2003, 23:13
Okay, I'll post questions as I come across them.
To start, how are all those structs in picdefs 'memory mapped'?
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.