Monday, May 08, 2006
Servo control from flightsim cont.
I have entirely rewritten the firmware using idea from Mike's book. The main idea is to set up timer2 of the PIC to fire every 20ms. The interrupt routine will start timer1 according to a 2 byte delay. With both timer interrupts enabled, the firmware is something like
set up timer 2 to fire every 20ms and enable interrupt for it
main loop
check if serial input is available (RCIF flag in PIR1)
if serial is available then read 2 bytes and put it into pulse width delay parameter
goto main loop
interrupt routine
if firing because of timer2 then enable servo control output, set timer1 to delay parameter, enable interrupt for it
if firing because of timer1 then disable servo control output
It worked much better then previous version, since timer1 enables me to control pulse width with precision of one instruction cycle. Since PIC is using internal 4Mhz oscillator, it means pulse width precision of 1usec (or 0.001 ms). Of course I had to slightly change the interface C program to send correct values for TMR1L and TMR1H. The servo movement was much smoother then previously. If I clock the PIC using an external oscillator, then this would allow me even more precise pulse width control (using let's say 20Mhz, one instruction cycle goes down to 0.2 usec or 0.0002 ms).
The firmware for driving 8 simple servos (for example all small gauges with one PIC) is getting shape, again using idea from Mike's book, something like:
set up timer 2 to fire every 2.5ms and enable interrupt for it
main loop
check if serial input is available (RCIF flag in PIR1)
if serial is available then read x bytes and put it into pulse width delay parameter of appropiate servo
goto main loop
interrupt routine
if firing because of timer2 then enable next servo control output, set timer1 to delay parameter, enable interrupt for it
if firing because of timer1 then disable actual servo control output
This way each servo is served in 2.5ms*8 = 20ms intervals.
By the way: I'm still waiting for the Simkit delivery (it has not even shipped yet). Just for the record:
set up timer 2 to fire every 20ms and enable interrupt for it
main loop
check if serial input is available (RCIF flag in PIR1)
if serial is available then read 2 bytes and put it into pulse width delay parameter
goto main loop
interrupt routine
if firing because of timer2 then enable servo control output, set timer1 to delay parameter, enable interrupt for it
if firing because of timer1 then disable servo control output
It worked much better then previous version, since timer1 enables me to control pulse width with precision of one instruction cycle. Since PIC is using internal 4Mhz oscillator, it means pulse width precision of 1usec (or 0.001 ms). Of course I had to slightly change the interface C program to send correct values for TMR1L and TMR1H. The servo movement was much smoother then previously. If I clock the PIC using an external oscillator, then this would allow me even more precise pulse width control (using let's say 20Mhz, one instruction cycle goes down to 0.2 usec or 0.0002 ms).
The firmware for driving 8 simple servos (for example all small gauges with one PIC) is getting shape, again using idea from Mike's book, something like:
set up timer 2 to fire every 2.5ms and enable interrupt for it
main loop
check if serial input is available (RCIF flag in PIR1)
if serial is available then read x bytes and put it into pulse width delay parameter of appropiate servo
goto main loop
interrupt routine
if firing because of timer2 then enable next servo control output, set timer1 to delay parameter, enable interrupt for it
if firing because of timer1 then disable actual servo control output
This way each servo is served in 2.5ms*8 = 20ms intervals.
By the way: I'm still waiting for the Simkit delivery (it has not even shipped yet). Just for the record:
- I received simkits newsletter advertising the new boards on 2006.03.30 18:40
- I ordered both input boards on 2006.03.31 8:29 (lead time indicated was 10 business days)
- I asked about status of order on 2006-04-24 16:28
- Answer (on 2006-04-24 17:11) was: it was "such a succes that we were sold out very quickly"
- Nothing since then