You need to introduce a variable for the delay for this, and slowly increase/decrease it as needed and feed your control loop with that. And because of this you need a higher resolution of delay than the __delay_ms() function. I have suggested this only for testing purposes. if(GPIO & (1<<3)) { inc =3D 1; } else { inc =3D -1; } // add the increment here towait +=3D inc; // make sure you are limiting the value if ( towait < 1000) towait =3D 1000; if ( towait > 2000) towait =3D 2000; GPIO |=3D(1<<2); __delay_us(towait); GPIO &=3D~(1<<2); Something like that... If you need even more resolution then you might need to calculate with floats... Tamas On 10 February 2012 14:08, yamanoor sairam wrote: > Hello All, > I am controlling a servo motor using the PIC12F675. The servo rotates in > opposite directions. I am controlling the servo as follows: > > > if(GPIO & (1<<3)) > { > GPIO |=3D(1<<2); > __delay_ms(1); > GPIO &=3D~(1<<2); > } > else > { > GPIO |=3D(1<<2); > __delay_ms(2); > GPIO &=3D~(1<<2); > } > __delay_ms(18); > I would like to control the rate at which the servo reaches the opposite > ends. I tried looking for articles related to speed control, I found it t= o > be too complicated to control the rate of sweep. I am looking for > suggestions for the same. Increasing the delay did not help me control t= he > speeds. I am planning to control the speed using a potentiometer. Any > suggestions would be helpful. > > Sai > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 int main() { char *a,*s,*q; printf(s=3D"int main() { char *a,*s,*q; printf(s=3D%s%s%s, q=3D%s%s%s%s,s,q,q,a=3D%s%s%s%s,q,q,q,a,a,q); }", q=3D"\"",s,q,q,a=3D"\\",q,q,q,a,a,q); } --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .