I am having two problems concerning interrupt handling on my attiny45, using an Arduino UNO r3 as an ISP.
My intention is to drive a piezo-speaker through the PWM-output on PIN PB1 (equals PIN 6 as a hardware-pin). When driving the Attiny45 with a 1Mhz clock, the frequency of the PWM output is around 60Hz, when clocking it at 8Mhz it equals roughly 480Hz (around 8 times more i guess ;)).
Now I want to drive my speaker at a frequency that I want to be able to influence. That is why I read through some pages of the datasheet for setting the PWM Timer (should be timer1):
As a prescaler I chose 256, which results in ~4kHz @ 1Mhz base clock and a compare register size of 0, which should be reset at the desired frequency (ctc mode enabled).
Now this is the code I am using to set the timer up:
TCNT1 = 0; // reset counter to 0 TCCR1 = 0; // reset tccr, I was having severe problems with timer interrupts when not doing this! TCCR1 |= (1 << COM1A1) | (1 << COM1A0) | (1 << PWM1A) | (1 << CTC1) | (1 << CS13) | (1 << CS10); // [b]COM1A1 and COM1A0[/b], each set to "1": // OC1x Set on compare match. Cleared when TCNT1= $00. (NOT)OC1x not connected. // PWM1A: Should enable PWM based on comparator OCR1A // CTC1: Clear counTer on Compare ;) // CS13/CS10: Set Prescaler to 256 OCR1A = 0;
Now I am still getting 60Hz/480Hz of PWM output on my desired output pin. Where lies the problem?
When using “attachInterrupt(interrupt, function, mode)”, which pin is that interrupt assigned to? Can any pin be used as an interrupt pin? Judging by the pin layout given in the datasheet it seems as though all pins could be assigned intterupt functionality…
Thanks in advance!