PDA

View Full Version : servo program



rohitkondekar
09-06-2009, 07:55 PM
I am trying to run servo using interrupts, but not able to. I did it using delay function.


Ignore the comments. So whats wrong in this? i am trying to give interrupts at 1.5,1.25,1.75 ms but not able to. plz help.

or a program about how to give interrupts here?





/*----------------------------------------------------------------
-----------------HEADER FILES-------------------------------------
-----------------------------------------------------------------*/
#include<avr/io.h> //HEADER FILE FOR AVR INPUT OUTPUT
#include<compat/deprecated.h> //HEADER FILE FOR FUNCTIONS LIKE SBI AND CBI
#include<util/delay.h> //HEADER FILE FOR DELAY
#include<avr/interrupt.h> //Header for interrupts

/*----------------------------------------------------------------
-----------------MAIN PROGRAM-------------------------------------
-----------------------------------------------------------------*/
int main(void)
{
DDRA=0B11111111;
TCCR1B=(1<<WGM12)|(1<<CS11)|(1<<CS10);
TIMSK=(1<<OCIE1A);
OCR1A=375; //SET DATA DIRECTION REGISTER


while(1)
{


sbi(PORTA,0);










//DELAY IN MILISECOND ARGUMENT SHOULD NOT BE MORE THAN 255
}
return(0);
sei();}



ISR(TIMER1_COMPA_vect)
{


cbi(PORTA,0);
if(OCR1A==375)
{OCR1A=312.5;}
if(OCR1A==312.5)
{OCR1A=437.5;}
if(OCR1A==437.5)
{OCR1A=375;}

}

virgo
09-07-2009, 01:48 AM
return(0);
sei();}


I have not looked at your code in detail but your last two statements shown above will never get executed.

you shoud be doing sei(); early in your code , probably just before while(1)

and as a side note we should never return from a program running on microcontroller
so return(0); should be avoided unless you know where you will return.