RC osc. calibration at 3.3V

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

Reading the atmel datasheets (mega8L datasheet to be exact) I find that the calibration byte for the internal oscillator only works for 5V operation.
At 3.3V operation the resulting operating frequency will be a bit lower. (about 0.965MHz compared to 1MHz).
Add to this the +-1% error and the worst case scenario is a frequency 5% lower than 1MHz. A serial com link will not be very reliable at 5% frequency error.

So, how can one best solve this problem?
Of course for hobbyist applications, one can simply adjust the calibration byte a bit and hope it works good enough.
I am thinking perhaps it is possible to do it in a more reliable way. How about some kind of auto-calibration during ISP programming?
Let's say we download a very simple app to the AVR that sets up a timer interrupt to occur at let's say 1kHz. At each timer interrupts the AVR sends a signal to the PC using the ISP cable. A program on the PC counts the number of signals during one second. If the PC program finds the frequency is off by too far, it simply adjusts the calibration byte a bit and restart the AVR program for a new test. This can be repeated until a good enough calibration value is found.
When the calibration value is found, the real AVR application can be downloaded to the AVR together with the new calibration value.
The good thing is that the above suggested process could be totally automated and it results in a very reliable operating frequency.

Other advantages with the method described above is that the oscillator could optionally be calibrated to other frequencies than thoose provided by atmel (1, 2, 4, 8MHz). A very handy feature since none of the frequncies provided by atmel are very UART-friendly.

What do you think? Is there a better solution to the problem?

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

Don't use the internal UART but program your own UART code, then you can add auto calibration to it I think.

admin's test signature
 

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

The biggest problem with the internal RC oscillator, is it is not temperature stable. thus if you need precise timing for things like asynchronous communications, I STRONGLY suggest using an external crystal.

Alternatively you could devise some sort of self calibration method while the part is in operation (not during programming). One way to do this is feed a low frequency pulse train to the ICP pin (say a 60Hz[north america] square wave, generated from the AC mains of the power supply). Then in your input capture ISR you can compare the measured count to the mathematical ideal value, and adjust the OSCAL accordingly. This forms a sort of software PLL. This method allows for both correction due to voltage variance, and temperature. All you need is a stable input reference (AC mains are great for this)

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

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

The internal RC oscillator does not change that much with the temperature...
There is a difference of 1% beween 0 and 40 degrees celsius.
For devices that operate indoors this should not be much of a problem.

You don't think the internal oscillator is good enough for async. serial comms?

I'am working on a very small device where every square millimeter of board area counts. I'am currently looking at the mega8 because it has internal oscillator, BOD, large SRAM, and exists in 5*5mm MLF package.

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

Hi,

I am using the internal oscillator for a 115200 baud serial link and have had no problems so far (i've tested against temperature as well).

I bumped the internal oscillator to a 'nice' frequency that works well with baud rates using the OSCCAL byte (7.3728 MHz).

As long as the voltage is stable you should be able to calibrate the internal oscillator I would think.

-Colin

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

Actually, the baudrate is irrelevant in the equation.
A lower baudrate does not in any way compensate for a errornous CPU clock frequency.

I've built 40 systems based on a tiny15 with internal oscillator. They used a serial link. Worked well, except I think two or three had problems. Probably due to the fact that they were running at 3.3V...
Some trial and error with the ASCCAL byte made even thoose two work.

Thing is, I don't want any "trial and error solution" in the system I'am working on now.

How did you calibrate the oscillator to 7.37MHz ? Trial and error?

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

Hi,

Actually, the baudrate is irrelevant in the equation.

Although the maximum baud rate will depend on the clock frequency...

How did you calibrate the oscillator to 7.37MHz ? Trial and error?

I used trial and error for this application. That is not the most efficent (or accurate) way though of course, but for this application it was acceptable.

A better way is just to setup a PWM or some other pulse that is easily related back to the AVR's frequency, and calibrate it that way.

As well there is a design note on this, although I think it fed a signal into the AVR and internally compared it.

-Colin

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

"The internal RC oscillator does not change that much with the temperature..."

In a simple experiment with a Mega8, 22 to 85 degrees C caused a 7% change in the oscillator frequency.

But, ampz, I believe that it will work well enough at modest speeds. I wouldn't count on it in a life-critical application, though. An indoir application, you say. Suppose it is supposed to send a message over the serial line to the fire department when the temperature rises. :) But, wait, the internal oscilator frequency has changed, and the message cannot be successfully sent!

Lee

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

Hi,

There is a difference of 1% beween 0 and 40 degrees celsius.

In a simple experiment with a Mega8, 22 to 85 degrees C caused a 7% change in the oscillator frequency.

First I'm going to assume that both those numbers are 100% correct (ahh.. more percentages).

The tests may have occured at different voltages, which would change the characteristics.

The tests are conducted at different temperatures. For example the RC oscillator may change 1% from 0 to 40, but all of a sudden at 55 C it marks a sharp turn in frequency

Also what was being measured? External air temperature, body temperature, junction temperature?

So its all a hard call ;-) I would say its probably higher than 1% error though.

