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:
If simkits tells me the truth, it means the original stock was sold out in about 17 hours and they were not able to get new parts in about 25 business days. Remember, I fabricated this kind of input myself, no fancy and/or rare items were used and the firmware was almost trivial. If I add that I ordered the kit (no assembly needed on Simkits part), I start to wonder about their business model. I really hope that was the last thing I had to order from them.

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?