An easy way to calibrate the ATtiny2313 internal oscillator

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
opossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am

An easy way to calibrate the ATtiny2313 internal oscillator

Post by opossum »

The factory cal for the 2313 is +/- 10%. Here is an easy way to tweak it to be much more accurate using only ordinary household 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

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Post by adafruit »

you may want to use "U" as it is an awesome chacter for measuring bit timings

User avatar
opossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am

Post by opossum »

Using 'x' results in less jitter than 'U'.

User avatar
ricg
 
Posts: 4
Joined: Sun Feb 17, 2013 4:11 am

Re: An easy way to calibrate the ATtiny2313 internal oscillator

Post by ricg »

Does the code you provide work with the attiny85 and the 45 ?
thanks
Ric

grit
 
Posts: 3
Joined: Wed Aug 12, 2015 3:48 am

Re: An easy way to calibrate the ATtiny2313 internal oscilla

Post by grit »

Is there also a left-hand orientated version of this awesome little calibration program?

User avatar
opossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am

Re: An easy way to calibrate the ATtiny2313 internal oscilla

Post by opossum »

I don't understand what "left-hand orientated version" means.

grit
 
Posts: 3
Joined: Wed Aug 12, 2015 3:48 am

Re: An easy way to calibrate the ATtiny2313 internal oscilla

Post by grit »

I was just kidding man, who cares which key to press (with any finger from left or right hand) on a utility like this - great tool!

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”