ATtiny13 internal oscillator accurate @9.6MHz but inaccurate @4.8MHz

ATtiny13A datasheet states that the internal oscillator has a +/-10% error with factory calibration and +/-2% error with user calibration.

When I use the 9.6MHz internal clock the error range is ~2%.
But when I use the 4.8MHz internal clock I get an error range of ~12%.
Since the datasheet says 10% max I was assuming that I should normally be expecting values much less than that, and certainly not more. Like how I’m getting 2% with 9.6MHz even tho it’s on factory calibration.

Now in the section about the internal oscillator the datasheet also states that:

During reset, hardware loads the calibration data into the OSCCAL register and thereby automatically calibrates the oscillator. There are separate calibration bytes for 4.8 and 9.6 MHz operation but only one is automatically loaded during reset (see section “Calibration Bytes” on page 105). This is because the only difference between 4.8 MHz and 9.6 MHz mode is an internal clock divider.

I don’t understand this perfectly but I assume what the last line is trying to say is that both clocks use actually the same oscillator and because of that the same calibration value should work for both of them? Is that what it’s saying?

And here’s what section “Calibration Bytes” on page 105 has to say:

The signature area of the ATtiny13A contains two bytes of calibration data for the internal oscillator. The calibration data in the high byte of address 0x00 is for use with the oscillator set to 9.6 MHz operation. During reset, this byte is automatically written into the OSCCAL register to ensure correct frequency of the oscillator.
There is a separate calibration byte for the internal oscillator in 4.8 MHz mode of operation but this data is not loaded automatically. The hardware always loads the 9.6 MHz calibration data during reset. To use separate calibration data for the oscillator in 4.8 MHz mode the OSCCAL register must be updated by firmware. The calibration data for 4.8 MHz operation is located in the high byte at address 0x01 of the signature area.

I’m not quite sure what this is trying to say either. Does it mean that the calibration data of 9.6MHz also works for 4.8MHz? Or is it saying that for using the 4.8MHz the user should in fact load the 4.8MHz calibration data manually?

This is my ATtiny13 code that I use for determining accuracy:

#define pin PB2
#define period 5000

void setup(){
  //OSCCAL = 0x66;
  pinMode(pin, OUTPUT);
}

void loop(){
  PORTB &= ~(1<<pin);
  _delay_us(period/2);
  PORTB |= (1<<pin);
  _delay_us(period/2);
}

Pin 2 is connected to an Arduino which measures the period of the square wave created:

#include <util/atomic.h>

volatile unsigned long period = 0;

void setup(){
  Serial.begin(115200);
  attachInterrupt(digitalPinToInterrupt(2), isr, FALLING);
}

void isr(){
    static unsigned long lastTime = 0;
    unsigned long time = micros();
    period = time - lastTime;
    lastTime = time;
}

void loop(){
  unsigned long prd = 0;
  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
    prd = period;
  }
  Serial.println(prd);
  delay(500);
}

My measurements:
9.8MHz factory calibrated clock error: ~2%
4.8MHz factory calibrated clock error: ~12%
4.8MHz user calibrated clock error: ~1%

Question (1): Why am I getting so much error when using the 4.8MHz clock?
Question (2): Given those quoted sections, do the 4.8MHz and 9.6MHz clock need different calibration data after all or not?
(When using MicroCore’s calibration sketch I get different calibration values for 4.8 and 9.6)

IIRC I discussed this on the Avrfreaks forum a while ago.

I got an ATtiny13 from eBay that clearly didn't meet it's specification when it came to the internal oscillator clock speed, and thus sold on the "black market". The 9.6 MHz oscillator ran at 9.0 MHz, and the 4.8 MHz one ran at 5.0.

The weird thing is that in order silicon revisions, the 9.6 and 4.8 MHz are actually separate oscillators! In recent silicon revisions, it's the same oscillator but divided down.

What are the week and year writings on the chip (YYWW)? The one I have (inaccurate, from eBay) says 1234.

Oh that's interesting. Mine says "1633", I guess it's not that old.

Are you referring to this avrfreaks post? ATtiny13A 4.8MHz | AVR Freaks
It goes WAY off topic but there doesn't seem to be any conclusive answer to the question "if 4.8 is only the divided version of 9.6 then why does its accuracy differ?"
The only answer is what you suggested but mine is from 2016 if those values are correct. So I guess some chips still have two different oscillators for each speed. Since there doesn't seem to be any other explanation.

