The Trinket by default runs at 8 MHz, a plenty fast speed for nearly all of your microcontroller needs. However, you may want to use code that requires it to run at 16 MHz, or maybe you just want a little boost in speed.
The 16 MHz clock speed is for Trinket 5V only!
The ATtiny85 is only specified to run at 16 MHz when powered at 5V - that means that officially you can only run the 5V Trinket at 16 MHz.
However, the AVR series is pretty forgiving for overclocking, so you may be able to run the 3V Trinket at 16 MHz. Note that this is still overclocking, your code may run flakey or not at all! Overclocking should not damage the AVR, but we still recommend sticking with 8 MHz only for the 3V version, and 8 or 16MHz only on the 5V version.
Power Tradeoffs
Doubling the speed will increase the power usage just a bit. At 8 MHz the current draw is about 9 milliamps. That number includes the green power LED which draws about 3mA so thats 6mA for the microcontroller itself.
At 16 MHz the draw is 12mA total. Subtracting the green LED current draw, that means 9mA for the microcontroller itself.
How to activate the 16 MHz clock
...on AVR-GCC
We can activate the 16MHz clock 'in software' simply by asking the chip to set the clock prescale. If you are using raw avr-gcc, run this as the first line in main()
clock_prescale_set(clock_div_1);
You may need to add #include to your file so that the commands are recognized. Then make sure to compile your code with F_CPU = 16000000
...Arduino IDE
Using 16 MHz mode is very similar when using the Arduino IDE. Add the following line to the very top of your Arduino sketch (as the first line)
#include <avr/power.h>
Then, in setup() - add this as the first line in the function:
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
Then select Trinket 16MHz from the Tools->Board menu. Your code will compile and run at 16 MHz!
Text editor powered by tinymce.