Okay I am trying to get at a frequency above 60k with an Attiny85 and programming it with an uno.
I couldn't figure out how to do that, so I settled for doing it with the uno.
I found this code :
void setup() {
pinMode (3, OUTPUT) ;
TCCR2A = 0x23 ;
TCCR2B = 0x09 ; // mode 7, clock prescale by 1
OCR2A = 50-1 ; // 160 clock periods = 10us per cycle
OCR2B =0 ;
TCNT2 =0 ;
}
void loop() {
// put your main code here, to run repeatedly:
analogWrite (3, 25);
}
It worked incredibly well, and I was able to get a pwm output with 330 kHz!
I need some help understanding it please.
In the past, I would use a line like "TCCR2A = TCCR2A & 0b11111000 | 0x01" or something to change the frequency, but I could onyl get around 4 kHz. I know this has a bit to do with the prescaler.
My question is this: why did the author of this code use OCR2A and TCNT2? What do these mean?
Also, does anyone know how to edit the code to make it suitable for an Attiny85 with an internal 20 MHz clock?
I tried changing the timers to TCCR0A because that is which timer controls the output pin im using on the ATtiny85.
Thanks!