1
\$\begingroup\$

From this tutorial, I can print local time when I code using codeblock. https://www.tutorialspoint.com/c_standard_library/c_function_localtime.htm

I am measuring capacitance by atmega644. I read the capacitance data from the ADC and print it. I want to add the local time so that I can know how much is the capacitance at a specific time.

I try the exact same thing of this tutorial and get the following errors. How can I print local time along with my continuous capacitance measurement?

enter image description here

\$\endgroup\$
3
\$\begingroup\$

The full C library is not available on embedded devices. Consult the avr-libc manual to see what's available.

In practice, if you want a real-time clock on an ATmega microcontroller, you will probably need to implement it yourself using a timer configured to fire once per second. (This will also mean you will need some way for the user to set the current time.)

\$\endgroup\$
2
\$\begingroup\$

You can easily count the amount of micros/millis from startup, but you can't have localtime on the uC. So your best bet is to couple the ADC value with the local millis elapesed since startup, and translate that timing into localtime on your host machine, once it received the value from the uC.

In order to have a good translation, you might want to issue the start command from the host machine as well. Just take into consideration also the communication times; they are pretty predictable (ex: if you are using a serial port, the serial speed and the amount of bits sent to issue the start command, is the base to make your math and add a fixed time value to the start command).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.