Change the world

Control Software

The following example programs are available to demonstrate the basic principles of using servo motor(s) with a PIC18F4620.

ex1_servo_sweep.c

Example program that changes the position of a servo every 200ms from 90 degrees (high pulse = 1000us) to 180 (2000us) degrees and back again in 100us pulse increments

 

ex2_servo_sw.c

Example program that changes the position of a servo based on the inputs from 8 switches. Each switch will correspond to a specific pulse value, with SW0 being 700us and SW7 being 2300us.  SW0 has the lowest priority and SW7 has the highest, i.e. if SW0 and SW3 is both ON, SW3 will take priority.  If all the switches are off the servo will move to the centre position (1500us)

 

ex3_servo_multiple_sw.c

Example program that changes the position of 2 servos at the the same time according to 8 switches.  SW7 to SW4 controls servo0 and SW3 to SW0 controls servo1.

 

ex4_servo_analog.c

Example program that changes the position of a servo based on an analog input PORTA RA0 (AN0).  The position of the servo will be based on the following scaling of the input value:

ANALOG VAL      SERVO POSITION (x100us)

============    =======================

1023            23

.

.               (16 different positions)

.

0               7

Just note that if a non-linear POT is used, the botom values of the analog input will not be linear and the servo output will also not be linear.