I'm trying to get this program to use channel B for the output waveform using the phase correct PWM mode and using OCR1A as the top. With a 50% duty ratio I'm attempting to get a 10 Hz freq. I'm able to adjust the OC1A (Pin 9) if I set TCCR1A to 0x43; but nothing comes from pin 10. Code:
include "avr/io.h"
void setup()
{
DDRB = 0x6; //set pins 9 and 10 as output
/*set operation Toggle mode; WGM13:0 = 1011 phase correct PWM
CS12:0 = 101 prescaler = 1024*/
TCCR1A = 0x23;
TCCR1B = 0x15;
OCR1A = 0x187; //391 for 50% duty cycle
TCNT1 = 0; //clear counter and update OCR1A
}
void loop()
{ }
1 Answer 1
You are using Timer/Counter 1 in Fast PWM Mode with TOP set to OCR1A:
OCR1A
only describes the number to what it counts up so, 0...391 in your case.
You have to define the duty cycle with OCR1B
. 50% would be 195.
Explore related questions
See similar questions with these tags.
TCCR1A |= (1<<COM1A1);
. Pin 10 refers to the arduino's pin 10?OCR1AL = 0x87
andOCR1AH = 0x01
separately.