RTC time of day code available?

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
I am using a Xmega processor with the internal RTC that keeps track of time in a 32 bit register. I need to convert that time in a calender format of time and date.
Is there some code available to do that?

Thank You.

Charles :idea:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How do you set the initial time? How do you display it?

What do you mean by "internal RTC"? Do you use an external 32KHz crystal or the internal RC oscillator? If you use the internal RC, you will not be happy with clock accuracy!

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Jim,
The Xmega 128D3 has a built in RTC real time counter which can used an external oscillator. I do use that external oscillator for high accuracy.The time will be set by a keypad and display and also thru a computer connected to the USB port. I am just looking for code available to convert the 32 bits counter to a data/time format.

Thanks,

Charles

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Best bet is probably to use "unixtime" then you can use POSIX time.h library code to convert this into years/months/days/hours/minutes/seconds since 12:00:00 1-1-1970.

Using unixtime has a number of advantages. For example to calculate the time between two dates/times is just uint32_t - uint32_t. Similarly to do alarms is just if(uint32_t == uint32_t).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank You clawson, I will check it out

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Counting and displaying the time is far easier than getting an oscillator accurate enough to tell time. Best off to buy one.

 

"We trained hard... but it seemed that every time we were beginning to form up into a team, we would be reorganized. I was to learn later in life that we tend to meet any new situation by reorganizing. And a wonderful method it can be of creating the illusion of progress while producing confusion, inefficiency and demoralization." Petronius Arbiter, approx. 2000 years ago.