Hi,
I'm trying to use phase-correct PWM (for the first time) to control a motor connected to a tiny44. No matter what I set OCR0A to, duty cycle is always hanging out around 50% but the frequency is varying. What am I doing wrong?
Thanks!
#include#define byte(bit) (1 << bit) // byte with bit set #define IRLedPin PA1 #define motorPin PB2 #define setPortAPinForOutput(pin) (DDRA |= byte(pin)) #define setPortAPin(pin) (PORTA |= byte(pin)) #define clearPortAPin(pin) (PORTA &= ~(byte(pin))) #define setPortBPinForOutput(pin) (DDRB |= byte(pin)) #define setPortBPin(pin) (PORTB |= byte(pin)) #define clearPortBPin(pin) (PORTB &= ~(byte(pin))) int main(void) { //set clock divider to /1 CLKPR = (1 << CLKPCE); CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0); setPortAPinForOutput(IRLedPin); setPortAPin(IRLedPin); setPortBPinForOutput(motorPin); TCCR0A = _BV(COM0A0) | _BV(WGM00); //Toggle OC0A on Compare Match, Set WGM00 for Phase Correct PWM (Also must set WGM02 in TCCR0B) TCCR0B = _BV(WGM02) | _BV(CS00); //Set WGM02 for Phase Correct PWM as described in previous line, no prescaler OCR0A = 200; //Something other than 50% Duty cycle for(;;){ } return 0; }