Millis() and timer 0

I am a little confuse where to post my questions. The categories are not very explanatory.
I am using an UNO rev3.
It looks to me as though the millis() function uses timer 0.
I need to use all six of the UNO's PWM outputs but if the millis() function uses timer 0 then only 4 PWM outputs are available for projects?

Can I use timer 0 PWM if millis() is not used or does millis() use timer 0 in any case, whether I use it or not.

I need to reconfigure the timers to suite my PWM requirements.

Not directly. Timer 0 is used for micros() and some overflow will increment millis(). PWM is not affected, can be used as indicated.

Timer0 runs millis() off its overflow interrupt, while PWM works using the Output Compare hardware of the timer. That means you get millis() and analogWrite() functionality at the same time.

However, if you're using custom PWM (by manipulating the timer control registers to change PWM frequency or resolution) (instead of just using analogWrite()), then you WILL break millis()

3 Likes

Thank you, that answers my question well.

What is the default values of the TCCR0A and TCCR0B for correct operation for millis() to work correctly?

According to the data sheet the INITIAL values are 0 but this will put the timer into normal port operation and not timer operation.

This is the initialization of timer0 from the init() code in the Arduino core:

It called Timer/Counter X (x = 0, 1, 2) Module (TC X) in ATmega328P MCU. It can be operated either as Timer or Counter with th ehelp of the TCCR1B Register.

1. TC1 is said to be working as "Timer 1" when the driving pulse of TCNT1 Register (clkTC1) ia taken from internal oscillator (Fig-1) with TC1Clock Prescaler.


Figure-1:

2. TC1 is said to be working as "Counter 1" when it receives the clocking pulses (clkTC1) from external source (Fig-2) with prescaler.


Figure-2:

YES I KNOW ALL OF THIS but it is not what I asked!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.