Date and time for atmega

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

hey,
i want to work with real world time, in date and time.
so please suggest a way, i am working with atmega16.
i suppose that to create a clock in code, would be tiresome, so is there some other IC for this purpose.

thank you for any help.

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

there are an awful lot of external chips that can do it.
Not sure on the M16, but if it has the ability to also have a 32KHz crystal attached to a special timer input, you should also be able to make the clock with not to much effort in FW.
A search of the forum for real time clock or real time timer should give a long list of threads discussing this already.

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

FW?

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

what is wrong with making that yourself?

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

Quote:

FW?

FW=Firmware - is the code you write and put into the AVR.

It's pretty trivial to write:

ISR(TIMER_vect) {
  ms_tick += 50; // called here every 50ms
  if (ms_tick >= 1000) {
    ms_tick = 0;
    seconds++;
    if (seconds >=60) {
      seconds = 0;
      minutes++;
      if (minutes >=60) {
         minutes = 0;
        hours++;
.. etc.
      }
    }
  }
}

Actually what most people may/would do is simply have the ISR tick up a uint32_t that counts seconds since 1st Jan 1970 (it's a bit of standard!) and then later on decode that count into yy/mm/dd hh:mm:ss to work out "time now".

Or you can add an external chip like a DS1307. You just set its yy/mm/dd/ hh:mm:ss registers once then as long as power is applied it just keeps time and at any stage you can go back and read all those registers.

This latter option may be easier but it adds about $1 to the cost of your chips.

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

Take a look at Lady Ada's Ice Tube Clock for ideas: http://www.adafruit.com/products/194#Description.

Schematic & firmware can be found here: http://learn.adafruit.com/ice-tube-clock-kit/downloads.

Note that this project uses an ATmeg168, not an ATmega16 but it should be helpful.

OBTW: I have one of these and it keeps pretty good time and has battery backup.

Don