Servo Control using a Microcontroller
In this tutorial, I have used Atmega8 development board and HXT900 servo. If you do not have a development board, you can either setup the entire circuit on a breadboard, or make yourself one. Refer DIY AVR development board tutorial if you are interested in making your own development board. If you are using a breadboard, just keep voltage and power requirements in mind and generate regulated input to your setup and servos.
Also refer Software requirements tutorial if you are not sure what software to use for writing and compiling code, or for uploading code into the microcontroller.
While writing this tutorial, I have used USBasp programmer and Eclipse with AVR Eclipse Plug-in installed. You can as well use any serial programmer (or other compatible programmers), AVR Studio and/or Ponyprog for development and uploading code into microcontroller.
Simple Servo Code (Using software PWM)
There are two programs written in this tutorial for controlling a servo. First one is using software PWM for generating appropriate repetitive cycles and pulses using delays. In the second program, the logic is still the same, but uses timers to generate hardware PWM.
Psuedocode:
- Setup hardware
- Bring a port pin high for 1ms-2ms
- Bring pin Low
- Wait for 15-20ms
- Go to step 2 and Repeat the process
...to be continued
Do you have anything to say?
Visit the Forum to discuss, learn and share anything related to robotics and electronics !!