Try this;
Adjust the values 1100 to 400 for your particular servos.Code:@ DEVICE HS_OSC,WDT_OFF,PROTECT_OFF DEFINE OSC 20 ' We're using a 20MHz crystal TRISB=%00000000 ' Set PortB to all outputs PORTB=%00000000 ' Clear PortB Position VAR WORD ' Servo position data Y VAR BYTE ' Servo position update speed Left_Servo var PortB.4 ' PortB.4 = left servo output Right_Servo var PortB.5 ' PortB.5 = right servo output Y = 20 Servo: FOR Position = 1100 to 400 step-Y PULSOUT Left_Servo,Position PAUSE 15 NEXT Position FOR Position = 1100 to 400 step-Y PULSOUT Right_Servo,Position PAUSE 15 NEXT Position FOR Position = 400 to 1100 step Y PULSOUT Left_Servo,Position PAUSE 15 NEXT Position FOR Position = 400 to 1100 step Y PULSOUT Right_Servo,Position PAUSE 15 NEXT Position Y = Y-1 IF Y <=4 THEN Y=20 GOTO Servo
The resolution of PULSOUT at 20MHz is 2uS. 1100 * 2uS = 2.2mS. 400 * 2uS = 800uS. Most hobby type servos require between 1 to 2mS pulses, but it can vary depending on the servo brand.
Just experiment until you get the movement you need without slamming the servo into its stops when moving full left or full right. Increase the value of Y to speed up movement. Decrease it to slow down.
Have fun.....;o]




Bookmarks