Question (1): Why am I getting so much error when using the 4.8MHz clock?
Because the Attiny13 always uses the calibration byte for 9.6 MHz.

Question (2): Given those quoted sections, do the 4.8MHz and 9.6MHz clock need different calibration data after all or not?
Yes, when using the 4.8 MHz clock, the user software needs to change the OSCCAL value if a more precise clock is required(communication etc).

In short:
The Attiny13 has two calibration bytes, one for 9.6 MHz and one for 4.8 MHZ.
The calibration bytes cannot be read from a sketch, only via a programmer.

You can read them using avrdude like:

avrdude -p partnumber -c programmer_id -U calibration:r:calibration.txt

E.g:
avrdude -p t13 -c usbasp -U calibration:r:calibration.txt:h

In any case, it is best to do a calibration rather than using the factory settings.

I have shown a small calibration sketch example with more explanation
here

Thanks for the avrdude command. I was wondering how to read that value.

ardcp:
Question (1): Why am I getting so much error when using the 4.8MHz clock?
Because the Attiny13 always uses the calibration byte for 9.6 MHz.

Question (2): Given those quoted sections, do the 4.8MHz and 9.6MHz clock need different calibration data after all or not?
Yes, when using the 4.8 MHz clock, the user software needs to change the OSCCAL value if a more precise clock is required(communication etc).

What confuses me about that is this phrase in the datasheet:
"This is because the only difference between 4.8 MHz and 9.6 MHz mode is an internal clock divider."
If the only difference is a divider, then why should they need different calibration?

One thing I forgot to mention is the 1.2MHz internal osc. has the same accuracy as the 9.6MHz. I checked MicroCore files and the 1.2MHz uses the 9.6MHz osc. with an 8 prescalar. This further proves that if 4.8MHz was in fact 9.6MHz divided down it would also be accurate like 1.2MHz is.

Another "proof" is what the calibration instructions of MicroCore's github page says:
"The internal 9.6 and 4.8 MHz internal oscillators (yes, these are separate in some silicon revisions) in the ATtiny13 are usually not very accurate."
(Emphasize mine).

I think the most reasonable explanation is that there are in fact two separate oscillators even in newer chips, and the datasheet is incorrect?

A short follow up:
You can search for two documents, AVR053 and AVR054, they explain many details about the internal oscillators and also have example code. I have not read all the details, except page 3 of the AVR053 which has a table showing the oscillators and frequencies for many attiny versions.

Is the ATTiny test sketch working well? I would use the timer to generate a PWM and measure its frequency. It can be as easy as using analogWrite(127). The delay_us and loop has some overheat unknown to me. You are adding it to the measured error.

ardcp:
A short follow up:
You can search for two documents, AVR053 and AVR054, they explain many details about the internal oscillators and also have example code. I have not read all the details, except page 3 of the AVR053 which has a table showing the oscillators and frequencies for many attiny versions.

Thanks for the hint.
Here are a couple points worth mentioning from the docs:

"If a device has more than one oscillator a calibration byte for each of the RC oscillators is stored in the Signature Row."
The ATtiny13 has 2 calibration bytes stored, so this could indicate it has 2 oscillators.

About the ATmega8 it says: "Four different RC oscillators with the frequencies 1, 2, 4, and 8MHz are present in the device."
About the ATtiny13 it says: "...two frequencies are offered: 4 and 8MHz for ATtiny2313, and 4.8 and 9.6MHz for the ATtiny13."
So when its talking about the tiny it says two "frequencies" as opposed to "Four different RC oscillators". Maybe that means it doesn't have two different oscillators.

Smajdalf:
Is the ATTiny test sketch working well? I would use the timer to generate a PWM and measure its frequency. It can be as easy as using analogWrite(127). The delay_us and loop has some overheat unknown to me. You are adding it to the measured error.

Duh, you're right. I guess my original project which used the delay method made me blind to the obvious and better way.
That error is insignificant compared to how off the 4.8MHz is tho. With 9.8MHz I get ~5100us periods, and with 4.8MHz I get ~5600us periods.

IIRC the 4.8MHz oscillator needs less current than the 9.6MHz prescaled by 2 which would be a hint they are different.