attiny85 clock precision

I am using an attiny85 coupled to a mosfet and a water valve to water my plants at a regular interval. I want to water it every day. I programmed it to turn on every 24h, and today it is not on time. I expected a drift, but watering can occur 4 hours earlier or later, no problem. When should I expect there to be a problem in my setup? In other words, given that I use the internal clock of the attiny85 (which I run at 1MHz), what is the time bracket I can expect the water to turn on if I target 24h of delay between two waterings? Also, is it always going to be biased in the same way, i.e. is the bias systematic or random?

As always, start by reading the datasheet:

6.2.3 Calibrated Internal Oscillator

By default, the Internal RC Oscillator provides an approximate 8.0 MHz clock. Though voltage and temperature dependent, this clock can be very accurately calibrated by the user. See “Calibrated Internal RC Oscillator Accuracy” on page 164 and “Internal Oscillator Speed” on page 192 for more details.

...

During reset, hardware loads the pre-programmed calibration value into the OSCCAL Register and thereby automatically calibrates the RC Oscillator. The accuracy of this calibration is shown as Factory calibration in Table 21-2 on page 164.

The referenced table:

------------------------------------------------------
| Method  | Frequency | Vcc      | Temp   | Accuracy |
------------------------------------------------------
| Factory | 8.0MHz    | 3V       | 25°C   | ±10%     |
------------------------------------------------------
| User    | 6-8MHz    | 1.8V-5.5 | -40-85 | ±1%      |
------------------------------------------------------


So the factory calibration may be off by as much as 10%, at 3V and 25°C. If your voltage and/or temperature is something else, there's no specified accuracy at all.

You can calibrate the RC oscillator in your specific attiny to be 1% accurate at a fixed voltage and temperature (details, again, are in the datasheet).

But honestly, if you need any sort of temporal accuracy, the easiest way is to just use a crystal as a clock source, assuming you can spare the I/O pins. The internal oscillator is nice for when you don't need the accuracy, or when you have large volumes and need the absolute lowest BOM cost.

If you want to go the RC oscillator route, see Atmel RC oscillator calibration app note for more details. (Suggested in the comments by bigjosh - Thanks! Didn't know that one yet.)

• Full app note on getting best possible calibration here... atmel.com/images/doc2555.pdf Commented Aug 3, 2016 at 16:47
• @bigjosh The crystal is 20ppm and the calculation is for 2ppm, so 10x that. You can use a $25 oscillator which is guaranteed to drift less than 15 minutes in 100 years! Commented Aug 3, 2016 at 17:57 • is the drift positively or negatively correlated with temperature? Commented Aug 3, 2016 at 18:32 • UPDATED: Agreed on using a$0.04 crystal to get you to within [1.7s](wolframalpha.com/input/?i=(24+hours)+*+(20ppm) per day accuracy! Commented Aug 3, 2016 at 19:13
• @nmz787 Pretty much. You also need load capacitors as shown in the data sheet. You also have to set the fuses and registers right. But once you do that, the crystal will work. Alternately you could use an external RTC like a DS2313 or RX8900. These guys are crazy accurate (<5ppm) and use almost no power, but they do cost big bucks.. about \$2 each! :) Commented Aug 27, 2018 at 6:47

I'd also add (from the data sheet!)...

...so out of the box you should expect your chip to be accurate to within 144 minutes per day, and with a little work doing extra calibration yourself to within 864 seconds per day.