Try this way... Psuedo Code: Program ServoFollowsSwitch Loop Top If Switch =3D 1 then Pulse :=3D 1ms //drive to 1ms position else Pulse :=3D 2ms; //drive to 2ms position Delay 20ms // cycle delay Go to Loop Top On 2/9/2012 9:35 PM, yamanoor sairam wrote: > Hello All, > > I am trying to control a servo motor using a PIC12F675 with a toggle swit= ch. When the switch is one state, the servo goes forward and the other stat= e, the motor goes reverse.=20 > > Here is something that I tried: > > _CONFIG(WDTDIS&PWRTEN&MCLRDIS&BOREN&UNPROTECT&INTCLK); > #define_XTAL_FREQ4000000 > > voidmain(void){ > TRISIO=3D(1<<3)|(1<<4); > while(1){ > if(GPIO3) > { > GPIO=3D(1<<2); > __delay_us(900); > > > GPIO&=3D~(1<<2); > __delay_us(100); > __delay_ms(19); //here the total time pulse is 20 ms including ON time > > > > } > if(GPIO4) > { > GPIO=3D(1<<2); > __delay_us(2100); > > > GPIO&=3D~(1<<2); > __delay_us(900); > __delay_ms(17); > > } > > } > } > > My main need is that the servo should spin in opposite directions wheneve= r the switch changes state. The motor changes position only once and nothin= g happens after that.=20 > > I am not able to find out what is wrong here. I also tried making the mot= or move in opposite directions without any switch control. The servo does n= ot spin as it should. It stays at the same position and makes some jerky mo= vements. > > I am looking forward to your suggestion regarding the same. > > Sai --=20 John Ferrell W8CCW Be thankful we're not getting all the government we're paying for. - Will Rogers --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .