Clarification required for the ATmega32U4's documentation with regards to oscillators

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

I would like some clarification on some of the ATmega32U4's specs and the terminology used in its data sheet. I'm specifically interested in oscillators.

 

NOTE: Although I have experience with electronics and microcontrollers, I still consider myself just a hobbyist, so feel free to point me to documentation that can help me learn and grasp the basic concepts better. Also feel free to correct my use of terminology, etc..

 

This article explains why someone would want to use an external oscillator instead of the internal oscillator. The main reasons are an external oscillator will generally have better accuracy and frequency stability.

 

I assume when people refer to an "external oscillator" they are talking about a crystal oscillator, ceramic resonator, or oscillator module. Is that correct?

I assume when people refer to the "internal oscillator" they are talking about the microcontroller's internal RC oscillator. Is that correct?

There are two pins - XTAL1 and XTAL2 - that deal with the microcontroller's use of oscillators.

I assume "XTAL" is an industry term for "crystal". Is that correct? Does that mean the pins can only use crystal oscillators for input? Or can I also use a resonator, oscillator module, or just a generic square wave from "some clock source" as input to XTAL?
 

Based on Figure 6-6 - attached - in the data sheet, I assume I can use an external clock source or the internal oscillator to drive the microcontroller. I just have to set the correct fuses to make sure I select my clock source properly. Is that correct?

Is the component labeled "RC OSCILLATOR 8 MHz" in Figure 6-6 the microcontroller's internal oscillator?

 

Section 33.2 in the data sheet says that the ATmega32U4-MU and ATmega32U4RC-MU "are shipped with no USB bootloader pre-programmed". Yet the Features section of the data sheet mentions "Parts using external XTAL clock are pre-programed with a default USB bootloader". Is that an error in the data sheet?

 

Section 33.2 in the data sheet mentions application note AVR291 with regards to the ATmega32U4-MU and ATmega32U4RC-MU. Yet the application note says it only applies to the ATmega32U4RC-AU and ATmega32U4RC-MU. The application note deals with tuning/calibrating the internal oscillator for low-speed USB operation. Is that an error in the data sheet?

 

Sections 6.2.1 and 6.2.2 in the data sheet mention:

  • The ATmega32U4 "is shipped with Low Power Crystal Oscillator (8.0 - 16MHz) enabled and with the fuse CKDIV8 programmed, resulting in 1.0MHz system clock with an 8MHz crystal".
  • The ATmega32U4RC "is shipped with Calibrated Internal RC oscillator (8.0MHz) enabled and with the fuse CKDIV8 programmed, resulting in 1.0MHz system clock".

What is the difference between these two internal oscillators?

Can the ATmegaU4's (non-RC variants) internal oscillator be set to run at 16 MHz?

 

Based on the research I've done, here are my assumptions:

  • All ATmega32U4's come with an internal 8 MHz internal RC oscillator. The fuses are factory-set to divide the clock down to 1 MHz. The ATmega32U4RC's internal oscillator is specially calibrated for better accuracy.
  • All ATmega32U4's can be optionally driven by an external oscillator (e.g. such as a crystal oscillator).
  • As long as the proper fuses are set, the user can choose to drive their microcontroller either from an external oscillator or the internal oscillator - for any variant of the microcontroller.

 

Are my assumptions correct? Please correct me, if I'm wrong.

Attachment(s): 

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

Atmel sort of screwed up its terminology , just to cause mass confusion.

 

A crystal (xtal) has two essential leads & by itself does nothing....it requires a circuit of some sort (often inside the AVR) to produce a very precise & stable frequency signal. 

Before China came along, decent xtals used to be somewhat expensive, so ceramic resonators stepped in...somewhat roughly a "cousin", they were a lot cheaper, with limitations in accuracy & temperature stability.  

 

An oscillator is an entire circuit that requires power and produces a clock signal (frequency) that can be applied to other circuits.  

An oscillator example is an AVR internal RC oscillator that is rather poor, but "good enough" for  many things where you don't need a very exact freq (do you care if your led blinks 3 times a sec or 3.01 times a sec?)

You can buy precise crystal oscillator modules (say 10 MHz) , that requires power & output a very precise clock signal (to an AVR external clock input pin). 

 

Unfortunately, just to make things confusing, Atmel will call a plain crystal, a crystal oscillator.  Technically that is correct, yet it muddles the water when trying to discern between making settings for an oscillator or settings for a plain old crystal

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Tue. Aug 17, 2021 - 01:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


 

MaxJ345 wrote:
I assume when people refer to an "external oscillator" they are talking about a crystal oscillator, ceramic resonator, or oscillator module. Is that correct?

See Tip #4 in my signature, below.

 

A ceramic resonator - like a crystal - is just a passive component; it will not oscillate on its own

 

