Hi,
I am trying to run a servo control using PWM in phase and frequency correct mode.After programming my AVR (Atmega16), when i run it, the servo only twitches without actually moving. Here is the code below:
#include#include //HEADER FILE FOR FUNCTIONS LIKE SBI AND CBI #include int main(void) { //Enable internal pull ups PORTD=0xFF; DDRD=0xFF; //TOP=ICR1; //ICR1=20000 defines 50Hz PWM ICR1=20000; TCCR1A|=(0<<COM1A0)|(1<<COM1A1)|(0<<COM1B0)|(0<<COM1B1)| (0<<FOC1A)|(0<<FOC1B)|(0<<WGM11)|(0<<WGM10); TCCR1B|=(0<<ICNC1)|(0<<ICES1)|(1<<WGM13)|(0<<WGM12)| (0<<CS12)|(0<<CS11)|(1<<CS10); //start timer with prescaler 1 //with input clock frequency = 2 MHz while(1) { OCR1A = 1000; _delay_ms(3000); OCR1A = 2000; _delay_ms(3000); } }
I am using a HS-311 servo which is capable of 90 degree rotation.
My Clock frequency is 2 MHz and prescalar is N=1 so that I get a 50 Hz square wave. I set the TOP=ICR1=20000. I vary the OCR1A value for the different servo positions as shown in the code.
I am following the guidelines as given in this URL:
[url]
http://mil.ufl.edu/~achamber/ser...
[/url]
Please see the attached file which contains the table of waveform generation modes. I am using mode 8.
Please tell me if I am doing something wrong or missing something.
Thanks,
Sumair