That's a great question Bert. Well, you being an asm guy will probably get a few laughs at my first real attempt at using more than 20 lines of asm in my program. But I will show you anyway. This uses Timer1 for PWM measurement (read servo channels in). Basically, Timer1 runs non-stop, and when a state change interrupt is detected, the timer value is read. The start timer value is subtracted from the stop timer value to get the pulse width. This is done for all channels. After all channels are read, it is time to output pulses to the servos. So I do not have a 20 ms timer, it cheats and uses the R/C receiver as the 20ms timer. If all channels have been read, it must be 20 ms. The second interrupt is timer0. That is used for pulse duration on the output. I made the pulse base 1ms, then the timer gets set for a second interrupt to complete the pulse.
Here is an example of reading 5 R/C channels, and outputting 4 R/C channels using two timers: http://www.scalerobotics.com/PWMpassthrough.html
Something like that could be used. And in addition to detecting servo pulse in, and interrupt on change could time a pulse from two sonars at the same time. This could also read timer1 start and end times, so no additional timers would be needed. If you did not want to use the R/C receiver as the 20 ms timer, then timer2 could be used. But that is the last timer on this chip. But then, you can still throw more on those two other timers, if you wish.
Last edited by ScaleRobotics; - 21st November 2010 at 15:11.
http://www.scalerobotics.com
Bookmarks