by OddBot » Sat Aug 31, 2013 5:16 am
by OddBot
Sat Aug 31, 2013 5:16 am
In cases where external interrupt pins are limited the next best way is to create a timer interrupt. This generates an interrupt at precise intervals. The ISR (Interrupt Service Routine) then checks the pins attached to the encoders.
There is an Arduino library here that is quite useful:
http://playground.arduino.cc/Code/Timer1
Unfortunately this library uses the same timer as the servo library so you cannot use servos with it unless your using An Arduino Mega or DAGU Spider controller. There is also a timer3 version of the library suitable for these boards.
Alternatively, if your main code repeats quickly enough then simply monitor the inputs with each loop of the program. This is ok for distance measurements but not suitable for speed measurement which needs accurate timing.
I often use the millis() or micros() function to call my ISR once every millisecond. The accuracy of this method depends on how quickly your main loop is running. If your encoders or maximum speed is low enough then you can check your encoder inputs at longer intervals.
In cases where external interrupt pins are limited the next best way is to create a timer interrupt. This generates an interrupt at precise intervals. The ISR (Interrupt Service Routine) then checks the pins attached to the encoders.
There is an Arduino library here that is quite useful:
http://playground.arduino.cc/Code/Timer1
Unfortunately this library uses the same timer as the servo library so you cannot use servos with it unless your using An Arduino Mega or DAGU Spider controller. There is also a timer3 version of the library suitable for these boards.
Alternatively, if your main code repeats quickly enough then simply monitor the inputs with each loop of the program. This is ok for distance measurements but not suitable for speed measurement which needs accurate timing.
I often use the millis() or micros() function to call my ISR once every millisecond. The accuracy of this method depends on how quickly your main loop is running. If your encoders or maximum speed is low enough then you can check your encoder inputs at longer intervals.