Hello! I need a bit of help understanding this code involving timers

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!

Start by reading the Timer2 chapter (Section 18) of the ATMega328P datasheet to understand the function of each register. It might also be helpful to read the sections on Timers 0 and 1. Once you understand how the code works, you can read the Timer sections in the ATtiny85 datasheet and see if they can provide similar capability.

meadsd:
My question is this: why did the author of this code use OCR2A and TCNT2? What do these mean?

In ATmega328P processor of UNO board, there are three TC Timer/Counter Modules which have these hardware symbolic names: TC0, TC1, and TC2 -- Timer/Counter 0, Timer/Counter 1, and Timer/Counter 2.

OCR2A stands for Output Capture Register A of TC2.
TCNT2 stands for Timer/Counter 2 Register which is a software symbolic name for TC2.

The following diagram give you more details on the hardware structure of TC1. Similar things exits for TC0 and TC1.