Go Down

Topic: Can't set to Fast PWM TOP=OCRA mode (Read 1 time) previous topic - next topic

Coding Badly

1. Why COM2A1:0 = 1 (Toggle OC2A Mode) is giving me frequency? In this mode WGM22:0 = 7 and OCR2A also busy with holding TOP value.


The counter increments from zero (BOTTOM) to the value in the OCR2A register (TOP).  When the counter reaches the value in the OCR2A register (TOP), the counter is reset to zero (BOTTOM).

When the Compare Output Mode is Toggle, the output pin is toggled when the counter value equals the value in the OCR2A register (which also happens to be TOP).

The counter reaches OCR2A (TOP), the pin is toggled, the counter value is reset.

Quote
2. Documentation says:
Quote
In non-inverting Compare Output mode, the Output Compare (OC2x) is cleared on the compare match
between TCNT2 and OCR2x, and set at BOTTOM. In inverting Compare Output mode, the out-put is set on compare match and cleared at BOTTOM.

This means both, OCR2A and OCR2B can hold TOP values.


No.  "TOP" is the label used for the value at which the counter is reset.  It has nothing to do with the output.  Only the OCR2A register is used for the TOP value.

OCR2A and OCR2B registers are used for the value at which the "output action" is performed.  This has nothing to do with when the counter is reset.

Go Up