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:


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.

  • 1
    \$\begingroup\$ 1) define what you mean by "High Frequency PWM", 1 kHz, 100 kHz , 1 MHz? Any uC has certain limitations. Be aware of those limitations before you want something from a uC, it might simply be unable to deliver. I have a limited understanding of the inner workings of microprocessors I do not see how that is relevant, being able to use it does not mean you need to know how it does what it does. I don't have a clue Well, get the clue then, look for projects which use a potmeter and a uC, learn how they read out the potmeter. Look at projects using PWM, see how they do it. \$\endgroup\$ – Bimpelrekkie Sep 22 '17 at 7:05
  • \$\begingroup\$ The default PWM frequency of the Arduino library is somewhere around 400Hz at 8 MHz clock freq IIRC. To go higher, you need to start manipulating the registries directly, and then you might as well abandon AnalogWrite altogether and use the registries to set the duty cycle as well. Take some time to study the datasheet. That part is gonna take you at least a few hours. Maybe days or weeks, depending on how quickly you are able to find, absorb, and organize the information therein. \$\endgroup\$ – Dampmaskin Sep 22 '17 at 7:11
  • \$\begingroup\$ According to my friend 32khz is around what I am looking for. \$\endgroup\$ – Atton Mathews Sep 22 '17 at 7:50
  • \$\begingroup\$ How do you plan to drive the MOSFETs from your Arduino? What topology? Do you know the parameters of your transformer? \$\endgroup\$ – winny Sep 22 '17 at 8:04
  • \$\begingroup\$ @MarcusMuller XY problem? \$\endgroup\$ – winny Sep 22 '17 at 18:22

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

  • \$\begingroup\$ Well that looks like fun \$\endgroup\$ – Atton Mathews Sep 22 '17 at 8:03

There is a fairly good "turn-to" PWM chip that can have its oscillation frequency set with a resistor and it has a 0 to 1 volt dc control voltage to give you 0% to 100% on the PWM output: -

enter image description here

I have a limited understanding of the inner workings of microprocessors

This is a good starting point if you have a DAC output that can generate the control voltage.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.