I have an ATtiny85 and I'm trying to set the clock to 8 MHz. I have read the data sheet and some discussions on how to do this but am not having any luck getting it to work. I have included my code and any help will be greatly appreciated.

#include <avr/io.h>
#include <avr/interrupt.h>

int main(void)
    CLKPR |= 1<<CLKPCE;
    CLKPR |= 0;

    DDRB |= 1<<PINB1 | 1<<PINB0;

    TCCR0A |= 1<<WGM00 | 1<<WGM01 | 1<<COM0B0 | 1<<COM0B1;
    TCCR0B |= 1<<CS00;
    OCR0B = 240;

    TCCR1 |= 1<<PWM1A | 1<<COM1A0 | 1<<CS13 | 1<<CS12 | 1<<CS11 | 1<<CS10; 
    OCR1C = 255; 
    OCR1A = 127;

    while (1)

I do not have a scope, so I'm not able to determine what the frequency of Timer0 is but I know that Timer1 is running at around 61 Hz (prescaler = CK/16384) because I timed the blinking of a led. That would mean that the CK is still at 1 MHz. Not sure what I'm doing wrong here.


Obviously I figure out what I was doing wrong after posting a question. The following changes fixed it.

CLKPR = 0b10000000;
CLKPR = 0;
  • \$\begingroup\$ #include <avr/power.h> clock_prescale_set(clock_div_1); \$\endgroup\$ Oct 11 '13 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.