Search code examples
avr

Independent modes of Output Compare Pins A and B in Atmega328


I was looking at Atmega328. Atmel has given lot of features in timer section. But I observed that Output Compare A and Output Compare B modes of operation depends on WGM bits and cannot be set differently for both. For Example: I cannot select OCA pin in Fast PWM mode and OCB in Normal mode/CTC mode. Either both have to be in normal mode or both in fast PWM or other modes. Can anyone confirm this? May be atmel could have added a feature where in both OCA and OCB be operated in independent modes.


Solution

  • Since both OCxA and OCxB use the same counter, it cannot be used it in different counting modes simultaneously. One single value cannot in the same time count repeatedly from zero to top, and in the same time to top and then downward to zero, or count to particular independent value (CTC). It has no sense. But using COMxxx bits in TXCCRxA, you can configure compare match unit to be not connected to the output, therefore, to be used as if in "Normal mode".

    When WGM bits set to 111 you can use the timer in mixed PWM/CTC mode: timer will count up to OCRA value, while OCRB (in range 0...OCRA) will be used to generate PWM output.

    In Timer1 you can set WGM bits to 1110 to enable CTC up to value of the ICR1 register, while both outputs could be used to generate PWM waveform, you can disconnect any PWM output in COM1xx bits, and use it as "normal", to generate the interrupt request, without value output to the OC1x pin.