Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
#include <avr/io.h> //for 8mhz internal oscillator controlling servo by centering it #include <avr/interrupt.h> unsigned int i=0;int main (void) { DDRC |= (1 << 7); // Set LED as output TCCR1B |= (1 << WGM12); // Configure timer 1 for CTC mode TIMSK |= (1 << OCIE1A); // Enable CTC interrupt sei(); // Enable global interrupts TCCR1B |=(1<<CS12); // Start timer at Fcpu/256 for(;;); } ISR(TIMER1_COMPA_vect) { if(i==1) { PORTC&=~(1<<7); OCR1A=625;//give 20ms delay after the servo is given no signal i=0; } if(i==0) { PORTC|=(1<<7); OCR1A=47;//bring servo to the centre by giving nearly 1.5 ms delay i=1; }}
#include<avr/io.h>#include<util/delay.h>int main(void) { DDRC|=_BV(7);//set pin7 of portc as o/p while(1) { PORTC=0x10; //turn on pin7 _delay_us(1100); //delay 1.1ms to bring the servo to extreme left PORTC=0x00;//turnoff pin7 _delay_us(1100);//delay another 1.1ms _delay_ms(19); //delay 19 ms for giving out 50 hz frequency }return(0); }
#include<avr/io.h>#include<util/delay.h>int main(void) { DDRC|=_BV(0);//set pin0 of portc as o/p while(1) { PORTC|=1<<PC0; //turn on pin0 _delay_us(1100); //delay 1.1ms to bring the servo to extreme left PORTC&=~(1<<PC0);//turnoff pin0 _delay_ms(19); //delay 19 ms for giving out 50 hz frequency }return(0); }
PORTC=0x10; //turn on pin7
#include <avr/io.h> //for 8mhz internal oscillator controlling servo by centering it #include <avr/interrupt.h> #include <util/delay.h>#define F_CPU 8000000int main (void) { DDRD |= _BV(5); // Set PORTD5 as output DDRC =0x01; TCCR1B |= (1 << WGM13); // phase and frequency correct mode ICR1=10000; TCCR1A|=(1<<COM1A1);//clear oc1a when upcounting and set Oc1a while downcounting TCCR1B |=(1<<CS11); // Start timer at Fcpu/8 PORTC=0X01; while(1) { for(OCR1A=500:OCR1A<=1000;OCR1A++) { _delay_ms(1); }return(0); }
my servo requires a pulse of 0.5 to 2.6 ms