Continue to Site

[SOLVED] ATTiny13 get current time

Status
Not open for further replies.

strongdrink

Junior Member level 2
Junior Member level 2
Joined
Sep 27, 2011
Messages
23
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,434
Hello all,

I am using the ATTiny13.
How would one get the current time using C? Is there a gettime() function or similar?

Tx.
 

strongdrink said:
I am using the ATTiny13.
How would one get the current time using C? Is there a gettime() function or similar?
In microcontrollers low level programming, you have to write such functions by yourself. Some compilers may have built in functions for time measurement, but there is no PC here to keep a calendar and give it to you whenever you ask for it.

Alexandros
 

I am aware. Sorry if I wrote the question wrong. But I mean, is there any way to get uptime in milliseconds (or any format)? one way would be to keep incrementing a variable at the end of the main loop...
 

strongdrink said:
is there any way to get uptime in milliseconds (or any format)? one way would be to keep incrementing a variable at the end of the main loop...
I think it would be better to use the timer interrupt for this purpose. This is what timers are meant to do. Inside timer interrupt you can increment this counter and process it from the main loop.

Hope this helps.
 
Ok, so like how its done on this page AVR Timers - An Introduction. | eXtreme Electronics ?

Tx!

Well done! :smile:
I think that the tutorial could keep a better time base, but it is just a tutorial. If you want to measure time you should have a better time base. Like if you have 10ms, 100 interrupts means 1 sec.
Please keep in mind that if you need precise time count, then the internal crystal cannot do the job, you need an external one. 32.768KHz is the best you can get from precision point of view, but even an 8MHz external is far better that the internal 8MHz. Finally, if you need the time to keep counting even when system is powered off, then the only solution would be an external Real Time Clock (RTC). Using a small battery or a super cap, time is still running inside this IC even when system power loss is in progress.

Alexandros
 

No, I do not need a very precise clock time, but thanks for the advice!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top