Yep, with coding and utilizing the timer interrupt, one can do an RTC with ATMEGA8, but, reading the ATMEGA8 user guide, I can’t find discussion on RTC. It it takes lot of coding to support RTC and calendar, I am thinking of just getting the DS1307 RTC chip–about 70 cents and it offers many features.
My question: Would it take a lot of programming to do a simple RTC with ATMEGA8? In other words, ATMEGA8 does not support it out of the box?
It’s not impossible. Probably the best you could hope for is to set the 1024 divider and then manually figure out how many counts per unit time you end up with. 32768 is a somewhat arbitrary value only made popular by the fact that it’s used as a clock source in digital watches. If you need accuracy over a long time frame, say more than a few seconds, look for crystals that have tighter tolerances.
It’s not arbitrary at all, it makes time-keeping very simple. With a 32.768kHz clock, all you need to do is increment a 16-bit counter each tick. Then, when it overflows, reset it to 1 and 1 full second has passed.
mkissin:
It’s not arbitrary at all, it makes time-keeping very simple. With a 32.768kHz clock, all you need to do is increment a 16-bit counter each tick. Then, when it overflows, reset it to 1 and 1 full second has passed.
I said somewhat arbitrary. It’s not an absolute. You can count time in any other relative unit and still get the same or similar results. Whether or not it’s more work is another issue. The point being, you don’t lose out on having time keeping abilities if you clock it with something else.
the usual rationale for an external clock chip is that the microprocessor lacks a built-in oscillator that can run on battery power when the main microprocessor is off or sleeping.
Most newer chips have that 2nd oscillator and it’s intended to use a 32KHz crystal. However, comma, an external clock chip is easier and it has a calendar and so on built in. The amount of code to talk to this chip is about the same as to do your own time/calendar. The messy part is leap year, leap second, leap day, and so on. If you care. I don’t think most clock chips deal with this either. Hence hooking WWV or GPS up or connecting to an Internet time server. Depends on how automated you wanna be.