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.
How to obtain current date and time with milliseconds in a Embedded C program?
Collapse
X
-
Tags: None
-
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
-
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 astime_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
-
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
Comment