Im having trouble trying to figure out what I thought would be simple--generate a 60hz square wave
with variable duty cycle..
what I have seems to 'hang' when the pwm value is around 78..I cant see why it would do that..
i am using a common minipro 5v 16m 328 on pin3 output
here is my code--
//Initialize Timer2 TCCR2A = 0; TCCR2B = 0; TCNT2 = 0; // Set OC2B for Compare Match (digital pin3) pinMode(3, OUTPUT); //bitSet(TCCR2A, COM2B0);//not valid when used by itself bitSet(TCCR2A, COM2B1);//clear OC2B on up count compare match //set OC2B on down count compare match // Set mode 5-- Phase correct PWM to OCR2A counts up and down bitSet(TCCR2A, WGM20); bitSet(TCCR2B, WGM22); // Set up /1024 prescale bitSet(TCCR2B, CS20); bitSet(TCCR2B, CS21); bitSet(TCCR2B, CS22); //OCR2A = 32; // Sets freq 50hz? OC2A PIN 11 OCR2A = 156; //Sets freq 50Hz //Timer 2 counts up and down for 312 total counts //312 x 1024 x.0625 = 19.968ms 50.08 Hz // enable timer compare interrupt //bitSet(TIMSK2, OCIE2A); OCR2B = 78;//50% duty cycle valid values 1-155
maybe someone has better code for this or can see what I have wrong--thanks for any help--