Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVR Timer Programming : CTC mode vs. Normal mode

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.

like image 238
Casper Avatar asked Mar 19 '23 01:03

Casper


2 Answers

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).

like image 122
uncleO Avatar answered Mar 20 '23 14:03

uncleO


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".

like image 41
Ignacio Vazquez-Abrams Avatar answered Mar 20 '23 15:03

Ignacio Vazquez-Abrams