![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
jruibarroso
Joined: 07 Jan 2006 Posts: 64 Location: Braga
|
1/10 Sec counter |
Posted: Fri Mar 09, 2007 6:25 am |
|
|
#define INTS_PER_SECOND 32 // (8388608/(4*256*256))
BYTE seconds; // A running seconds counter
BYTE int_count; // Number of interrupts left before a second has elapsed
#int_rtcc // This function is called every time
void clock_isr() { // the RTCC (timer0) overflows (255->0).
// For this program this is apx 32 times
if(--int_count==0) { // per second.
++seconds;
int_count=INTS_PER_SECOND;
}
}
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
i've done this and get a very precise seconds counter, but how can i get a 1/10 Sec counter , any ideas ? Thank you all |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Fri Mar 09, 2007 7:58 am |
|
|
It appears that your clock is 8.388608MHz.
So, you want a interrupt every 838860.8 counts. This is problematical (particularly because of the '.8'...). Presumably you have to use this frequency for some other reason?. If not, then consider changing master clock rates.
However if you are 'stuck' with this frequency, then the big question is whether the 1/10th second has to be accurate 'short term', or 'long term'. If the latter, then 'tweaks' can be applied to correct the error from the effect of the odd starting frequency. If the former, then you have problems. One solution (if the pins, and hardware are available), is to use a second clock for the timing. The nearest I could get, without using this, with the existing clock, was to use timer2, with a value of 218 or 219, 1:16 prescaler, and 15 postscale, which gives an interrupt every 1/40.08 second, or 1/39.9 second. Using this instead of your existing counter 'tick', allows the single interrupt to feed both clocks, but with a 0.002% error. Long term, this can be corrected by adding or subtracting one extra count to the clock.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
jruibarroso
Joined: 07 Jan 2006 Posts: 64 Location: Braga
|
cont |
Posted: Fri Mar 09, 2007 8:07 am |
|
|
Hello and thank you for your help. I'm not stucked to 8388608 MHz, this value is very precise to 1 sec. counts, so if you can advise me with other value that machs ok with 0.1 Sec i would apreciate, I'm very newby at this and have no school formation on this
Thank you so much |
|
![](templates/subSilver/images/spacer.gif) |
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Mar 09, 2007 8:32 am |
|
|
I suggest you to read the following threads posted by newguy, it is a very good
explanation regarding timers use. Once you grasp how the parameters affect the
timers behaviour, surely you will try to solve your consult by yourself.
http://www.ccsinfo.com/forum/viewtopic.php?t=22467
Humberto |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|