Changing the ATmega328 Clock Speed to 8 MHz
By default, the ATmega328 runs at 1 MHz. Because the bit-banging performed by Danny Havenith’s ws2811 library is timing senitive, the AVR needs to run at a clock speed of 8 MHz.
Step 1: Check the clock speed
The clock speed is controlled by the low fuse byte (LFUSE). Its value can be found with avrdude.
$ avrdude -c usbasp -p atmega328p -v
avrdude: Version 6.3, compiled on Feb 7 2018 at 03:33:11
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
...
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as FF
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (E:FF, H:D9, L:62) (1)
avrdude done. Thank you.
1 | L:62 is the low fuse byte. (In hexidecimal, 0x62 = 0b01100010.) |
If your chip reports L:62
, its clock is running at 1 MHz and you
need to perform the next step.
Step 2: Change the clock speed using avrdude
Use avrdude to set LFUSE = 0xe2 to run the ATmega328 at 8 MHz.
$ avrdude -c usbasp -p atmega328p -v -U lfuse:w:0xe2:m
avrdude: Version 6.3, compiled on Jul 12 2018 at 21:00:17
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
...
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as FF
avrdude: reading input file "0xe2"
avrdude: writing lfuse (1 bytes):
Writing | ################################################## | 100% 0.01s
avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xe2:
avrdude: load data lfuse data from input file 0xe2:
avrdude: input file 0xe2 contains 1 bytes
avrdude: reading on-chip lfuse data:
Reading | ################################################## | 100% 0.00s
avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (E:FF, H:D9, L:E2)
avrdude done. Thank you.