Internal oscillator 328P how 'inaccurate' is it?

So I have my 328P running the calibrated internal oscillator (no external crystal or resonator). The datasheet indicates the internal is not designed for high accuracy. So how inaccurate are we talking about here?

My chip is running a game timer. Can I expect to see timing errors in the range of seconds, minutes or just a few millis in a 30 minute game?

Have you tuned the oscillator?

Page 304 quotes +/-10% for the '328p, which is terribad - but that's over the full temp range specified, while you're likely to be running it at room temperature.

Some of the other AVR chips spec 2%, or 2% w/in narrow temp range, 10% w/in full temp range.

It also says that user calibration via the OSCCAL register can narrow the error to ±1% over the whole temperature range. Even allowing for a narrower range it still sounds like the error would be on the order of seconds per 30 minutes. But I have not tried it, not yet anyway.

This application could be exposed to anything from -15 to 30+ Celsius so the I expect there to be some effects. The calibration is set to 0x9A which in the data sheet is listed as a reserved address. Any idea what that setting is giving me for a clock frequency?

The 0x9A clock calibration setting refers to the tuned value correct? To get the best internal accuracy the clock calibration should be set to match the system voltage, if I'm reading this right. If I'm interpolating correctly then my internal oscillator should be set to 7.99 MHz for the 5V rail. Is this correct?

The calibration is set to 0x9A which in the data sheet is listed as a reserved address. Any idea what that setting is giving me for a clock frequency?

Huh? What do you mean the value is a reserved address?

It's in the data sheet. At system reset a default value is loaded into the OSSCAL register which gives you 8MHz ± 10%. You can reprogram the register to tweak the frequency and get better accuracy. There are charts in the data sheet that show the relationship between the OSSCAL value and the frequency, as well as the temperature dependence. But if it were me I'd want to measure the clock frequency, either with an oscilloscope or by comparing the output of a counter against a stopwatch over some period of time.

I suppose it would be possible to continually tweak the value based on temperature and voltage measurements. I don't know how well that would work. At some point it's easier to buy a crystal.

Huh? What do you mean the value is a reserved address?

Sorry, this is my first foray into the chip settings. When I search the data sheet the only reference I find for 0x9A is a page that shows it as a reserved address.

I had a crystal on the chip but the audio (tone) output of this chip is getting sent to a siren through a 5W amplifier. I was getting an artifact from the crystal that could be heard in the amplifier output. Running on the 8MHz internal I get none of that.

I’ll look for the charts.

Ahh. I see the chart you mean. (ATmega328P: Calibrated 8 MHz RC Oscillator Frequency vs. OSCCAL Value).

So, the 0x9A (154 DEC) at 8MHZ plots outside the charts best range. The 8MHZ line intersects the curve at 184 or 0xB8. Am I interpreting that correctly?

Is it as simple as putting OSCCAL = 154; in Setup()?

Is it as simple as putting OSCCAL = 154; in Setup()?


But with the value you may have to experiment to get good results.

You could also take a look what the OSCCAL of your individual 328P is at the moment like

void setup() 

Excellent. Thanks, I’ll do that.

The OSCCAL loaded at reset is one that is programmed at the factory to yield the specification in the datasheet (~10% at some particular operating voltage, IIRC.)
You can fine-tune the value for your particular operating conditions, and/or a slightly different frequency, by loading a different value into OSCCAL, but you probably have to determine the value experimentally - it’s not something you can just read off the graph in the datasheet - if the datasheet were exact, they’d just program OSCCAL to have the exactly correct value.

There are some tools that you can use to find more accurate values, assuming that you have an accurate thing to measure them. Google “osccal calibration clock arduino” and there are lots of results…

Yes I see your point. Just referencing the graph is not going to do it. I'll do some testing. The accuracy may be enough as is.

I've had an experience with inaccuracy of an internal oscillator, not with a 328p but with a 1284p. When I was using the serial peripheral, I was getting garbage output. I thought the serial peripheral was fried from a wiring mistake. I then decided to switch over to an external crystal and the serial worked fine, which pointed to the internal oscillator being problematic. I then used PWM on one of the pins to get a frequency low enough that could be measured my my multimeter's frequency measurement function. Turned out, it was off a bit.

I then hooked up the external crystal (and of course made the necessary changes to the fuses) and read the factory programmed OSCCAL value to give me a starting point. I then switched back to the internal oscillator and experimented until I found an OSCCAL value that got me as close as I could get to 8 MHz. After that, the serial peripheral worked off of the internal oscillator just fine.

What voltage is the 1284P running at? There was a topic last summer where a 16 MHz unit running at low voltage also had serial issues. I think with a crystal.
Speed Grades chart in 28.2, Figure 28-1, looks to have same speeds & voltage as 328P, so below ~3.8V running at 16 MHz is out of spec.

The 1284P is running at 5V.

According to the spec the 8MHz internal osc is calibrated in factory at 3.0V (not 5V nor 3.3V).
I did measurements with 328p and the OSCAL 1-254 did 5-15MHz freq range (nonlinear, btw).
The int osc frequency is temperature and voltage dependent - provided you have set the frequency to a known value (must be measured by a frequency counter - you can pass the clock to RB0 output pin via fuse settings) and run your chip at stable temperature and voltage, you may get 1% "average stability" (it is an RC oscillator).
The OSCAL frequency "step" was something like 40-50kHz (plus minus, afaik). I also observed the frequency wobbled within a step, so the frequency counter reading was like kHz (for 7.7MHz). But that could be caused by noisy voltage source during measurements.

Mind however, the chip temperature changes based on the calculation you perform :slight_smile:

OK so back to the original question then. How much inaccuracy would manifest in a real time clock? Does 10% freq error directly equate to +/- 3 min over on a 30 min timer?

Does 10% freq error directly equate to +/- 3 min over on a 30 min timer?

Note that there oscillator is supposed to be pretty "stable"; so the error will be a particular amount in a particular direction, depending on the environment. You won't be +10% in the first 30 minutes and -10% in the next...