Can I use internal RC oscillator of ATMEGA328PB

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

Hi, 

I am using atmega328pb MCU. 

In our product we were facing some issue because of External crystal oscillator. 

So, we tried the system on internal RC oscillator on 8 MHz. And now the system is working fine.

But my concern is that will it be a good choice for long run?

 

I have used these resources of MCU.

 

 

1. Timer0 at 244 Hz (running continuously, by interrupt) 

2. Timer1 at 1 Hz  (only when required, by interrupt)

3. Timer2 at 50 Hz  (only when required, by interrupt)

4. Timer3 as a delay of 2 sec  (only when required, polling)

5. Timer4 1 sec delay (only when required, by interrupt)

6. UART1 at baud rate 9600

7. All the GPIO are used except 2

8. We are using a serial controled RGB LED (WS2812B) which requires high low signal in a gap of ~400 ns and ~ 800 ns.
which I have provided by _delay_loop_1 function.

9.  Application Hex file size 28 KB and bootloader HEX file size is 5 KB.

And the device will run 24*7 

 

So, can I rely on internal oscillator?

 

Please help us in making the decision. 

Thanks in advance.

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

What is the issue with the external crystal oscillator? Normally, they "just work".

 

The internal oscillator of the 328PB may be more stable and accurate than that of the 328P. But, for UART timing, I would prefer a crystal oscillator.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

In few devices crystal stops working. I checked from oscilloscope it was giving just noise. because of this device stops working.

And in few devices EEPROM value gets corrupted. (when I checked with internal RC oscillator I did not face this problem)

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

