PDA

View Full Version : Real time the right way?



Michael
- 1st March 2007, 12:04
I built a stopwatch that simply uses counters that build (seconds + 1), (minutes + 1) etc.

Is that a no-no? There may be a reliability problem that way? (Although mine works fine) (I used a PAUSEUS to get everything based on an exact second).

Should you always use the PIC internal timer (TMR0) and look for a flag instead?

I've never used the timer registers and not familiar so didn't go that route.

I did notice a weird count one time and thought that maybe it's because the count got "off" and the code needed to be reset.

If you referenced to the PIC timer maybe that wouldn't happen?

Darrel Taylor
- 1st March 2007, 12:51
Have a look at paul borgmeier's clock routines.

It'll get you alot closer to real time.

Easy and Accurate Clocks without RTC IC
http://www.picbasic.co.uk/forum/showthread.php?t=2129
<br>

Michael
- 1st March 2007, 13:30
Thanks, Darrel...great info.

I've never had an experience with the timer registers so I think I'll rewrite the stopwatch code just as a self tutorial.

I was just wondering, doing it the way I have based on build counters and instruction cycles there is a chance that the code could get corrupt and miscount as the pic would need a hard reset?

I suppose if you had a reference like the timer you could "reset" based on that or something.

I did see a strange count one time and that's all I could think of.

It'll be fun to study that material.

Darrel Taylor
- 1st March 2007, 13:39
No, I don't think so.

All clock programs have to do the Seconds = Seconds +1 kind of stuff. It just depends on the Time Base that determines the accuracy.

We'd have to see the code to figure out if there was a Counting problem.

But in general, if the routine counts properly, it won't get corrupted. Well, except for a stray Cosmic Ray or two, every 10 years.
<br>

BobK
- 1st March 2007, 14:15
Good morning,

Don't forget Melanie's Olympic Timer program! Measures in 1/100th of a second if I recall. AND it's written in plain English so you can easily follow what is going on in the program.

BobK

Michael
- 1st March 2007, 18:38
I'll search that and print it out.

Actually, my code works fine except for something that looked fishy one time...it's stays in sequence all the way to 59:59 and that's all that matters.

I spent a whole afternoon trial and error with PAUSEUS to get it right. (Too lazy to do the math to figure it out).

One thing I need to look at are the led displays...they could be a bit brighter but then there being fed by the constant loop of the 4 mhz Picbasic program. I'm sure if they were scanned at a lower frequency they would brighten up.