Hi John,
Difficult to say something about it, without any code and hands on.
I never liked CTC timer modes. Perhaps it is easier to have an
interrupt generated only by a prescaler. Of cource that gives you
weird time values, depending on your crystal, and may give an
interrupt at every 57uS or whatever. But that is not a problem, to
have 'master' clock that ticks at such weird (but steady) interval.
Assume you have an interrupt every 57 uS.
[untested code]
int timervalue = 0;
int msektimer = 0;
.
.
.
timer_int()
{ timervalue += 57; // add the uS that have passed since previous interrupt
if(timervalue>1000) // a millisecond + some extra uS have past
{ timervalue -= 1000; // keep the remaining uS
msektimer++; // keep track of total milliseconds
}
}
Keeping track of seconds can be done in a similar way, just expand code.
Sure there is some jitter on the timervalues, but a jitter of 57uS
is usually not a problem for household purposes.
Frank
-----Oorspronkelijk bericht-----
From: NeonJohn
Sent: Monday, November 04, 2013 11:16 PM
To: [email protected]
Subject: [neonixie-l] Atmel clock/timer projects
I'm working on a simple count-down timer that will time from 0.1 to 999
seconds with 0.1 second resolution. I'm using an Atmel ATmega8515,
probably not the best chip but I have a ton of 'em from another project.
My problem is, it's not behaving anything like I expect. Up to about 10
seconds, the time interval is about a tenth of a second too long.
Between 11 and about 60 seconds, it's spot on. At 999 seconds, it has
lost 3 seconds.
I'm doing things rather conventionally. Timer 0 is set up in CTC mode
to count down the 16MHz clock at 1ms intervals. There's a state machine
that stores what the timer is doing (idling, being set, counting,
finished, etc) but the actual assertion and de-assertion of the output
pin is done in the ISR. It should therefore have millisecond accuracy.
The erroroneous time is repeatable from one run to the next down to the
millisecond so I know that I'm not missing interrupts. I've also
verified that by toggling an unused pin inside the ISR and timed it with
a high precision HP counter/timer.
So my first question to the list is, can you point me to some Atmel
clock code in C that I can study to see what I might be doing wrong?
Later I may post the code and ask for someone to look at it but I really
want to solve this problem for myself.
This is a timer for our (Fluxeon's) Roy induction heater but I plan on
open sourcing the thing - hardware and software - once I get it working.
So it needs to work right AND the code has to look good :-)
Thanks.
John
--
John DeArmond
Tellico Plains, Occupied TN
http://www.fluxeon.com <-- THE source for induction heaters
http://www.neon-john.com <-- email from here
http://www.johndearmond.com <-- Best damned Blog on the net
PGP key: wwwkeys.pgp.net: BCB68D77
--
You received this message because you are subscribed to the Google Groups
"neonixie-l" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
To post to this group, send an email to [email protected].
To view this discussion on the web, visit
https://groups.google.com/d/msgid/neonixie-l/52781CA1.2060803%40neon-john.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"neonixie-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send an email to [email protected].
To view this discussion on the web, visit
https://groups.google.com/d/msgid/neonixie-l/3C4AD234AB4E4ADDACC3F635A1C46345%40FrankPC2012.
For more options, visit https://groups.google.com/groups/opt_out.