Step 5Improvements
What this code should use instead of delays is the PIC's built in timers. Code for this might look something like:
OpenTimer0( TIMER_INT_OFF &
T0_SOURCE_INT & T0_16BIT &
T0_PS_1_2 ); // i think this makes a timer that raises a flag every 21.8 ms
while (1) {
while(!INTCONbits.TMR0IF){ // wait for timer to set flag
// do useful things
}
INTCONbits.TMR0IF=0; // reset timer flag
// send pulse to servo
}
I know I said there was supposed to be a pulse every 10 to 20 ms, but 21.8 ms is pretty close and hobby servos are generally very forgiving.
| « Previous Step | Download PDFView All Steps | Next Step » |








































google pic hardware pwm
here's a good page on it:
http://www.winpicprog.co.uk/pic_tutorial8.htm
(you can usually use assembler in line with other higher level code if you're using PICBasic or PICC)