MaxJ345 wrote:
I assume when people refer to the "internal oscillator" they are talking about the microcontroller's internal RC oscillator. Is that correct?

Note that there are (at least) two "oscillator" circuits within the AVR chip:

  1. The RC oscillator, as mentioned: this is a complete oscillator including the (RC) resonant components;
  2. The crystal oscillator: this is just the active electronics - the resonant element (crystal or ceramic resonator) must be added externally.

 

MaxJ345 wrote:
There are two pins - XTAL1 and XTAL2 - that deal with the microcontroller's use of oscillators.

Those are the pins to which you attach the two terminals of the external crystal or ceramic resonator:

 

 

If you are using an external oscillator (or other external clock source), that is applied to just XTAL1:

 

 

MaxJ345 wrote:
I assume "XTAL" is an industry term for "crystal". Is that correct?

Yes.

 

Does that mean the pins can only use crystal oscillators for input? Or can I also use a resonator, oscillator module, or just a generic square wave from "some clock source" as input to XTAL?

 

See above

 

Based on Figure 6-6 - attached - in the data sheet

It's easier if you put the image in the post, where we can see it:

 

 

See Tip #1 for how to do that.

 

Is the component labeled "RC OSCILLATOR 8 MHz" in Figure 6-6 the microcontroller's internal oscillator?

See above. 

 

 

EDIT

 

Extended the 1st datasheet screenshot to include the start of the 6.3 "Low Power Crystal Oscillator" section.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Aug 17, 2021 - 10:00 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it's a 32U4 you have presumably chosen it for the USB? If so then your clocking choices reduce dramatically. To get to the 48MHz that is divided down to get USB's 12MHz the 32U4 (when USB is to be used) can only be clocked by either an 8MHz crystal (that is multiplied by 6 to get to 48) or a 16MHz crystal (that is multiplied by 3 to get to 48).

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

avrcandies wrote:

Atmel sort of screwed up its terminology , just to cause mass confusion.

 

A crystal (xtal) has two essential leads & by itself does nothing....it requires a circuit of some sort (often inside the AVR) to produce a very precise & stable frequency signal. 

Before China came along, decent xtals used to be somewhat expensive, so ceramic resonators stepped in...somewhat roughly a "cousin", they were a lot cheaper, with limitations in accuracy & temperature stability.  

 

An oscillator is an entire circuit that requires power and produces a clock signal (frequency) that can be applied to other circuits.  

An oscillator example is an AVR internal RC oscillator that is rather poor, but "good enough" for  many things where you don't need a very exact freq (do you care if your led blinks 3 times a sec or 3.01 times a sec?)

You can buy precise crystal oscillator modules (say 10 MHz) , that requires power & output a very precise clock signal (to an AVR external clock input pin). 

 

Unfortunately, just to make things confusing, Atmel will call a plain crystal, a crystal oscillator.  Technically that is correct, yet it muddles the water when trying to discern between making settings for an oscillator or settings for a plain old crystal

So a crystal and a crystal oscillator are technically two different things - with the former requiring a frequency source. Is that correct?

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

MaxJ345 wrote:
So a crystal and a crystal oscillator are technically two different things - with the former requiring a frequency source. Is that correct?

A crystal is a passive element of a crystal oscillator.

A crystal oscillator is a circuit whose frequency output is controlled by the xtal.

An xtal oscillator can be internal (ie. built into the micro) but requires an external passive component (xtal or resonator) to set the operating frequency.

OR an external component that requires power and provides an output that can feed the xtal input pin with a clock signal.

OR an internal RC oscillator whose frequency is determined by the internal R and C components, and just to add one more some of the older atmegas, also had an internal oscillator that could use external RC components to set the frequency of operation.....

 

Does that help?

 

Jim

Edit added internal RC Osc.

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

Lets go Brandon!

Last Edited: Tue. Aug 17, 2021 - 02:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Note that there are (at least) two "oscillator" circuits within the AVR chip:

  1. The RC oscillator, as mentioned: this is a complete oscillator including the (RC) resonant components;
  2. The crystal oscillator: this is just the active electronics - the resonant element (crystal or ceramic resonator) must be added externally.

 

So I can either use the internal RC oscillator or I can use the internal crystal oscillator as long as I complete the circuit by introducing the resonant element (crystal or ceramic resonator) externally.

Is this a correct interpretation?

 

awneil wrote:

If you are using an external oscillator (or other external clock source), that is applied to just XTAL1:

 

 

Can external clock signal can be anything (e.g. output from a waveform generator, the clock line from another device, etc.)?

 

awneil wrote:

It's easier if you put the image in the post, where we can see it:

 

...

 

See Tip #1 for how to do that.

 

