servo motor controlling with atmega16

Thread Starter

stylediva

Joined Dec 6, 2011
72
i have written code for my servo motor which is HITECH HS-442..using atmega16..but with this code it is taking only 12 positions..i need to control the angles..what shud i do with this code??.

Rich (BB code):
#include<avr/io.h>
#include<util/delay.h>
float num1=0.1;
int main()
{
DDRB=0xFF;
PORTB=0x00;
int i;

while(1)
{
for(i=1;i<=10;i++)
{
PORTB=(1<<0);
_delay_ms(num1);
PORTB=0x00;
_delay_ms(20);
num1=num1+.5;
_delay_ms(1000);
}
}
}
 
Last edited by a moderator:

kubeek

Joined Sep 20, 2005
5,795
Rewrite it to use timer/pwm. This is a simple example of the timing of servos, but if you want your micro to do anything else than simply output one signal, you need the timing to be independent of the main while loop. This way if you calculated anything else before finishing the loop, you would upset the timing.
 
Top