Skip to content

Instantly share code, notes, and snippets.

@valerionew
Created September 3, 2018 18:38
Show Gist options
  • Save valerionew/3b7f3be883065c6469940819f6ff9fe0 to your computer and use it in GitHub Desktop.
Save valerionew/3b7f3be883065c6469940819f6ff9fe0 to your computer and use it in GitHub Desktop.
Blinking a led at 38kHz on an attiny10. Gaining extra precision by swithching from the default :8 prescaler to the :1 prescaler (8MHz clock)
@MCCreeper8890
Copy link

MCCreeper8890 commented Dec 7, 2019

That's a dangerously lightweight program. I might be able to optimize it further into AVR assembly, especially if the halt instruction leaves the clock running.
Although, to be honest, I'm not really sure it would be useful. I'm going under the assumption that OCR0A contains the number of clock cycles needed to toggle PB0. I imagine it would be relatively easy to drop one of the writes to CCP, like so:

LDI r0, 0xD8
LDI r1, 0x00 ;Might not be necessary
OUT CCP, r0
OUT CLKMSR, r1
OUT CLKPSR, r1

could replace four lines in your C++ program:

CCP = 0xD8;
CLKMSR = 0;
CCP = 0xD8;
CLKPSR = 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment