Sony's Developer World forum

    • Home
    • Forum guidelines

    Upcoming maintenance 

     

    Dear Customers and Partners.

    This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.

    This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.

    We apologize for any inconvenience.

     

     

    How to use the clock in SPRESENSE

    Spresense
    3
    6
    5034
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      DocDan last edited by

      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

      1 Reply Last reply Reply Quote
      • K
        KamilTomaszewski DeveloperWorld last edited by

        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

        T 1 Reply Last reply Reply Quote
        • T
          the_mutt @KamilTomaszewski last edited by

          @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).

          1 Reply Last reply Reply Quote
          • K
            KamilTomaszewski DeveloperWorld last edited by

            @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

            T 1 Reply Last reply Reply Quote
            • T
              the_mutt @KamilTomaszewski last edited by the_mutt

              @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)?

              1 Reply Last reply Reply Quote
              • K
                KamilTomaszewski DeveloperWorld last edited by

                @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

                1 Reply Last reply Reply Quote
                • First post
                  Last post
                Developer World
                Copyright © 2021 Sony Group Corporation. All rights reserved.
                • Contact us
                • Legal