I am having issues with properly setting up the fast PWM mode 15 in my Arduino Uno (ATmega328).
Most of the registers seem pretty straight-forward, but I am not sure about a few of them.. For example, I struggle with understanding what type of compare output modes (COM) to choose.. What does it mean if OC1A or OC1B are disconnected. Will OC1A still serve as the TOP value for mode 15?
I am aware that OC1A will not generate a signal with mode 15, so I am measuring the PWM signal on the OC1B pin (PB2).
This is my code for setting a PWM frequency of 100Hz with a duty cycle of 0.5, but I am picking up no signal on PB2:
void setup(){
DDRB = 0;
DDRB |= (1 << PB2) | (1 << PB1); // Set OC1A and OC1B to outputs
// Set WGM 3:0 = 0b1111
// Set prescaler to 1024 with CS2:0 = 0b101
// Set COM to non-inverted for OC1B (UNSURE HOW THIS WORKS)
TCCR1A |= (1 << COM1B1) | (1 << WGM11) | (1 << WGM10);
TCCR1B |= (1 << WGM13) | (1 << WGM12) | (1 << CS02) | (1 << CS00);
TCNT1=0;
/* Formula for calculating OCR1A for 100Hz with prescaler 1024 chosen:
f = Fclk/(presc*(OCR1A + 1)) -> OCR1A = (16000000/(100*1024))-1 = 155
*/
OCR1A = 155;
OCR1B = 77; // For a duty cycle of 50%
SREG |= 0b10000000; // Enable global interrupts
}
void loop() {}