Author Topic: AVR Port settings when using an external Oscillator ?  (Read 1511 times)

0 Members and 1 Guest are viewing this topic.

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1795
  • Country: ca
AVR Port settings when using an external Oscillator ?
« on: January 10, 2025, 01:48:50 pm »
I'm using an ATtiny44A, and I know to change to an EXT XTAL, I need to change the CKSEL fuse bits, and consider the SUT start-up times.

XTAL1 is the input pin, and XTAL2 is the output pin, but do I have to set that up in the DDR and PORT register's, or is that automatically done when changing to the EXT OSC source ? Can those DDR/PORT bits for XTAL1/2 still be changed afterwards, or is it locked, and it doesn't matter?

Sometimes, I might want to clear a whole 8-bit port register at once, and I'm just wondering if that could break the EXT OSC settings.
 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 15203
  • Country: de
Re: AVR Port settings when using an external Oscillator ?
« Reply #1 on: January 10, 2025, 02:07:21 pm »
The DDR register settings should have not effect for the XTAL1 pin. It can have an effect for the XTAL2 output pint, that is normally not used with an external oscillator. The XTAL2 pin may be available as an extra IO pin, not just clock out.

 

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1795
  • Country: ca
Re: AVR Port settings when using an external Oscillator ?
« Reply #2 on: January 10, 2025, 07:17:50 pm »
Well this is for the inverting amp between the XTAL1/2 pins, and the crystal is in the feedback path. But in the datasheet, I don't see any warning, or note saying what happens if you were to use OUT to send full byte in a REG, to the DDRB or PORTB in this case.

Of the other PortB pins, I'm only using 1 of them, so I shouldn't have to worry about those DDRB, PORTB bits. But in other chips, I may want to use OUT, and then would I set those bits to 0 or 1 ?

IDK, I'm about to solder up the crystal, so I'll try a little program and see what happens. I also want to see how long it takes the OSC to stabilize.

I had wanted to use a deep-sleep state, and wake-up in a few cycles like from the internal OSC. But to my dismay, if the EXT OSC it restarted, it takes at least 258cycles to wakeup, and then they recommend a stabilization time of mili-seconds.
 

Online PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 2123
  • Country: au
Re: AVR Port settings when using an external Oscillator ?
« Reply #3 on: January 10, 2025, 08:44:51 pm »
IDK, I'm about to solder up the crystal, so I'll try a little program and see what happens. I also want to see how long it takes the OSC to stabilize.

I had wanted to use a deep-sleep state, and wake-up in a few cycles like from the internal OSC. But to my dismay, if the EXT OSC it restarted, it takes at least 258cycles to wakeup, and then they recommend a stabilization time of mili-seconds.
Yes, external crystals can take millisecond region times to start. Ceramic Resonators are somewhat faster, but less accurate.
eg'
https://www.murata.com/en-global/support/faqs/timingdevice/ceralock/char/cch0003

How accurate does your clock need to be ?

If you enable a CLKOUT to a pin, you can check the start times without disturbing the crystal nodes.
 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 15203
  • Country: de
Re: AVR Port settings when using an external Oscillator ?
« Reply #4 on: January 10, 2025, 10:20:23 pm »
An external cystal and external oscillator are different things. If the fuses are set to external oscillator it would not work with just a crystal and the µC would be blocked until a clock is applied.
The external oscillator are those packages with 3 or 4 pins, that also need power.
 

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1795
  • Country: ca
Re: AVR Port settings when using an external Oscillator ?
« Reply #5 on: January 11, 2025, 04:41:30 am »
Right MCU circuit with the external 2-pin crystal, that whole circuit is the oscillator, yeah I'm mixing that up.
 

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1795
  • Country: ca
Re: AVR Port settings when using an external Oscillator ?
« Reply #6 on: January 22, 2025, 09:24:27 am »
On a through-hole proto-board, I have an ATtiny44A (from ebay) running off a 12MHz crystal, with two 15 or 18pF non-NPO caps. And the trace lengths for those XTAL pins aren't the same, and I'm using a standard length ground clip. There's only a 100nF cap, on the 5V rail. There's only a single GND trace on the board, and it's not a loop.

And just looking at the MCU turn on/off some LED's, w/ only about 6mA each, it puts some higher frequency ripple onto the attiny's XTAL output pin.

So how typical does this look ? 12MHz is not that high, so IDK how much the poor PCB and probe setup, leads to this ripple on the scope. But I'm running the MCU at 1:1, so I'm guessing it's not good if you have all this extra noise on there.
 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 15203
  • Country: de
Re: AVR Port settings when using an external Oscillator ?
« Reply #7 on: January 22, 2025, 10:24:35 am »
The crystal signal is very sensitive to loading. Just probing with the scope can stop the oscillator and change the frequency / amplitude quite a bit.
It is also easy to pick up capacitive coupled other signals.
Usually the crystal at the AVRs works OK, though the frequency is not super stable. So for something like a frequency counter I would prefer a separate canned oscillator.
 

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1795
  • Country: ca
Re: AVR Port settings when using an external Oscillator ?
« Reply #8 on: January 23, 2025, 04:00:29 am »
Ok so don't worry about it too much then. I've made BJT oscillators with crystals before, I should add a changing load circuit and see what effect it has them.

I made some low capacitance JFET probe last year, I should try it.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf