How to use the clock in SPRESENSE



  • For the NTP Server I need some time functions as used in the Arduino Time Lib. It seems that SPRESENSE brings its own time functions? Include Time.h has no effect, it won´t even show up while compile. I´m searching for the "now()" function which gives the actual time in a seconds timestamp format. Any hint on this?
    thanks
    Daniel


  • DeveloperWorld

    Hi Daniel

    You can use "time()" function for this.

    Example:
    void setup() {
    Serial.begin(115200);
    }

    void loop() {
    time_t start_time;

    time(&start_time);
    Serial.println(start_time);
    }

    Best regards,
    Kamil



  • @KamilTomaszewski How precise is the time() function? I'm currently using an interrupt every 25 us to increment an unsigned int counter and then using that counter as necessary. I've no idea if I need to take care of an eventual overflow, but maybe it won't cause any huge problems for me (just maybe a minor sound glitch).


  • DeveloperWorld

    @the_mutt CONFIG_USEC_PER_TICK is set to 10000, so the precision is 10 us. See https://github.com/sonydevworld/spresense-nuttx/blob/master/sched/Kconfig#L96



  • @KamilTomaszewski Oooh! Very interesting! From what I understand of the text in the link you quoted, 10000 is the number of us per tick (from a timer interrupt) if SCHED_TICKLESS is false, while 100 us precision is the precision reported by the system timer (without interrupts). However, how do we set SCHED_TICKLESS (would defining it at the top of our code file suffice)? And does the underlying timer have enough resolution to bring CONFIG_USEC_PER_TICK down to 10 us (and again how to set that)?

    By the way, that link brings up another question: how much can I rely on the underlying NuttX implementations of things? I know that the Arduino IDE works on top of a base NuttX install, but up to what point can I depend on that, and is it possible to alter some things for gains (similarly to how I might set registers on an ATMega328 to increase Arduino performance)?


  • DeveloperWorld

    @the_mutt I'm sorry but I made a mistake. Precision is 10ms, not 10us. The current config can be found here: arduino15 / packages / SPRESENSE /tools / spresense-sdk / 1.1.3 / spresense / release / include / nuttx / config.h. Adding define used in NuttX in the Arduino code will not do anything. If you would like to change something in NuttX then you can use this repository to prepare a package for Arduino: https://github.com/sonydevworld/spresense-arduino-compatible