I was trying to make a 24-bit timer with the output of timer1 driving the input of timer0. But it didn't work, and my scope shows no output from timer1. So concentrating on timer1 for now. 328P.
I need to run timer1 at 16MHz, and will need to use the capture facility. So I would like to set OCR1A at 0xFFFF as the top, and OCR1B at 0x8000, which in theory should produce a 50% duty cycle square wave at about 244Hz. But it doesn't. So after hours in the datasheet I've concluded I don't know how to get this done.
Below is code from a tutorial that duplicates my situation: fast PWM mode 15, no prescaler.
void setup () {
// Pin 10(OC1B) is output
pinMode(10, OUTPUT);
//Load 1000 into OCR1A for 15.98KHz
OCR1A = 1000;
//Load 200 into OCR1B for 20% duty cycle
OCR1B = 200;
// non-inverted fast PWM on OC1B with prescalar of 1 for 15.98KHz fast PWM
TCCR1A = (1<<COM1B1) | (1<<WGM11) | (1<<WGM10);
TCCR1B = (1<<WGM13) | (1<<WGM12) | (1<<CS10);
}
void loop() {
}
And that does produce an oscillating output, but it doesn't look anything like a square wave. Moreover, if I change the settings very much, the output goes away, and it just stays high all the time. For example, changing OCR1B to 500 does that.
So is what I want to do not possible? Or do I have the registers wrong? Also, my understanding is that the compiler automatically handles the two steps involved in reading from or writing to 16-bit registers. Is that correct?
This link offers a cheat sheet for changing PWM frequency and takes a hybrid approach ... just changes the registers that affect frequency then use analogWrite to set the duty.