SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By MA$TER_E
#115959
http://www.sparkfun.com/products/99

Could I use this to pull times with a resolution of .00 or even .0 seconds? I see that it does HH:MM:SS and AM/PM... However for my application the end result would be a stop watch reading thats something like MM:SS:XX

Or if I'm way off base and you know of a better way point me in the right direction :)

Eric
User avatar
By phalanx
#115961
While the RTC doesn't directly give you hundredths of seconds, you can make use of the SQW/OUT pin on the module and then process the output signal on your controller to give you accurate times to that resolution. The pin can be configured to output a 1Hz, 4KHz, 8KHz, or 32Khz square waves that you will have to process on your own to resolve down to 0.xx seconds. On a PIC, I would feed the signal into a timer module and set the period register to interrupt at whatever frequency I wanted.

-Bill
By MA$TER_E
#115965
Blackfin wrote:According to the DS1307 datasheet:

http://www.sparkfun.com/datasheets/Comp ... DS1307.pdf

I see no indication it can return sub-second values.

Can you clarify: Are you building a stop-watch and had intended to use a RTC for the timing function?

BTW, love the sig lol
I read through the data sheet and didn't see a way but I figured there has got to be one.

The plan is to build a little data acquisition box/lap timer for my motorcycle. I thought the RTC would be great for capturing date and time for unique identifiers to data I write to an SD card as well as display on an LCD. And I figured if I can it would be ideal to when requested just pull the time from the RTC and get my lap times as well. That’s where I need the .0 or .00 seconds.

Thanks, a guy at work said that and it describes are methodology perfectly :-)

phalanx wrote:While the RTC doesn't directly give you hundredths of seconds, you can make use of the SQW/OUT pin on the module and then process the output signal on your controller to give you accurate times to that resolution. The pin can be configured to output a 1Hz, 4KHz, 8KHz, or 32Khz square waves that you will have to process on your own to resolve down to 0.xx seconds. On a PIC, I would feed the signal into a timer module and set the period register to interrupt at whatever frequency I wanted.
-Bill
I'm glad there's people like you in the world Bill. Do you know of a good time keeping or wave processing tutorial somewhere? I haven't been through the Arduino playground or forum, yet; but I need some basics as to how I process the square wave and put it to work. I have an Arduino Uno I'm developing/learning on so hopefully I can find some kind of tutorial that utilizes it.

Eric
User avatar
By phalanx
#115973
Unfortunately I'm not well versed with AVR controllers (what's used in Arduinos) so I can't give you the specifics of how to set it up on them but I would imagine it works in a similar manner to PIC timers.

On a PIC, some timers have a period register which allows for periodic signals to be generated. The timer module constantly compares the contents of its counter register to the value in the period register. If a match occurs, an interrupt flag is set and the counter register of the timer is reset to zero so the process can start again. The timer would also be configured so its clock source comes from an external pin (which would be tied to the SQW/OUT pin) instead of the internal clock.

Pseudo code would look like this:

Config:
Set RTC to output 4KHz square wave;
Set Timer to use an exteral clock;
Load period register with 40; (4000Hz / 40 = 100Hz )
Configure interrupts;
Turn on Timer;
Turn on RTC;

ISR:
Increment Hundredths;
Clear interrupt flag;

Main:
Process time;


You will have to be careful on how you turn modules on and off since you need to synchronize the system with the updates from the RTC. If you don't need long term time keeping and calendar functionality, I would not use an RTC for stopwatch purposes since they really aren't designed for that purpose. I would simply use a timer on the controller and clock it using the crystal already on the board. Timing resolutions can be orders of magnitude smaller using the the system clock as your reference.

-Bill
By follower
#116021
MA$TER_E wrote:However for my application the end result would be a stop watch reading thats something like MM:SS:XX
If you're using it as a stop watch maybe you don't a realtime clock? Using millis() would be somewhat accurate for measuring elapsed time.

--Philip;
By mcuaust
#116023
Eric,

Sparkfun have the open-source ClockIt kit. It could give you some experience with timing on the AVR.

Also, search the Arduino forums and google for Arduino 'timer', 'lap timer', 'stopwatch' etc.