Atmega4808 as a real time clock?

Hello, From a firmware stand point. Can I use the atmega4808 as a real time clock with a 32khz crystal even If it has a 20mhz oscillator build in? And If so Which pins can I use for the crystal ? Also Which code Would work on this processor? Sense it is not a normal Atega328.

Joseph

Dubious at best. I assume you've checked the data sheet and found an RTC peripheral device in the 4808? The "Blue Pill" has something like that, so a 32kHz crystal circuit is present on the board, but the same conductors also go to I/O pins on the board. A 32kHz oscillator is far too sensitive to permit that, but they do it anyway. I always omit the oscillator connected pins when I solder the pin headers to a Blue Pill for that reason. Even if they go to pads, at least it doesn't get off the board. But throwing a crystal on some I/O pins, I would think, is not a very safe way to lay out an oscillator circuit. So I think unless some provision is made on board (you didn't say whether Arduino or custom board), not a great idea.

The concept is good, at least - I have a homebrew desk clock based on that idea. It uses the internal RTC of the STM32F103C8 (Blue Pill) and the clock frequency compensation hardware that is part of the RTC subsystem. With that, the crystal frequency can remain a little high or low, and the hardware will automatically adjust it by a calibration value that I program into it. I obtain the calibration value by running a calibration sketch while it is connected to a reliable GPS PPS source. It takes about 10 minutes. With the calibration, and no temperature compensation, it has still remained +/- 20 seconds per 6 months or so. That is pretty good for a non-IC RTC solution.

Hello aarg, My arduino 328p uno clock clock project in the past I did has in place of the 16mhz crystal it is a 32khz with 2 caps on it and also uses the internal 8mhz for the processor fubctions. So far it has been workinout great. I only lose 2 Seconds per year so far. I'm trying to make my friend a clock as well. But I have no more 328p processors or any other processors due to shortage. However I do have 5 of the 4808 processors. I'm just trying to build him a clock that's all.

Joseph

I'm looking into getting a RTC module but for now I don't have that much money for one.

Joseph

Well it would be interesting to know how you ran the 8MHz and 32kHz clocks in tandem, as the 328 has no internal counter for the 32kHz osc. The STM32F103 has independent clock chains for each, and a dedicated counter for the low power osc, so it requires little thought really.

If you did that, you are the expert and you should be telling other people how to do it. :slight_smile:

A quick scan of the 4808 data sheet tells me, you can configure the 32MHz osc to run independently (alongside a high frequency crystal source for the CPU), feeding an interrupt prescaler. So you could have it generate fairly accurate time via interrupts. But the difference between that and the STM32, is that there seems to be no provision for stand alone low power operation when the processor power is removed, nor any backup power source or timer to keep track of time while it's powered down.

The interrupt responses that you would need to continue tracking time, would not be active while the processor is powered down. There might be sleep/wakeup options for that, though...

So on every 32kHz driven periodic interrupt, you would wake up and increment your seconds count, go back to sleep.

If you are just leaving it on all the time, not much point in using a 32kHz source, since 8/16MHz crystals that are just as accurate (or can be calibrated to be so) are common.

In one of my other post someone told me how to do that. I can’t not remember which one. I need to go on my laptop and see. It was just recently I think

Joseph

Here it is.

https://forum.arduino.cc/t/smallest-real-time-clock/910291/10

So my Question is What pins would I need to make this work? I know which ones on the 328p, But on the 4808 I'm unsure.

Joseph

You can find the information you're looking for in the datasheet. I've used the datasheet found here http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega4808-4809-Data-Sheet-DS40002173A.pdf

The signals we're interested in is described in the Real Time Counter chapter, page 255.

Then we lookup the signal pins in the multiplexed signals table on page 18.

So the pins you're looking for is PF0 and PF1.

Hello nicolajna, Thsank you very much. Now all I have to figure out is what Capacitor would i need?

Joseph

The crystal specification states the total load capacitance required, which will include stray capacitance in the wiring or PCB.

Thank you all for the help. I'm looking to add a crystal to it. I will do a follow up shortly.

Joseph

You're welcome.