PDA

View Full Version : Programming doubt!!



firebolt_4u
01-14-2006, 11:59 PM
hi
i am woring on interfacing servo motor with avr muc.
and i have been able to do it using delay ms function and loops
however now i want to do the following
take the servo to some small angele say 10 degrees keep it there for some time say 30 ms(time can vary in a sequence of iterations) and then take it to soem large angle say near 180 degrees and then hold it for the same time
this way i wanna check the response time of the servo to move between two positions
i do not have any knowlege about timers and interrupts and i am not able to understand the libc syntax for them or how to use them
however i ahve written the folowing program

#define F_CPU 8000000UL

#ifndef sbi
#define sbi(_register,_bit_value) (_register) |=_BV(_bit_value)
#endif

#ifndef cbi
#define cbi(_register,_bit_value) (_register) &= ~(_BV(_bit_value))
#endif

#include<avr/io.h>
#include<avr/delay.h>

int main(void)
{ int i;
DDRA |=_BV(PA7);
while(1)
{
for(i=0;i<20;i++)
{
PORTA|= _BV(PA7);
_delay_ms(1);
PORTA&= ~_BV(PA7);
_delay_ms(20);
}
for(i=0;i<20;i++)
{
PORTA|= _BV(PA7);
_delay_ms(2);
PORTA&= ~_BV(PA7);
_delay_ms(20);
}
}
}

the for loops can hold the motor at positions corresponding to on time of 1ms and 2 ms respectively
however my problem is i cannot mesure the time in such a setup
and hence cannot compute the response time of the servo
is there a way to know the time takn by i to go from i=1 to i=2?
isnt this equal to one cycle?

do advice

thanks in advance

regards
pulkit