Closed drf5n closed 2 years ago
Thanks for the detailed report!
I tested this on a physical Arduino (connecting a logic probe to pin 3), these are the results:
const byte myWGM = 7; const byte myCOM2B = 0b10;
const byte myWGM = 5; const byte myCOM2B = 0b11;
const byte myWGM = 5; const byte myCOM2B = 0b10;
The other two myWGM = 5 configurations show no output as expected (do nothing/reserved). So I can confirm this is a bug in the simulator.
Fix released as AVR8js 0.18.10, and also updated on wokwi.com.
Thanks again for the super detailed report, it's been very helpful!
I was trying to generate a 32768Hz clock on OC2B by using WGM mode 5: Phase Correct,TOP=OC2A mode but I was unable to control OC2B in the mode.
Here is a sketch on the Uno: https://wokwi.com/projects/326859205681087060
The code is:
In the other WGM modes, I was able to generate a clock on pin 3/OC2B, which I could then count from T1, divide, and re-output on pin 10. If you change the commenting to try a different WGM mode, the LEDs toggle, and the T1 count increases.
To get my 32768Hz from 16MHz needs a divide by 500, which I could fit in a phase-correct PWM mode with OC2A=250 up and down, or a toggling mode WGM=2 CTC mode works to get the right frequency, and WGM=7 mode works, but at double the frequency.
-- Also OC2A output doesn't appear to work in Timer2 WGM=5 Maybe it's all Timer2 WGM=5 outputs?