Which clock is used to run each timer (Timer0, Timer1, and Timer2)? Is there only one or more than one clock?
You can have internal or external clocks, with different prescalers, selectable for each timer. See the ATMega data sheet for the details.
Unfortunately I'm not understanding the datasheet on this one.
The prescalers and compare values for interrupts I get but I'm not seeing information where the timers are getting their input from and if they are all the same source or different (given there are no external sources).
For each timer, there is a section in the data sheet entitled "Timer/Counter Clock Sources".
The Timer section titled "Register Description" tells you to set bits in a register (bits CS00 to CS02 in register TCCR0B for Timer0) to select a particular clock source. For Timer0, Table 15.9 in the ATMega328p data sheet gives the exact details.
What particular points are giving you difficulty?
Quite a few items actually.
I’m trying to understand what the clock sources are for each timer which feeds into understanding which clocks are running in each power save mode which in turn will help me understand why my program isn’t working. All the while (hopefully) leading to an understanding of Timer 2 and the possibility I may have to rewrite the entire project to use it based on the table “Active Clock Domains and Wake-up Sources in the Different Sleep Modes” and the comment below it “If Timer/Counter2 is running in asynchronous mode”. If it gets that far, I need to the comment about timer 2 and its asynchronous clock mode (what ever that means).
Perhaps you should read the "How to use this forum" post, post your code using code tags and ask a relevant question.
"Asynchronous" in this case means that Timer2 can run from a crystal (often 32768 Hz), or a clock signal on an external pin, even while the processor is in the deepest possible sleep mode and everything else is stopped. Very handy for creating a Real Time Clock.
jremington: Perhaps you should read the "How to use this forum" post,
I have. The datasheet, google, and Mr. Gammon's forum have not been able to explain this to me.
jremington: post your code using code tags
In my experience it takes asking the right question to get an answer. Technically this is my fourth thread. I posted the code previously and got zero responses (help).
jremington: ask a relevant question.
I did. See post 1.
jremington: "Asynchronous" in this case means that Timer2 can run from a crystal (often 32768 Hz), or a clock signal on an external pin, even while the processor is in the deepest possible sleep mode and everything else is stopped. Very handy for creating a Real Time Clock.
With your help, I'm finally now getting somewhere.
Are you familiar with the sleep modes and the table in datasheet "Active Clock Domains and Wake-up Sources in the Different Sleep Modes"?
I think all the timers run off of the Main pclk, except that timer 1 can optionally run off an external crystal (that shares pins with the external main oscillator, so isn't very usable on an arduino.) Power savings wise, any mode that turns off the cpu clock also turns off the timers. Except the wdt.
I'll check when I'm on a system that is better for reading the data sheets.
So the millis() function stops when any power save mode is invoked?
Westfw's post #7 is largely wrong, and I hope he will take the time to read the data sheet and correct it, particularly with respect to Timers 1 and 2.
Good luck with your project.
I’m going to have to stick with what I said, with two exceptions:
- timer 0 and 1 can be clocked by an external pins. But those pins are synchronous wrt CLKio, so they don’t work if the main oscillator is off.
- I left out the prescalers that you can insert between CLKio and the timer input, considering them “part of the timer”
Unfortunately, that means that the primary conclusion, that the timers don’t run during the main power-down modes, still seems to be true.
jremington: Good luck with your project.
Luck is not what I need, I'm in need of information (I can understand). What more information do you want?
I, too, would not consider the prescaler a "source". The prescaler is applied to CLKIO when run from the internal source. The prescaler doesn't matter if the timer doesn't increment.
From the way I read the datasheet and what has been posted so far, this is what I understand: 1. All the timers can be run from an internal source which is based on CLKIO or can be clocked externally 2. But the clock input is the same pins as the main oscillator 3. Only Timer2 runs while powered down.
Questions: 1. Is the millis() function inoperable while powered down? 2. The Arduino UNO and other prefabricated Arduino boards will not allow the use of the external clock for Timer2? 3. Where would I find details the steps to setup the software and the hardware to clock Timer2 from an external source?