-Colin

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

dang, forgot to end the italics. should look more like

Hi,

There is a difference of 1% beween 0 and 40 degrees celsius.

In a simple experiment with a Mega8, 22 to 85 degrees C caused a 7% change in the oscillator frequency.

First I'm going to assume that both those numbers are 100% correct (ahh.. more percentages).

The tests may have occured at different voltages, which would change the characteristics.

The tests are conducted at different temperatures. For example the RC oscillator may change 1% from 0 to 40, but all of a sudden at 55 C it marks a sharp turn in frequency

Also what was being measured? External air temperature, body temperature, junction temperature?

So its all a hard call ;-) I would say its probably higher than 1% error though.

-Colin

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

"The tests may have occured at different voltages..."

Sorry, 5V supply voltage, 7.3728MHz.

"Also what was being measured? External air temperature, body temperature, junction temperature?"

Inside an environmental chamber, stabilized for at least 20 minutes at each setting change.

And my body temperature usually remains constant at work, unless I have a fever and on days the new rep with the long hair calls on us.

Lee

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

The 1% number is straight from the mega8 datasheet. No test.
There are quite a few RC oscillator characteristics diagrams in there.

The oscillator frequency curve does change slightly faster at higher temperatures acording to the diagramns, but 7% is way off.
There should be about 2.5% drop in oscillator frequency when comparing 85C to 22C acording to the diagrams.

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

Hi,

Inside an environmental chamber, stabilized for at least 20 minutes at each setting change.

Sounds like a pretty good test!

The 1% number is straight from the mega8 datasheet. No test.
There are quite a few RC oscillator characteristics diagrams in there.

Ah I see! However there is one catch: that is in the 'typical characteristics' section.

Lee's AVR is perfectly capable of having a 7% change in oscilllator frequency. Its capable of having a 50% change as well; unlikely, but still possible according to the datasheet.

We don't know which batch (data-code) of chips Atmel tested, there may have been a period of less reliable internal RC oscillators.

So I guess its back to what Lee said a while ago:

But, ampz, I believe that it will work well enough at modest speeds. I wouldn't count on it in a life-critical application, though. An indoir application, you say.

-Colin

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

Yeah, I know.
Still, calibration of the oscillator at 3.3V would drasticaly increase the chanses.

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

I have an application that works from -20 to 85 deg C, and I am using the internal osc. (mega16) and the only thing that I can add is that the osc. doesn't work as you expect, doesn't matter is you calibrate the avr.... honestly I am moving on to something with a real stable and accurate internal osc, and going to try the Cygnal microcontroller, this micro has a real internal osc, not a toy int. osc... good luck!!! and the force stay with you, you will need it!!! :)

Alex.

admin's test signature
 

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

Can you elaborate on the statement that it "doesn't work as you expect"
and doesn't matter if it's calibrated?

admin's test signature