ATTiny10 Clock Calibration

If you have access to a frequency counter, the internal oscillator of the ATTiny 4, 5, 9 & 10 chips can be calibrated by programming the chip with the following code:

.device ATtiny10

.fuses ckout

 

.CSEG

.org 0

;Interrupt vector table

  rjmp reset ; All Resets

  reti ; External Interrupt Request 0

  reti ; Pin Change Interrupt Request 0

  reti ; Timer/Counter0 Input Capture

  reti ; Timer/Counter0 Overflow

  reti ; Timer/Counter0 Compare Match A

  reti ; Timer/Counter0 Compare Match B

  reti ; Analog Comparator

  reti ; Watchdog Time-out

  reti ; VCC Voltage Level Monitor

  reti ; ADC Conversion Complete

reset:

; Set Stack Pointer (SP)

  ldi r16, 0x00

  out SPH, r16

  ldi r16, 0x5F

  out SPL, r16

; Set clock to 4MHz

  ldi r16, 0xD8 ; Unprotect CLKPSR reg

  out CCP, r16

  ldi r16, 1 ; Divide by 2

  out CLKPSR, r16

; Calibrate Oscillator

  ldi r16, 0x70 ; <- Adjust this value

  out OSCCAL, r16

wait:

  sleep

  rjmp wait

Then, connect the ATTiny10 to the frequency counter, like this:

Then, adjust the 0x70 value until the frequency counter reads 4.00 MHz.  Note: if you don't have a frequency counter, you can sometimes find a frequency counter function on some multimeters, such as this Extech EX330.  Most modern digital oscilloscopes also include a frequency counter function.