1
votes

Is the internal clock on the ATTiny85 sufficiently accurate for one-wire timing?

Per https://learn.sparkfun.com/tutorials/ws2812-breakout-hookup-guide one-wire timing seems to need accuracy around the 0.05us range, so a 10% clock error on the AVR at 8MHZ would cause 0.0125us sized timing differences (assuming the 10% error figure is accurate, and that it's 10% error on frequency, not +/- 10% variance on each pulse).

Not a ton of margin - but is it good enough?

3

3 Answers

1
votes

First of all, WS2812 LEDs are not the 1-wire. The control protocol of WS2812 is described in the datasheet

The short answer is yes, ATTiny85, also the whole AVR family have enough clock accuracy to control the WS2812 chain. But routine should be written at assembler, also no interrupts should be allowed, to guarantee match the timing requests. When doing the programming well, 8MHz speed of the internal oscillator may be enough to output the different data to two WS2812 chains simultaneously.

So, when running 8MHz ±10%, the one clock cycle would be 112...138 ns.

The datasheet requires (with 150ns tolerance):

  • When transmitting "one": high level to be 550...850ns; - 6 clock cycles (672...828) matches this range (also 5 clock cycles (560...690ns) matches)
  • following low level - 450...750ns; - 5 cycles (560...690ns)
  • When transmitting "zero": high level 200...500ns; - 3 cycles (336...414ns)
  • following low level 650...950ns; - 6 cycles (672...828).

So, as you can see, considering tolerance ±10% of the clock's source, you can find the integer number of cycles which will guarantee match to the required intervals.

Speaking from the experience, it still be working if the low level, which follows the pulse, will be extended for a couple hundreds of nanoseconds.

0
votes

There are known issues using internal oscilator with UART - should be timed to 2% accuracy while the internal oscilator can be up to 10% off with factory setting. While it can be calibrated(AVR has register OSCCAL for that purpose), its frequency is influenced by temperature.

It is worth the try, but might not to be reliable with temperature changes or fluctuating operating voltage.

References: ATmega's internal oscillator - how bad is it, Timing accuracy on tiny2313, Tuning internal oscilator

0
votes

The timing requirements of NeoPixels (WS2812B) are wide enough that the only really critical part is the minimum width of a 1 bit. The ATtiny85 at 16Mhz is plenty fast to drive a string of them from a GPIO pin. At 8Mhz, it may not work (I haven't tried yet). I just released a small Arduino sketch which allows you to control NeoPixel strings of any length on a ATtiny85 without using any RAM.

https://github.com/bitbank2/NeoPixel

For devices with hardware SPI (e.g. ATMega328p), it's better to use SPI to shift out the bits (also included in my code).