Attiny85 2kHz PWM

Hi everyone,

I’m trying to use a Attiny85 to interface with a ZIVAN High Frequency Battery charger. For that I need to be able to generat a 2kHz PWM signal.

I have been reading the Attiny85 datasheet and I think it’s possible.

On page 76 you can see that the PWM output frequency can be calculated by the following equation:

fOCnxPWM=fclk_I/0/(N*256)

being N the prescale factor (1, 8, 64, 256 or 1024).

On page 83

you can change this prescaler to clkI/0/8

using:

TCCR0B = TCCR0B & 0b11111000 | 0b010 ;

This means if your clock speed would be 4Mhz you would get a +/-2kHz PWM signal.

On page 34

you can select the clock division factor. Knowing that the attiny85 has an 8MHz internal resonator selecting a division factor 2 would get you the 4MHz needed.

But I don’t know if this is possible or how to change this division factor.

So, if anyone could help me I would appreciate it.

Thanks

Which core are you using?

How accurate does the 2 KHz need to be?

What resolution?