I've been having trouble understanding what's happening when I try to set a value for OCR1A. Making things as simple as possible, I tried:
void setup() {
OCR1A = 16000;
Serial.begin(9600);
Serial.println(OCR1A);
}
void loop() {
}
No matter what x I put for OCR1A though, it seemed to only give me x mod 256. This made it seem like it was only setting the lower register. So instead I tried
void setup() {
OCR1AH = 0b00111110;
OCR1AL = 0b10000000;
Serial.begin(9600);
Serial.println(OCR1A);
}
void loop() {
}
Again, it only printed the value in the lower register. Thinking this was maybe a problem with the print function, I replaced the println with separate commands to Serial.println(OCR1AH); Serial.println(OCR1AL); For some reason it doesn't print anything here, though when I was using Arduino-0021 earlier today (instead of the Arduino-0022 I'm using now), it printed 0 for OCR1AH and 128 for OCR1AL.
So maybe the println command is doing weird things. I tried setting up something using CTC mode with no prescaling, toggling OC1A on compare match.
void setup() {
pinMode(9,OUTPUT);
OCR1AH = 0b00111110;
OCR1AL = 0b10000000;
TCCR1A = _BV(COM1A0);
TCCR1B = _BV(WGM12) | _BV(CS10);
}
void loop() {
}
Now using a multimeter in frequency mode, I look across ground and Digital 9 (which should be PB1 / OC1A), and get a readout of 7.998 MHz, no matter how I try to set OCR1A. This seems consistent with OCR1A being zero, so not even the low bit is being set correctly?
As a further test, I tried putting Serial.println(TCNT1); into the loop() function, and it kept printing 0, which also seems consistent with OCR1A being 0, but I'm not sure if trying to print the value interferes with it updating or something, so this might not be a good test.
Anyway, if anyone can explain what is happening here, I'd be much obliged!