Hi there! i would like to know when to use timer registers for PWM, and when to use just analogWrite()
thanks
Hi there! i would like to know when to use timer registers for PWM, and when to use just analogWrite()
thanks
Use the timer registers when you are clever, and want to do PWM at a frequency different to the default.
In particular you can set different PWM frequencies (from a small set of related values) and still
have analogWrite() do what you expect, or be more adventurous and use different modes (and
more than 8 bits for timer1). Note than particular pins are controlled by specific timers on the
standard Arduinos, pins 5&6 by timer0 (which also does millis(), delay(), etc.), pins 9&10 by timer1
and pins 11 & 3 by timer2.
By default all the counters clock at system clock divided by 64 (for 16MHz than means 250kHz),
and timer0 cycles in 256 steps, the others in 510 steps (using phase-correct mode they count
up and then down and then up...)
The division factor can be programmed from 1, 8, 64, 256, 1024 on timer0, the other timers are
slightly different IIRC
A lot depends on your requirements. Some info here about timers: