Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: elapsedMillis and Crystal for Real Time Clock

  1. #1
    Senior Member
    Join Date
    Oct 2016
    Posts
    170

    elapsedMillis and Crystal for Real Time Clock

    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 by danixdj; 04-28-2017 at 05:25 PM.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,304
    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.

  3. #3
    Senior Member
    Join Date
    Oct 2016
    Posts
    170
    Ok thanks..
    And there's a function like elapsedMillis more accurate using Time library?

  4. #4
    Senior Member Constantin's Avatar
    Join Date
    Nov 2012
    Location
    In the yard with a 17' Dia. Ferris Wheel
    Posts
    1,408
    Quote Originally Posted by danixdj View Post
    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 by Constantin; 04-29-2017 at 12:41 PM.

  5. #5
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,063
    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.

  6. #6
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,021
    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

  7. #7
    Senior Member
    Join Date
    Oct 2016
    Posts
    170
    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..

  8. #8
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,453
    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.

  9. #9
    Senior Member
    Join Date
    Oct 2016
    Posts
    170
    Quote Originally Posted by Theremingenieur View Post
    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 by danixdj; 04-30-2017 at 08:37 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •