CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

1/10 Sec counter

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jruibarroso



Joined: 07 Jan 2006
Posts: 64
Location: Braga

View user's profile Send private message Send e-mail MSN Messenger

1/10 Sec counter
PostPosted: Fri Mar 09, 2007 6:25 am     Reply with quote

#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
Ttelmah
Guest







PostPosted: Fri Mar 09, 2007 7:58 am     Reply with quote

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
jruibarroso



Joined: 07 Jan 2006
Posts: 64
Location: Braga

View user's profile Send private message Send e-mail MSN Messenger

cont
PostPosted: Fri Mar 09, 2007 8:07 am     Reply with quote

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
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Mar 09, 2007 8:32 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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