Introduction: ATtiny Oscillator Calibration

Picture of ATtiny Oscillator Calibration

How does it works:

Your ATtiny comes with a uncalibrated oscillator, and when you need to work with time, your time is not going to be the expected one.

This process makes you able to get the right OSCCAL value for your Attiny, so you can compensate your clock and make it work as close as it should suppose to.

Material you need:

2x Push buttons
2x LED's
2x 220 ohm resistor
1x Breadboard
1x ISP Programmer (for your attiny)
~14x Jumper Wires
1x Arduino (Uno)
1x ATtiny (ATtiny13A in my case)
1x Multimeter that reads Hz

Step 1: Source Code

You have to program your Attiny with "osccal_attiny_slave" and your Arduino (Uno) with "osccal_uno_master".

If you need to add Attiny13 support to your Arduino SDK, use this instructions:
https://github.com/tekstop/attiny/tree/Arduino1

The "osccal_attiny_slave" is a very small and simple script that should not be bigger than 1K (after compiling) - This way, you are able to calibrate ATtinnies with a small In-System programmable flash.

Step 2: Multimeter Readings

Picture of Multimeter Readings

After you have your Multimeter on Hz, you connect the back probe to GND (on your circuit) and the red probe to those "Arduino PWM signal" or "ATtiny PWM signal" pins.

And first you measure your Arduino (Uno) PWM signal, and you should take that value as reference, because your ATtiny PWM signal should match this value.

If your ATtinny PWM signal needs to be incremented you press the right button "[ + ]" on your breadboard, if you need to decrement, you press the left button "[ - ]" on your breadboard. Debug Leds should brink for awhile after you press each button. (You should wait at least 2 seconds after the led goes off before you press another button)

Your OSCCAL value is visible on your Arduino console.

Note: You might not be able to get the right accuracy but a close one, so try your best to get the closest number possible.

Step 3: It's Taking Me So Long!!

Picture of It's Taking Me So Long!!

If your ATtiny PWM value is way too far from your wanted one, you can edit the code by your own and increase (or decrease) your OSCCAL starting value (you need to change it on both scripts, Master and Slave) then you should upload both sketches to your Arduino and your Attiny.

Step 4: I Have My OSCCAL Now!

Picture of I Have My OSCCAL Now!

Once you have your OSCCAL value, you should use it on your projects for that specific ATtiny.
Remember, this OSCCAL value only works for your ATtiny, if you get a new one, you have to do this process all over again so you can get the correct OSCCAL value for that new one.

In my case, my OSCCAL value is 46, so on my void setup() i will use "OSCCAL = 46", for each project i make with this specific ATtiny

Comments

SalbaheJim (author)2016-04-20

Is the OSCCAL a global variable in the arduino.h library? I don't see it declared in your sample sketch where you utilize the value you determined in the test. Thanks for the clarification.

PedroM31 (author)SalbaheJim2016-04-21

OSCCAL is in fact a register, so it should work just fine without any library.

SalbaheJim (author)2016-04-20

Is the OSCCAL a global variable in the arduino.h library? I don't see it declared in your sample sketch where you utilize the value you determined in the test. Thanks for the clarification.

陳亮 (author)2016-04-18

Great! I never try to do that in my previous project.

PedroM31 (author)陳亮2016-04-19

Thanks, go ahead :)

wold630 (author)2016-04-18

Great project!

PedroM31 (author)wold6302016-04-18

Thanks :)

About This Instructable

1,155views

19favorites

License:

More by PedroM31:Playstation 3 ventilation mod[Arcade PS2] Sync on green - simple way to remove the greenishATtiny oscillator calibration
Add instructable to: