3
\$\begingroup\$

I'm learning how to use an Attiny84. I've generated a fast pwm signal. I managed to understand how to do this:

#include <avr/io.h>
int main(void)
{
 // setup timer0
 TCCR0B |= _BV(CS00); // use clk_i/O without prescalers as clock source.
 // also enables TIMER0
 // set fast PWM mode
 TCCR0A |= _BV(WGM01) | _BV(WGM00); // Mode 3
 TCCR0A |= _BV(COM0A1) | _BV(COM0A0); // set OC0A on compare match, clear on BOTTOM
 OCR0A = 0xff / 2; // 50% PWM
 // set PB2 as output. This should enable OC0A
 DDRB |= _BV(PB2);
 for (;;) {
 }
}

However, I don't understand why I got only ~30kHz on the scope. I disabled the CKDIV8 fuse and sets my CKSEL to "Calibrated Internal RC Oscillator 8MHz".

I though I could have at least 8MHz PWM frequency. I can't find in the documentation how clk_i/o and clk_cpu are related. Is there any way to gain a higher PWM frequency ?

N.B.: I don't need to have a particular PWM frequency, I'm just testing the chip and trying to understand its boundaries.

Roh
4,6807 gold badges50 silver badges86 bronze badges
asked Oct 12, 2015 at 0:35
\$\endgroup\$

1 Answer 1

8
\$\begingroup\$

You have a 8MHz clock, but 8-bit PWM. This results in a 8MHz/256=31.25kHz output frequency. If you need a higher output frequency then you can use mode 7 instead, at the cost of PWM signal depth.

answered Oct 12, 2015 at 0:40
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.