NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Running the 2nd clock
June 06, 2010 by carlhako |
Hi I have put together a simple temp sensor that uses the first clock @ 900hz to multiplex 3 7seg displays. I want to run a 2nd clock to keep rough time. This will allow me to work out some averages, 24hr, 12hr etc. Does anybody have some sample code that runs a 2nd clock, or could point in the right direction. Ive tried working it out using the data sheet its still a little over my head. Thanks Carl |
---|---|
June 06, 2010 by mrobbins (NerdKits Staff) |
Hi Carl, The ATmega168 and ATmega328P have three timer/counter modules, named Timer/Counter 0, 1, and 2. Our Crystal Real Time Clock video shows the use of Timer/Counter 0, but this can be modified for one of the other timers if you wish. Watch that video before you try to move it to a different timer. For example, to modify it to run on Timer/Counter #2, you would have to make these changes: 1) Change the name of the interrupt handler from SIGNAL(SIG_OUTPUT_COMPARE0A) to the new notation ISR(TIMER2_COMPA_vect). 2) Change all of the register names and settings in the realtimeclock_setup function. Maybe something like:
The only thing that really changed from Timer/Counter0 is that different bits were required to set the clock prescaler to CLK/1024. Hope that helps! Mike |
June 07, 2010 by carlhako |
Thanks Mike :) Exactly what I was after. I have not tried it yet, I'm currently soldering it all together onto a project board. That code looks like it will pretty much work if I copy and paste it. Thanks again! Carl |
June 14, 2010 by banerjen |
From where do I get to know about all the names of the different interrupt handlers? Nandan. |
June 14, 2010 by mrobbins (NerdKits Staff) |
Hi Nandan, Take a look at this table. However, you still have to match this to the microcontroller datasheet in order to figure out which is which! Mike |
June 14, 2010 by banerjen |
Thanks a lot. Nandan. |
Please log in to post a reply.
Did you know that you can read diagnostic data from some cars with a NerdKit? Learn more...
|