Go Down

Topic: ATtiny841 -- OSCTCAL0A/B (Read 140 times) previous topic - next topic

jboyton

Does anyone know what these actually do?

The datasheet for 841 has this to say:

        The oscillator temperature calibration registers, OSCTCAL0A and OSCTCAL0B,
        can be used for one-time temperature calibration of oscillator frequency.
        See "OSCTCAL0A - Oscillator Temperature Calibration Register A" on page 33
        and "OSCTCAL0B - Oscillator Temperature Calibration Register B" on page 34.
                                         :
                                         :

        OSCTCAL0A - Oscillator Temperature Calibration Register A
                                         :
        OSCTCAL0B - Oscillator Temperature Calibration Register B

        The temperature calibration value can be used to trim the calibrated 8MHz
        oscillator and remove temperature variations from the oscillator frequency.


DrAzzy

#1
Jun 10, 2015, 06:28 am Last Edit: Jun 10, 2015, 06:30 am by DrAzzy
Yeah, I noticed that too...

The 1634 has the same registers - but they wrote a few sentences about them in that datasheet. I don't think Atmel proofreads their datasheets.

OSCTCAL0A - Oscillator Temperature Calibration Register A
This register is used for changing the temperature slope and frequency of the internal 8MHz oscillator. A pre-pro-
grammed calibration value is automatically written to this register during chip reset, giving the factory calibrated
frequency specified in Table 24-2 on page 230.
This register need not be updated if factory defaults in OSCCAL0 are overwritten although optimal accuracy is
achieved when OSCCAL0, OSCTAL0A and OSCTCAL0B are calibrated together.
• Bit 7 - Sign of Oscillator Temperature Calibration Value
This is the sign bit of the calibration data.
• Bits 6:0 - Oscillator Temperature Calibration Value
These bits contain the numerical value of the calibration data.
6.5.5 OSCTCAL0B - Oscillator Temperature Calibration Register B
A pre-programmed calibration value is automatically written to this register during chip reset, giving the factory cal-
ibrated frequency specified in Table 24-2 on page 230.
This register need not be updated if factory defaults in OSCCAL0 are overwritten although optimal accuracy is
achieved when OSCCAL0, OSCTAL0A and OSCTCAL0B are calibrated together.
• Bit 7 - Temperature Compensation Enable
When this bit is set the contents of registers OSCTCAL0A and OSCTCAL0B are used for calibration. When this bit
is cleared the temperature compensation hardware is disabled and registers OSCTCAL0A and OSCTCAL0B have
no effect on the frequency of the internal 8MHz oscillator.
Note that temperature compensation has a large effect on oscillator frequency and, hence, when enabled or dis-
abled the OSCCAL0 register must also be adjusted to compensate for this effect.
• Bits 6:0 - Temperature Compensation Step Adjust
These bits control the step size of the calibration data in OSCTCAL0A. The largest step size is achieved for 0x00
and smallest step size for 0x7F.

(the referenced table just lists the range of frequencies and accuracy with factory vs user calibration)
ATtiny core for 841+1634+828  http://goo.gl/6fRf8e
ATtiny core for x4/x5/x61/x7/x8 series http://goo.gl/O5Wtyu
ATtiny 841/1634/828/88/861/167 breakouts, mosfets, touch sensors and prototyping board in my store http://goo.gl/xyUN2v

jboyton

Thanks, I couldn't remember which datasheet I had seen that in (I've been paging through a lot of different uP datasheets lately). But does that mean that they left out part of the description in the 841 datasheet or that the 1634 is different? Either way, it still doesn't really explain what it does.

I have also noticed numerous errors in Atmel's datasheets. Their web site also has errors, promising features online that are not mentioned in the actual datasheets. There are some things I just can't figure out by reading the documentation alone. I will have to buy the parts and try them.

jboyton

I did some testing with the OSCCAL0, OSCTCAL0A and OSCTCAL0B registers of the ATtiny841. They combine to adjust both the frequency and the temperature compensation of the internal 8MHz oscillator.

Straight out of the box the 841 I tested compared favorably to an Atmega328 with respect to frequency variation vs temperature. Both of these chips are factory calibrated for lower voltages (either 3.3V or 3V). They were tested here at 5V which effectively translated their curves (interestingly in opposite directions). But the slope of the 841 was superior.





The datasheet for the ATtiny1634 includes greater detail about these three registers than the 841 datasheet and it appears to be valid for the 841.

*** OSCCAL0: It adjusts the frequency over a span of about 10MHz.

*** OSCTCAL0A: It adjusts both the frequency and the temperature compensation curve slope. The frequency adjustment span varies depending on the setting of OSCTCAL0B and roughly sums with that of OSCCAL0. When the step size is at a minimum (B=0xFF) the additional frequency span is about 6MHz; when at a maximum (B=0x80) it is about 16MHz. Bit 7 of OSCTCAL0A is a sign bit. The other bits determine the value of the frequency adjustment and temperature adjustment slope. From an OSCTCAL0A setting of 0x00 to 0x7F both of these values increase; from 0x80 to 0xFF they decrease. 0x00 and 0x80 are equivalent.

*** OSCTCAL0B: It has two parts. Bit 7 is an enable for the temperature compensation. The other bits determine the step size of both the frequency adjustment and slope given by OSCTCAL0A. From an OSCTCAL0B setting of 0x00 to 0x7F the value of OSCTCAL0A is ignored. From 0x80 to FF the step size decreases.


To get a picture of what happens I varied each of the registers while keeping the other ones at their fixed (default) values and observed the frequency. The factory defaults were 0x28, 23, 80.




Confused? Because of the way the registers depend on one another it's not intuitive what algorithm to use to determine optimal values. I employed an iterative approach where I first set the slope using the smallest step size and adjusting OSCCAL0 to set the frequency to 8MHz at room temperature. Then I varied the temperature to see what slope I really had. Wash, rinse repeat.

This graph shows the effects of adjusting the compensation slope. I was able to hand select values that kept the oscillator in a ±0.1% band over a wide temperature range.






For what it's worth.

Go Up