Electronic – arduino – ATtiny85 and high frequency PWM for driving a ferrite transformer

arduinoattiny85ferritepwm

Some background: I have an ATtiny85 running at 8 MHz under the Arduino IDE. I have been gifted a large ferrite transformer and some MOSFETs & drivers to drive it. However I am lacking a suitable PWM signal to actually make it work. I tried using analog write, however the current quickly got out of control due to the switching frequency simply being far too slow.

I know a little bit about programming here and there. I've also worked with the Arduino Uno, which I am also using as a programmer for the ATtiny. However I have a limited understanding of the inner workings of microprocessors. So I looked for a library to make all of this work, and I found this:

https://github.com/micooke/PWM

However, I am still unsure how to actually make this work, or adjust the pulse width with a potentiometer. Think a 4047 with a deadlocked frequency, but with an adjustable pulse width. To keep it simple I don't have a clue how to make this work, and it is driving me crazy.

Best Answer

In an ATtinyXX there are two timers. Timer0 can be clocked at the same CPU frequency, by setting the corresponding bits (see below) in the TCCR0B (for timer 0).

At 8 MHz and 8 bit, the PWM will have a frequency of \$\frac{8\ MHz}{2^8} = 31.25\ kHz\$.

Timer 1, instead, can be also clocked by the PLL (up to 64 MHz), which multiplies the internal frequency by 8, yielding a maximum frequency of \$\frac{64\ MHz}{2^8}= 250\ kHz\$.

Here's the timer 0 control register B:

Enter image description here

And here's the CS0x setting table:

Enter image description here

Here's the timer 1 control register:

Enter image description here

There you must set the correct clock prescaler value according to the table:

Enter image description here

To enable PLL you must set bits PCKE and PLLE in PLLCSR.

Enter image description here

Related Topic