When comparing the advantages and disadvantages of CTC mode and Normal mode in AVR Timer programming, which one do you think is better? Why? Can you explain more for me?
Thank you for you help.
In Normal Mode, the timer triggers interrupt handlers. These can do practically any function you want, but they run on the CPU, which prevents anything else from running at the same time.
In CTC mode, you can also trigger interrupts, but it is also possible to not use interrupts and still toggle an output pin. Using it this way, the functionality occurs parallel to the CPU and doesn't interrupt anything.
PWM runs in the background like CTC, but the timing of the output on the pin is different. It is more suited to devices like servos that take pulse-width modulation as input.
If all you want to do is toggle an output pin, use CTC or PWM. If you want to do more, use normal mode (or CTC or PWM, depending on the timing requirements).
From the manual:
Using the Output Compare to generate waveforms in Normal mode is not recommended, since this will occupy too much of the CPU time.
For generating a waveform output in CTC mode, the OC1A output can be set to toggle its logical level on each compare match by setting the Compare Output mode bits to toggle mode (COM1A1:0 = 1).
There is no "better" between the two. Sometimes you need to go full count, and sometimes you don't. You use the one that fits your needs, not the one that is "better".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With