Go Down

### Topic: Internal oscillator 328P how 'inaccurate' is it? (Read 4339 times)previous topic - next topic

#15
##### May 13, 2015, 09:31 pm
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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### Nicknml

#16
##### May 13, 2015, 10:08 pm
The 1284P is running at 5V.

#### pito

#17
##### May 13, 2015, 11:46 pmLast Edit: May 14, 2015, 12:16 am by pito
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 77xx.xxx 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

#### CopperDog

#18
##### May 14, 2015, 12:10 am
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?
Personal bytes are finite, save room for play.

#### westfw

#19
##### May 14, 2015, 01:01 am
Quote
Does  10% freq error directly equate to +/- 3 min over on a 30 min timer?
Yes.
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...

#### CopperDog

#20
##### May 14, 2015, 02:14 am
Yes I agree the error would be a consistent one that changed with temperature however I'm trying to understand just what , for example a 5% error would consist of on a 8 MHz clock. Would that show up as a couple of seconds per minute (gained or lost depending on the error) or a few millis?

An angle error for instance can be calculated to be x amount at y distance.

If there's a way to calculate for an inaccurate clock there's a way to compensate with code or design. Just trying to wrap my head around it.

Personal bytes are finite, save room for play.

#21
##### May 14, 2015, 03:12 am
If there's a way to calculate for an inaccurate clock there's a way to compensate with code or design.
Yup...
http://forum.arduino.cc/index.php?topic=80489.0
https://github.com/leomil72/swRTC

Quote
I'm trying to understand just what , for example a 5% error would consist of on a 8 MHz clock
A 5% error is a 5% error.  If you do the math you will find it makes no difference where you apply the 5%.

Quote
Would that show up as a couple of seconds per minute (gained or lost depending on the error) or a few millis?
1 minute = 60 seconds; a more convenient unit for understanding the error.

60 - (5% * 60) = 57
60 + (5% * 60) = 63

A 5% error over one minute is ±3 seconds.

#### westfw

#22
##### May 14, 2015, 03:19 am
Ah.  I remembered what one of the calibrators was called.  Check out: http://ernstc.dk/arduino/tinytuner.html

#### CopperDog

#23
##### May 14, 2015, 05:05 am
Coding Badly, if you're still here, I see the TinyTuner stuff is your baby. Will this need much tweaking to work on a 328P?
Personal bytes are finite, save room for play.

#### CopperDog

#24
##### May 14, 2015, 06:46 am
Testing the timing on my setup just using a stop watch and I can tell it's not going to work on the 8MHz internal without tuning and I'll have no idea what will happen with temp fluctuation later on. Switched it back to 16MHZ with a crystal and if there's an error I can't detect it using a stop watch. I'll live with the artifact on the amplifier output if I can't filter it.

When I have time I'll experiment with tuning the internal 8MHz.
Personal bytes are finite, save room for play.

#25
##### May 14, 2015, 07:20 am
Coding Badly, if you're still here, I see the TinyTuner stuff is your baby. Will this need much tweaking to work on a 328P?
Version 1 does not have a binding for the m328p processor.  At the bottom of TinyTuner.h is this...

Code: [Select]
`#if defined( __AVR_ATtiny2313__ )  typedef TinyTunerTemplate<0x1B,0> Tiny2313Tuner;  typedef Tiny2313Tuner TinyTuner;#elif defined( __AVR_ATtiny84__ )  typedef TinyTunerTemplate<0x16,1> Tiny84Tuner;  typedef Tiny84Tuner TinyTuner;#elif defined( __AVR_ATtiny85__ )  typedef TinyTunerTemplate<0x16,4> Tiny85Tuner;  typedef Tiny85Tuner TinyTuner;#elif defined( __AVR_ATtiny45__ )  typedef TinyTunerTemplate<0x16,4> Tiny45Tuner;  typedef Tiny45Tuner TinyTuner;#else  #error Add a definition for your processor.#endif`

Adding something like this may work...

Code: [Select]
`#elif defined( __AVR_ATmega328P__ )  typedef TinyTunerTemplate<0x03,7> Tiny328Tuner;  typedef Tiny328Tuner TinyTuner;`

The parameters are I/O port, bit.  I usually put Tiny Tuner on the XTAL2 pin.  The snippet above should put the Tiny Tuner input on PINB7.

Version 2 is easier to configure (TinyTuner2.h) and already has a binding for the m328p processor (XTAL2 / PINB7).

#### CopperDog

#26
##### May 14, 2015, 03:22 pm
The parameters are I/O port, bit.  I usually put Tiny Tuner on the XTAL2 pin.  The snippet above should put the Tiny Tuner input on PINB7.

Version 2 is easier to configure (TinyTuner2.h) and already has a binding for the m328p processor (XTAL2 / PINB7).

Thanks for the response Coding Badly. I didn't realize there was a version 2 of the Tiny Tuner. I'll have to find that.
Personal bytes are finite, save room for play.

#27

#### jboyton

#28
##### May 21, 2015, 03:42 amLast Edit: Jun 27, 2015, 08:19 pm by jboyton
I was hoping I could use the internal oscillator for a project I'm just starting. So I played around with it a bit to see what was what. Out of the box my Atmega328 defaulted to OSCCAL = 0xA6. At an ambient temperature of 71°F it ran a little slow, about 0.8% below 8MHz (for Vcc = 5V).

Tuning it from A6 to A7, A8, A9, AA as well as 66 and 67 (on the other side of the OSCCAL curve) produced this:

Interestingly A7 and A8 were almost the same whereas A9 jumped up quite a bit. Also, while I expected it to be impossible to nail it given the 8-bit OSCCAL register, I was hoping the frequency would be stable and so amenable to software calibration. Instead the variation (for a given temperature and voltage) was something around ±0.1%. In comparison, when using a resonator to clock the chip, the variation at a fixed voltage and (relatively) fixed temperature was less than ±1ppm.

Pushing the chip through a range of temperatures produced this:

And of course varying the voltage will do something similar.
From the datasheet:

For what it's worth.

Go Up