Here's a piece of code I am currently working on (this is mostly from memory). It uses CC5X compiler. I'm also polling serial I/O at 9600. This is my first attempt at PIC programming. Hope this helps /* SERVO */ #include <16F628.h> #define CP_off |=3D 0x3F0A #pragma config CP_off,WDTE=3Doff, FOSC=3DHS, PWRTE=3Doff, BODEN=3Doff uns8 servo; uns16 20ms_cntr; #define servoout RB4 #define PRESET 111 /* 256-144, (((1/18.432M)/4)/144) * 640 =3D 20ms */ #include "int16CXX.H" void init(void); #pragma origin 4 interrupt int_server( void) { uns8 temp;=09 int_save_registers // W, STATUS (and PCLATH) if (T0IF ) { /* Timer0 counter overflow flag*/ T0IF =3D 0; /* reset flag */ TMR0=3DPRESET; /* Reload timer0 */ if ( 20ms_cntr =3D=3D 0 ) { servoout =3D 1; } temp =3D servo + 32; /* 32 =3D ~1 msec,64 ~=3D2msec */ if ( 20ms_cntr =3D=3D temp ) { servoout=3D0; } 20ms_cntr++; if (20ms_cntr =3D=3D 641) { 20ms_cntr =3D 0; } }=09 int_restore_registers // W, STATUS (and PCLATH) } void init(void) { PIE1 =3D 0x00; /* Disable all Peripheral Interrupts */ INTCON=3D 0x00; /* Disable all Interrupts */ T0CS=3D0; /* Timer0 Clock Select 0=3DCLKOUT */ T0IF=3D0; /* Timer0 overflow flag bit */ PSA=3D1; /* Prescaler assigned to WDT */ TMR0=3D111; /* Preload value for 31.25 uSec intr */ servo=3D16; /* Servo initial position 16+32 ~=3D 1.5ms pulse 20ms_cntr=3D0; /* Timer0 interrupt counter 640 interrupts=3D20mSec */ } void main( void) { init(); T0IE=3D1; GIE=3D1;=20 while (1) /* infinite loop */ { =20 /* get serin position, put in servo */ } } -----Original Message----- From: James Fitzsimons [mailto:jamesfit@PARADISE.NET.NZ] Sent: Wednesday, February 27, 2002 3:00 AM To: PICLIST@MITVMA.MIT.EDU Subject: [PIC]: servo code and piclist website Hi all, I am trying to hunt down some code to drive a modified hobby servo. I have written some code in C, however I can't seem to get accurate enough performance out of it. I have just tried to go to the piclist website to see if there is any code there but the site seems to be down?? If anyone has some code that accurately turns a pin on and off for between 1 and 2ms and would like to share it I would be extremely grateful. I have a feeling that to get the accuracy I need I may need to inline some assembler, however I have not done this before... Thanks for any advice or help, James Fitzsimons -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics