How to obtain current date and time with milliseconds in a Embedded C program?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sreeram Charan
    New Member
    • Jan 2011
    • 1

    How to obtain current date and time with milliseconds in a Embedded C program?

    I am trying to obtain current date and time with milliseconds in an Embedded application using C programming language in Kiel compiler. can any one suggest how can I do this.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    That entire depends on if the platform you are using has a real time clock and if it does the resolution of that clock and the interface used to read it.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      To elaborate on Banfa's answer: there is no Standard C Library function that is guaranteed to give you current date and time with millisecond resolution.

      You either need to make use of the details of how your platform supports implementation-dependent features of the <time.h> functions or you need to make use of nonstandard functions provided by your platform.

      Does the hardware of your embedded system have a millisecond-resolution clock/timer?

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Elaborating further plenty of embedded platforms have no real time clock at all particularly in the default implementation so the standard library supplied with the compiler can't even support the standard functions in time.t such as time_t time ( time_t * timer ); which returns the current time in seconds since 1/1/1970 00:00:00.

        Most micro-processors include no real time clock, if one exists on the platform then it is normal additional hardware (in the form of a real time clock chip with crystal) so the standard library for the micro-processor can have no prior knowledge of it.

        On the other hand if you just need to measure elapsed time pretty much all micro-processors have a timer interrupt and some have several allowing you to measure time in terms of some multiple of the micro-processors clock frequency.

        Comment

        • horace1
          Recognized Expert Top Contributor
          • Nov 2006
          • 1510

          #5
          I tend use something like a FM33256 which has a RTC (real time clock) and SRAM which would suit most applications
          Uncover the future of technology with Infineon, the foremost innovator in semiconductor solutions ► Explore now and join us on the journey!


          I have also used a GPS receiver to get the current time
          However, real time accruracy to a millisecond is non trivial - do you need it to be so accurate?

          Comment

          Working...