elapsedMillis and Crystal for Real Time Clock

Status
Not open for further replies.

danixdj

Well-known member
Hi, i have a question:

If i use the optional Crystal for Real Time Clock on by teensy 3.2, the command "elapsedMillis" is more accurate or it works with a specific library only?

Thank you.

Dani
 
Last edited:
elapsedMillis always works from CPU clock from the PLL, which is synced to main 16 MHz crystal.

The RTC is meant to be used with the Time library.
 
Ok thanks..
And there's a function like elapsedMillis more accurate using Time library?

The answer to your question depends on two factors: the hardware and how you are using it. On the hardware side, the answer depends on the crystal / oscillator you're using and any compensation you may be throwing at the problem.
  • I managed to get a standard CFS-209 RTC crystal compensated to within 0.5PPM across a wide range of temperatures by coupling it with a DS18B20 and discovering its characteristic temperature-induced error curve that I could then compensate for using an open-loop control. That's a lot better than the standard CPU crystal, which is good for 5-20PPM, IIRC
  • Actively-compensated chips like the DS3231 can do that well pretty much out of the box. See Chronodot as an example. You can route a wire from the Chronodot 1Hz output into the Teensy CLKIN pinhole or simply get the time via I2C. Either way, you end up with something pretty accurate. Just remember to share grounds!
  • Lastly, if you go the custom teensy route, there are some very tasty SMD oscillators from Kyocera that allow the precision of a Chronodot in a tiny 2.5x2mm package. Not for the faint of heart but pretty amazing gear.
On the software side, you can make use of now() and a int32_t variable to achieve the same effect as elapsedmillis(), just with time function variables. The only downside is that now() increments solely in single-second increments limiting your timing flexibility to second+ intervals.

A solution with sub-second intervals could include use of the SQW output of the Chronodots' DS3231 or similar chips. Simply implement a counter on an interrupt input from SQW on the DS321 and then trigger when you exceed a reference elapsed milliseconds. Available frequencies on the DS3231 are 1Hz, 1.024kHz, 4.096kHz, and 8.192kHz. Note that the accuracy of the interval may or may not be hornswoggled by other operations on the Teensy (when interrupts get stopped, for example).
 
Last edited:
Well another alternative would be to incorporate a GPS unit (assuming your Teensy can get the radio signals from the birds). Or if your Teensy is connected to the internet, I would imagine you could use the network time protocol to get the official time.

In both of these cases, I imagine you would imagine that you would use it to adjust the internal micro/milliseconds.
 
if you have BT and your mcu connects to your android phone, you can have it pull the date command in console for date and time
 
I'm working on a 64 pad step sequencer that it send a midi clock and note out (standard serial MIDI not USB), and "elapsedMillis" isn't accurate for this scope, the midi time and note are little bit unstable and it's a problem for this use..

(ever 20 - 30 ms there is a midi output)

Can i have an accurate and stable MIDI CLOCK using a good Crystal?

Thank you..
 
Instead of using elapsedMillis(), if it's about to send data in precise regular intervals, I'd probably try to use an intervalTimer object to trigger a high priority interrupt-like function which would than care about data transmission.
 
Instead of using elapsedMillis(), if it's about to send data in precise regular intervals, I'd probably try to use an intervalTimer object to trigger a high priority interrupt-like function which would than care about data transmission.

This is a solution I think.. but it's possible to change the interval time when the object is running?
I need to change the microseconds interval without stop the function..
 
Last edited:
Status
Not open for further replies.
Back
Top