Change the world

Control Software

Download: Examples - Servo.zip

The following example programs are available to demonstrate the basic principles of using a servo motor:

ex1_servo_sweep.c

Example program that changes the position of a servo every 10ms from 45 degrees (high pulse = 1000us) to 135 (2000us) degrees and back again in 10us pulse increments

* Servo control signal connected to PB4 (Servo5)

 

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)

* Servo control signal connected to PB4 (Servo5)
* 8 switches connected to PB8 - PB15 with pullup resitors

 

ex3_servo_multiple.c

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

* Servo control signal connected to PB4 (SERVO5)
* Servo control signal connected to PB5 (SERVO6)
* 8 switches connected to PB8 - PB15 with pullup resitors

 

ex4_servo_analog.c

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

ANALOG VAL      SERVO POSITION
============    =======================
4095            2300
.               .
.               .        
.               .
0               700

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. 

* Servo control signal connected to PB4 (SERVO5)
* a potentiometer (POT) connected to PA1 (ADC1_IN1 - Analog1 Channel 1)