PROGRAM
const byte OUTPUT_PIN = 3; // Timer 2 "B" output: OC2B
const byte n = 65; // for example, 8.89 kHz
void setup()
{
pinMode (OUTPUT_PIN, OUTPUT);
TCCR2A = bit (WGM20) | bit (WGM21) | bit (COM2B1); // fast PWM, clear OC2A on compare
TCCR2B = bit (WGM22) | bit (CS21); // fast PWM, prescaler of 8
OCR2A = n; // from table
OCR2B = ((n + 1) / 2) - 1; // 50% duty cycle
} // end of setup
void loop() { }
This page can be quickly reached from the link: http://www.gammon.com.au/timers
PWM Phase shifting program
const byte n = 65; // for example, 8.89 kHz
void setup()
{
pinMode (OUTPUT_PIN, OUTPUT);
TCCR2A = bit (WGM20) | bit (WGM21) | bit (COM2B1); // fast PWM, clear OC2A on compare
TCCR2B = bit (WGM22) | bit (CS21); // fast PWM, prescaler of 8
OCR2A = n; // from table
OCR2B = ((n + 1) / 2) - 1; // 50% duty cycle
} // end of setup
void loop() { }
This page can be quickly reached from the link: http://www.gammon.com.au/timers
PWM Phase shifting program
Comments
Post a Comment