imrana326 wrote:
But my concern is that will it be a good choice for long run?
Yes though the internal RC 8MHz oscillator has some temperature drift (given regulated VCC, 1% estimated typical though couldn't locate a max)

imrana326 wrote:
6. UART1 at baud rate 9600

...

So, can I rely on internal oscillator?

Yes though consider adding a SYNC to UARTs' streams.

fyi, megaAVR 0-series has hardware auto-baud (no software for SYNC other than enabling auto-baud)

 

P.S.

imrana326 wrote:
8. We are using a serial controled RGB LED (WS2812B) ...
Well done!  (typically that's in AVR assembly language)

 


AN_2563 AVR054: Run-time calibration of the internal RC oscillator via the UART via ATmega328PB - 8-bit AVR Microcontrollers

ATMEGA4809 - 8-bit Microcontrollers

https://github.com/adafruit/Adafruit_NeoPixel/blob/master/Adafruit_NeoPixel.cpp#L250

 

"Dare to be naïve." - Buckminster Fuller

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

It may work for awhile using the internal RC, but it drifts with changes in VCC level and temperature, so if you project power supply is stable and only used indoors then you may (I said may) be ok with out a xtal.

Is this on a breadboard? or on a PCB?   Bread boards are notorious for bad connections and lots of stray capacitance, which may explain why some worked with xtal and some did not.

 

Jim

 

PS Post a picture of your setup!

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

ka7ehk wrote:

What is the issue with the external crystal oscillator? Normally, they "just work".

 

The internal oscillator of the 328PB may be more stable and accurate than that of the 328P. But, for UART timing, I would prefer a crystal oscillator.

 

Jim

I always set AVR parts to full swing crystal because sometimes low power mode is flakey.

I'm VERY disappointed that the 328pb removes the full swing oscillator option. A new device with more features and possibilities (the 328pb) is ruined for me by the lack of full swing.

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

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

ki0bk wrote:

It may work for awhile using the internal RC, but it drifts with changes in VCC level and temperature, so if you project power supply is stable and only used indoors then you may (I said may) be ok with out a xtal.

Is this on a breadboard? or on a PCB?   Bread boards are notorious for bad connections and lots of stray capacitance, which may explain why some worked with xtal and some did not.

 

Jim

 

PS Post a picture of your setup!

I wonder if a small piece of code could read the AVR temperature and tweak OSCCAL appropriately?

After some careful data acquisition, it should be possible to profile the R/C oscillator vs chip temperature characteristics and generate a correction curve...

(maybe my next project!)

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

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

Krupski wrote:
I wonder if a small piece of code could read the AVR temperature and tweak OSCCAL appropriately?

is a $0.10 xtal worth the effort? My time is better spent solving real world problems.

the newer 0/1AVRs have a better internal clock system, and may cost less then m328pb.

 

jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

ki0bk wrote:

Krupski wrote:
I wonder if a small piece of code could read the AVR temperature and tweak OSCCAL appropriately?

is a $0.10 xtal worth the effort? My time is better spent solving real world problems.

the newer 0/1AVRs have a better internal clock system, and may cost less then m328pb.

 

jim

 

 

I always use a crystal in my projects.  I just thought that a self-correcting R/C clock might be a fun way to waste an afternoon.......

 

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

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

Krupski wrote:
I always set AVR parts to full swing crystal because sometimes low power mode is flakey. I'm VERY disappointed that the 328pb removes the full swing oscillator option. A new device with more features and possibilities (the 328pb) is ruined for me by the lack of full swing.

Just add a 74HC1GU04 and a 1M feedback resistor. Works like a charm. smiley. Yes, a single gate, unbuffered, 1GU04.

I use PB variants with this external clock scheme a lot. Same immunity as the full swing clock in older parts AFAICT. And I did extensive testing on that.

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

As said.... a christal just works.....

When it does not work, then you either damaged it, slim chance. Or you set the wrong fuses, not sure what actually will happen then. Or you have put on the wrong capacitors, big big chance.

Start with 15pf - 18pf, that normally should be fine except when you have chosen the wrong crystal. You need to check the datasheet on that. I am not sure if a low capacitance crystal will do.

 

Another thing might be that you have attached a resonator and then added external capacitors, that gives the same effect as having a capacitance value that is way to high.

 

Have you tried with a simple program that toggles a pin in a loop to see at what frequency you actually are?

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

A practical perspective -

When I was a young fellow, before I wus a enjuneer. I was trying to pay for my first house, for decades I used to do what was called "piece work", did it after coming home from the main job.

That means I used to get paid a fixed price for each successful repair.

The items were portable radio devices such as cordless phones, radio pagers and hand held radios, by the thousands.

Most common fault was crystals, ask anyone who has repaired these kind of devices.

The reason is crystals don't like being dropped, they can be quite fragile.

 

If its a portable device I can see that the use of an RC oscillator might well improve reliability.

 

 

 

 

Last Edited: Tue. Oct 15, 2019 - 07:31 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The reason is crystals don't like being dropped, they are quite fragile.

 

 

Interesting observation from the bench & sounds like that is a good one (at least years ago).

 

The classical quartz crystal oscillator is historically one of the most fragile components in an electronic system. This is not surprising since the quartz crystal resonator within the oscillator was composed of a large crystal such as a large round-blank AT-cut crystal mounted by metal clips inside of a metal housing. This construction could not survive shocks much beyond 50 to 100 g. While these crystal oscillators are superb for large benchtop instruments and similar devices, they are not well suited for applications where the device can expect high shocks such as handheld devices

 

With this modern manufacturing and construction, the quartz crystal resonator is no longer the fragile device that it once was. Today, many manufacturers offer crystals and oscillators that can survive mechanical shocks of thousands of g’s.

 

https://www.electronicproducts.com/Passive_Components/Oscillators_Crystals_Saw_Filters/High-shock_quartz_crystal_oscillators.aspx#targetText=In%20general%2C%20tuning%2Dfork%20crystals,to%20be%20the%20most%20rugged.&targetText=For%20AT%20crystals%2C%20crystals%20in,to%2032%20MHz%20being%20best).

 

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

Still see it in current, modern avionics ramp test sets.
A few manufacturers may offer better but in this day of stingyness expect the cheapest.

Last Edited: Thu. Oct 17, 2019 - 07:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi 

I am also using Atmega328PB with External 8MHZ crystal at 3.3VDC

and I got the same problem 

after that, I shifted my crystal from external to internal 

Islam Bedair

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

Islam Bedair wrote:

I am also using Atmega328PB with External 8MHZ crystal at 3.3VDC and I got the same problem 

after that, I shifted my crystal from external to internal 

 

Whereas I, like many others on here, have thousands of units in the field, all working on crystals without problems.

 

If you design your hardware correctly then you will have no problems.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

Example Layout of ATxmega32A4 and ATmega324PB Devices | AVR® Microcontroller Hardware Design Considerations

...

Note: For ATmega PB devices, the total amount of capacitance must not exceed 22 pF. This includes PCN traces and pin capacitance.

...

 

"Dare to be naïve." - Buckminster Fuller

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

this is my Schematic and PCB

Islam Bedair

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

C1,C2 of crystal are 18pF/50V in my Design 

Islam Bedair

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

Nice board.

 

Make sure you also have AVcc also tied to Vcc !

 

JC

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

DocJC wrote:

Make sure you also have AVcc also tied to Vcc !

 

And use a ground plane.

 

Also, is that a relay? Does it have a diode across it? D4?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

HC49 crystals are popular though the low CL guideline limits what's available.

 

Example Layout of ATxmega32A4 and ATmega324PB Devices | AVR® Microcontroller Hardware Design Considerations

 

edit : resonator

Pololu - A-Star 328PB Micro - 3.3V, 8MHz

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Sat. Sep 5, 2020 - 11:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Set your fuses for the External crystal for 8 megahertz and up. >CKSEL = 111<  This will increase the drive on the crystal and might cure your problems.  If you are using a crappy crystal they might need an extra 'kick' in the pants to keep going.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

imrana326 wrote:

Hi, 

I am using atmega328pb MCU. 

In our product we were facing some issue because of External crystal oscillator. 

So, we tried the system on internal RC oscillator on 8 MHz. And now the system is working fine.

imrana326 wrote:

In few devices crystal stops working. I checked from oscilloscope it was giving just noise. because of this device stops working.

And in few devices EEPROM value gets corrupted. (when I checked with internal RC oscillator I did not face this problem)

this is my Schematic and PCB ...

 

How much shock does this get in operation ?

Is that a relay, right next to the crystal ?!  - what do the contacts switch ? Relay contact noise is famous for disturbing MCUs, tho usually it does not physically kill parts. 

 

Did you try carefully opening a failed crystal unit ?  (did you confirm replace of the xtal restores the system to working ? - ie a changed fuse could look like a xtal failure )

 

imrana326 wrote:
So, can I rely on internal oscillator?

 

Of course. The main issue is accuracy, if what you need to do is ok on RC-precision, it is less parts and less delicate, to use internal RC.

 

 

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

I would use an external xtal osc, like this: https://www.digikey.com/products...

It needs vcc/gnd and connect output to xtal 1 pin, no more problems.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

datasheet said that 

AVCC

AVCC is the supply voltage pin for the A/D Converter, PC[3:0], and PE[3:2]. It should be externally connected to VCC, even if the ADC is not used.

If the ADC is used, it should be connected to VCC through a low-pass filter.

Note that PC[6:4] use digital supply voltage, VCC

 

in my application, I do not use ADC is this correct?

Islam Bedair

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

Islam Bedair wrote:

AVCC is the supply voltage pin for the A/D Converter, PC[3:0], and PE[3:2]. It should be externally connected to VCC, even if the ADC is not used.

 

You are using PC1 for your buzzer are you not? So surely it should be connected?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

AVcc HAS to be connected to Vcc for proper chip operation.

 

If one is using the analog functions on the micro then feeding the AVcc pin through an LC filter will decrease the noise coupled from the Vcc rail into the analog section of the micro.

One then gets a little better performance, noise wise, on the ADC, DAC, AC, etc.

 

For many applications just connecting AVcc to Vcc directly is fine, and then adding a by-pass cap from the AVcc to Ground.

 

JC 

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

It should be externally connected to VCC, even if the ADC is not used.

Is it connected or not???  You remain unclear.  Why would you ever neglect to connect any power pin, regardless? 

 

  • It would be nicer to put U1 & C1 C2 next to the crystal, and keep the relay further away, swap where those parts are.  Not saying it is a problem, but there is always a chance, with the crystal signal being somewhat sensitive. Keeping the relay farther away makes the chance zero.

 

Write a test program to only click the relay on and off (maybe 2 times a second) in a nonstop loop.  With the external xtal being used, look at the relay AVR pin...does the AVR pin signal timing look uniform?  Does the program crash?  If everything is perfect, then you are probably good to go.  

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