Hi: I am new at programing on the atmega168, I am trying to control a motor with phase correct PWM on timer 0
can somebody take a look at my code to see if I am doing it correctly please.:
TCCR0A=0; //disable all PWM on Timer 0
OCRA=200; //frequency is 20kHz with no prescaler
DDRD=0xFF; //set D port as output
PORTD=0x00; //pull-up resistors turned off
//configure timer 0 for phase correct mode via OCRA, with no prescaler
TCCR0A= (1 << WGM00);
TCCR0B = (1 << WGM02)
//enable PWM on port D5 and D6 in non-inverted compare mode
TCCR0A |= 2 << 6; //port D6
TCCR0B |= 2 << 4; //port D5
//change OC0A and OC0B from 0-200 to drive motors
I am trying to follow what the datasheet says but I am not sure if I got it correct. I read that 20Khz frequency was good for controlling motors Any advise??