An easy way to calibrate the ATtiny2313 internal oscillator
Moderators: adafruit_support_bill, adafruit

An easy way to calibrate the ATtiny2313 internal oscillator

by oPossum on Wed Feb 06, 2008 5:30 pm

The factory cal for the 2313 is +/- 10%. Here is an easy way to tweak it to be much more accurate using only ordinary banned items.

First build the circuit shown below -or- hack a MiniPOV3 by adding a wire from pin 2 of the DE9 to pin 3 of the 2313.

Image

Burn the firmware. Make sure the fuses are set for internal 8 MHz oscillator (the default it 1 MHz internal).

Configure terminal software for 9600,8,N,1.

Press 'x' (must be lower case!). The factory calibration will be shown. Continue to press 'x' to increment the OSCCAL test value.

The time shown is the async serial (RS-232) bit time in units of 0.5 uS as perceived by the microcontroller. 9600 bps has a bit time of 104 uS, so a measured time of 208 (D0 hex) indicates that the internal oscillator is very close to 8.000 MHz. The clock frequency is equal to 38462 * Time. In the example below the factory OSCCAL value of 4A resulted in clock of 8.385 MHz (4.8 % high).

The factory calibration can not be changed, so firmware must set the optimal OSCCAL value during initialization.

Assembly:

ldi temp,0x45 ; Load optimal OSCCAL value in to temp register
out OSCCAL,temp ; Set OSCCAL register

C:

OSCCAL = 0x45;


Image
User avatar
oPossum
 
Posts: 635
Joined: Thu Oct 25, 2007 11:42 pm
Location: Michigan, USA

by adafruit on Wed Feb 06, 2008 5:31 pm

you may want to use "U" as it is an awesome chacter for measuring bit timings
User avatar
adafruit
 
Posts: 11683
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

by oPossum on Wed Feb 06, 2008 5:36 pm

Using 'x' results in less jitter than 'U'.
User avatar
oPossum
 
Posts: 635
Joined: Thu Oct 25, 2007 11:42 pm
Location: Michigan, USA

Re: An easy way to calibrate the ATtiny2313 internal oscillator

by ricg on Sun Feb 17, 2013 3:15 am

Does the code you provide work with the attiny85 and the 45 ?
thanks
Ric
ricg
 
Posts: 1
Joined: Sun Feb 17, 2013 3:11 am