The problem was I tried with the Add Media button. I didn't know I could paste directly into the editor. Good to know!

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

MaxJ345 wrote:
Can external clock signal can be anything (e.g. output from a waveform generator, the clock line from another device, etc.)?

As long as it meets the DS specifications for clock input, yes!   i.e. you can set a fuse bit on some AVRs to provide a clock output signal and feed that to another AVR(xtal1 pin), or any other circuit that needs a clock.

 

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

Lets go Brandon!

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

clawson wrote:

If it's a 32U4 you have presumably chosen it for the USB? If so then your clocking choices reduce dramatically. To get to the 48MHz that is divided down to get USB's 12MHz the 32U4 (when USB is to be used) can only be clocked by either an 8MHz crystal (that is multiplied by 6 to get to 48) or a 16MHz crystal (that is multiplied by 3 to get to 48).

 

Yes, I did choose the ATmega32U4 for its USB functionality, but the project is going to be a wired keyboard. I don't believe I'll be needing high-speed USB - low-speed USB should be fine.

 

Section 21.4 in the data sheet says:

 

"To reduce external components count and BOM cost, the USB module can be configured to operate in low-speed mode with internal RC oscillator as input source clock for the PLL. The internal RC oscillator is factory calibrated to satisfy the USB low speed frequency accuracy within the 0°C and +40°C temperature range. For USB full-speed operation only external crystal oscillator or external source clock can be used."

 

So I should be able to operate without a crystal for my application.

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

ki0bk wrote:

MaxJ345 wrote:
So a crystal and a crystal oscillator are technically two different things - with the former requiring a frequency source. Is that correct?

A crystal is a passive element of a crystal oscillator.

A crystal oscillator is a circuit whose frequency output is controlled by the xtal.

An xtal oscillator can be internal (ie. built into the micro) but requires an external passive component (xtal or resonator) to set the operating frequency.

OR an external component that requires power and provides an output that can feed the xtal input pin with a clock signal.

OR an internal RC oscillator whose frequency is determined by the internal R and C components, and just to add one more some of the older atmegas, also had an internal oscillator that could use external RC components to set the frequency of operation.....

 

Does that help?

 

Jim

Edit added internal RC Osc.

 

Yes that helps with reinforcing my new understanding of the microcontroller's internals!

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

ki0bk wrote:
the DS specifications for clock input, yes

 

Thank you for the clarification!

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

MaxJ345 wrote:
So I should be able to operate without a crystal for my application.

That's how I read it.  check out the LUFA project for working USB stack code. 

Good luck.

 

Jim

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

Lets go Brandon!

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

To reduce external components count and BOM cost, the USB module can be configured to operate in low-speed mode with internal RC oscillator   So I should be able to operate without a crystal for my application.

To be clear, even the cheapest garbage xtal will be far far better than the internal osc and for 12 cents (you can buy 10 for $1.20) give you 30 parts per million accuracy (11999640 to 12000360 Hz).  So what's the question?  Do you have 15 cents?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

ki0bk wrote:

MaxJ345 wrote:
So I should be able to operate without a crystal for my application.

That's how I read it.  check out the LUFA project for working USB stack code. 

Good luck.

 

Jim

 

 

Good to know. Thank you!

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

avrcandies wrote:

To reduce external components count and BOM cost, the USB module can be configured to operate in low-speed mode with internal RC oscillator   So I should be able to operate without a crystal for my application.

To be clear, even the cheapest garbage xtal will be far far better than the internal osc and for 12 cents (you can buy 10 for $1.20) give you 30 parts per million accuracy (11999640 to 12000360 Hz).  So what's the question?  Do you have 15 cents?

 

It has nothing to do with the price. I've built circuits using external crystals before - but that was without knowing why they were necessary or how they worked.

 

This thread's purpose is for me to gain a better understanding of the internals of the microcontroller, and the options available for driving the microcontroller.

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

Bottom line. If you are doing anything that requires timing accuracy (UART, RTC, USB etc) then use an accurate timing source. 

 

Sure some chips have enough of a clock to get something going but if you want reliability/accuracy pick the right components for the job.

 

I wonder exactly how accurate even low speed USB is going to be using any kind of int-RC or are you riding on the edge of some calibration range?

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


I've seen prices, even at a low quantity for one penny...at that price there is barely any debate (unless you are out of pins, or perhaps space is at an extreme premium).

Of course, they will stick it to you for shipping, but then just buy 25000 of them  crying

 

To reduce external components count and BOM cost, the USB module can be configured to operate in low-speed mode with internal RC oscillator ...so now you know both sides of the possibilities.

It is great that you are taking the time to investigate the tradeoffs...too many simply use the internal RC and end up very frustrated when things don't work on 10% of their builds.  It is very hard to go wrong using an external xtal.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!