Atmega4809 external crystal

Hello there!

I'm working on a home automation project that has modules that need many interrupt pins so I couldn't use mny old best friend, the 328p. I've decided to go with an Atmega4809 this time. Some of the environments can become quite toasty (between around -20/+50 °C) and I'm a bit worried about the internal RC oscillator's stability as the RS485/UART needs precise clocks, so I decided that I will use an external crystal oscillator.

As far as I'm concerned, there is no integrated driver circuitry in the 4809 and I've never used external crystal drivers before so I need some help to get the chip running. How would you recommend to give the chip en external clock? (It's possible that there is an integrated crystal driver, but I missed is)

Thank you for all constructive responses in advance.

Look at the schematic for the Uno WiFi rev. 2

It has a crystal

I am partial to the Kyocera KC5032A line… why? because they’re the only oscillator in the whole damned digikey catalog spec’ed to run from 1.8 all the way up to 5.5V - conveniently, the same range that AVRs run at!

There’s no magic to them, just do the obvious - put the decoupling cap the datasheet recommends right next to them, and keep the high frequency trace short.

That said, I would also want to use either an AVR128DA48 pr AVR128DB48; the former is readily available, and a much spiffier part (it’s supported my my DxCore) - the silicon came out just in April of this year. Still lacks external HF crystal support… but you can put a watch crystal on it and enable their “autotune” feature, and it will use the watch crystal as a frequency reference. Works pretty well - I tried hitting one of mine with freeze spray, with and without autotune enabled, like, it works? That said, the temperature dependence of the internal oscillator isn’t that big - look at the datasheet typical characteristics! The AVR128DB FINALLY brings support for external crystal to the modern AVRs; they’re still a little hard to get your hands on in the 48-pin package, but I was able to score some about a week ago from Microchip Direct (they dropped the “order in multiples of” parameter from a tray of several hundred down to 5 like normal products :stuck_out_tongue: )… the headline features of the DB-series are that they’ve got on-chip opamps that you can configure programatically (you probably don’t care - I can’t say I do, even though it is cute), and MVIO - if you enable it in the fuses (DxCore lets you do it with tools submenu and ‘burn bootloader’), the voltage supplied to the power pin in the middle of PORTC is separate from Vcc, and all of PORTC runs at that voltage instead of Vcc (ie, if you have 3.3v stuff, you put it all on PORTC, and put 3.3v into that “VDDIO” pin, and don’t need any level shifting or nothin). Besides those epic additions, the DB-series is a DA-series. It’s got the same modern peripherals as a 0-series atmega, but you get an extra TCA (so 6 more PWM pins), a wacky type D async timer, and the TCBs can team up to do 32-bit input capture if you need that for some weird reason?

It is interesting that Microchip keep bringing out freshened up 8 bit general purpose micro controllers. Whereas I am always curious about these new things, and am amazed at the new peripherals that these keep getting adorned with, the amount of time I am prepared to spend getting familiar with a new set of data sheets is diminishing. Anyway, as soon as you start needing maths functions or precision floating point arithmetic, the basic limitations of 8 bit start to show, so my next major investment in time will probably be with 32bit architecture.

Just back to the OP’s problem for a moment, I guess he has realized that pin change interrupts can be configured on just about every pin of the ATmega328p.

6v6gt:
Just back to the OP’s problem for a moment, I guess he has realized that pin change interrupts can be configured on just about every pin of the ATmega328p.

Indeed, pin can be interrupt can be configured but not individually per pin, but rather per I/O port

DrAzzy:
Still lacks external HF crystal support… but you can put a watch crystal on it and enable their “autotune” feature, and it will use the watch crystal as a frequency reference. Works pretty well - I tried hitting one of mine with freeze spray, with and without autotune enabled, like, it works? That said, the temperature dependence of the internal oscillator isn’t that big - look at the datasheet typical characteristics!

So you’re telling that I can attach the 32KHz crystal and tell it to calibrate its internal system clock using the 32KHz signal? That would be great as I have an external I2C RTC that has a temperature - and literally everything - compensated output that can be configured to output the crystal frequency.
If you can, please give me a page number in datasheet where I can find the related info.

ferihun:
Indeed, pin can be interrupt can be configured but not individually per pin, but rather per I/O port

I’m not sure I understand your particular use case.
You can set a mask to determine which individual pins can trigger the port ISR.
In the ISR, you can discover which pin(s) caused the interrupt and react accordingly.

As far as I'm concerned, there is no integrated driver circuitry in the 4809 and I've never used external crystal drivers before so I need some help to get the chip running. How would you recommend to give the chip en external clock? (It's possible that there is an integrated crystal driver, but I missed is)

External clocks are supported by MegaCoreX. The crystal driver circuit shown below works excellent!

6v6gt:
I’m not sure I understand your particular use case.
You can set a mask to determine which individual pins can trigger the port ISR.
In the ISR, you can discover which pin(s) caused the interrupt and react accordingly.

Of course, but if multiple changes occur, Then I have to address them all in the same interrupt routine. If I use individual interrupts, I can solve it with 5-6line subroutines. No branching, just a fixed routine.

hansibull:
External clocks are supported by MegaCoreX. The crystal driver circuit shown below works excellent!

Can you recommend a particular IC - or any guideline to choosing - to use with the crystal? As it tells me the one that makes the crystal oscillate, shouldn't be a Schmitt trigger.

Can you recommend a particular IC - or any guideline to choosing - to use with the crystal? As it tells me the one that makes the crystal oscillate, shouldn't be a Schmitt trigger.

The part number is right there in the schematic. The 74HC04 will work.

hansibull:
The part number is right there in the schematic. The 74HC04 will work.

I see. missed first time. Now I only look for some SMD alternative and I think I'm done with the circuitry of this project :smiley:

ferihun:
So you're telling that I can attach the 32KHz crystal and tell it to calibrate its internal system clock using the 32KHz signal? That would be great as I have an external I2C RTC that has a temperature - and literally everything - compensated output that can be configured to output the crystal frequency.
If you can, please give me a page number in datasheet where I can find the related info.

On the AVR Dx-series parts only (that was what that paragraph was talking about - I was promoting them as a more heavily featured option compared to megaAVR 0-series.) Section 11.3.5 of AVR128DA datasheet, under CLKCTRL->Functional Description->Auto-Tune - it's dead simple to use on parts that have it - you just enable a crystal or external 32.768 kHz clock source and set the AUTOTUNE bit in the appropriate register and you're done!
It's not available on tinyAVR 0/1/2-series or megaAVR 0-series; with some effort, you can do that yourself - I went through most of the mechanics of this, though I was using it to measure the clock speed of each cal value against the crystal in order to determine the range of possible speeds the internal oscillator can generate (it's HUGE! On the two tinyAVR parts I tested, the 16 MHz oscillator ranged from under 10 MHz to over 24 MHz, and the 20 MHz one from under 12.5 MHz to over 30 MHz. As is the tradition in the AVR world, the compliance of the internal oscillator is vastly understated in the datasheet - they spec +/- 1.5 MHz; in reality, it looks like it can be adjusted from approximately 5/8ths of the nominal speed to 1.5x the nominal speed. Among other things, this means that both oscillators can be calibrated to generate a clock fairly close to either 16 or 20 MHz :stuck_out_tongue: )