Writing Values Greater Than 0xFF to OCR1A in AVR C Code: How?
Hello, is anyone here ?? 🧐
Solution:Jump to solution
you need to ensure that both the high and low bytes are correctly written to
OCR1AH
and OCR1AL
. Here’s how you can do it:
```
OCR1AH = (0x3344 >> 8); // High byte
OCR1AL = (0x3344 & 0xFF); // Low byte...3 Replies
Can anyone tell me if any of you have successfully written a value greater than 0xFF into OCR1A, and if so, how?
Personally, I do it in assembly using AVR STUDIO 7, and my tests show that values such as 0x3344, for example, are correctly handled, and TCNT1 counts up to this value before toggling the corresponding output (OC1A).
However, under IDE 18.1.9, there's no way to directly write such a value in C. Even when incorporating my assembly code into C, the compilation goes fine, but OCR1H always remains at zero.
Does anyone have a solution?
Solution
you need to ensure that both the high and low bytes are correctly written to
OCR1AH
and OCR1AL
. Here’s how you can do it:
This should work in IDE 18.1.9 as well.Thanks so much for the tip!
I didn’t think of splitting the high and low bytes like that. I’ll try it out in IDE 18.1.9 and see if it works 👩💻