Introduction: 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 220 ohm resistor
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:
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
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!!
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!
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
We have a be nice policy.
Please be positive and constructive.