Does Arduino work for high frequency switching?

Does Arduino work for high frequency switching? Say I want to use arduino for PWM of a mosfet. In simulations project worked with frequencies as high as 330kHz. Can arduino work for such a case.

For AVR based boards (running at 16 MHz) the answer would be yes (I have never tried to modify the PWM frequency).

You will have to manually configure the timers so time to consult the datasheets. I think that there are libraries for the AVR based boards but did not look.

No experience with other boards.

Not for "real" PWM. 16MHz/256 is 62.5KHz. You could try playing around with top and trigger values, but at the cost of fewer steps. I haven't delved into the math, but I doubt you'd get 330KHz no matter how hard you tried.

Edit: fully prepared to eat my words. :slightly_smiling_face:

For the feedback loop in a switching power supply, you can tolerate very little delay in that loop. I think a microcontroller will not be fast enough to work well.

Ok, ill look into that.

yes, that was one of my concerns as well. Ill keep researching more efficient was to perform such operations. Thanks.

A PIO machine on RP2040/ 2350 Wil able to do it

try an ESP32, e.g. PWM using LEDC API three frequencies and duty cycles

330K, I get 48 micros per loop which is very doable on 16MHz AVR chips... a lightly loaded loop() can do that with cycles to spare. Doing nothing but 32-bit counting and once per second print it goes faster and 32-bit ++ may be as much load as PWM.

Run this as is... fast enough at doing something different? Really this sketch is for monitoring slower, sub-100Khz loops. It lets me measure the effect that changes have on in-progress sketches.

In Mode-14 Single-Slope TC1 UNO R3, the equation for PWM signal:
fpwm = clkSYS/(N x (1 + ICR1)) N = 1, 8, 64, 256, 1026; ICR1 = 1 to 65535

* Min frequency = 1 Hz    clkSYS = 16 MHz, N = 1024, ICR1 = 15624 (tested)
* Max fequency = 8 MHz    clkSYS = 16 MHz, N = 1, ICR1 = 1

Using UNO R3 running at 16 MHz, an exact frequency of 330 kHz cannot be achieved! The closest one is: 333.333 kHz or 326.530 kHz and no in-between.

The Arduinos that are based on the ARM SAMD processor like the MKR Zero can do PWM in the 330kHz area no problem, but not exactly 330kHz, if that matters. The resolution won't be 8 bits at that high a frequency, either.

All done in hardware counters using the 48MHz clock source. No load on the processor and not dependent on the speed of the sketch execution.

There's sample code snippets on this forum if you search for the topic.

Nice, as long as frequency is in that range its okay, ill try this suggestion. Thanks

If you need code, pls let me know.

That would be great! It would would really help a lot.

Which Arduino are you using?

Hi. I am currently working on a SEPIC converter design, basically a buck-boost converter. It works with one mosfet for switching, using feedback to control duty cycle of PWM to regulate output voltage. I wanted to use arduino as such feedback yo evaluate output voltage and control switching and duty cycle accordingly. Although code logic can be manageable, a concern I have is that arduina may not work for high frequency switching such as the ones I intend to use and doesnt provide enough voltage to drive mosfet. Is there any way for me to make arduino implementation work such an aditional component or is arduino useless for this type of work because of high frequencies.

Which are? You've done a lot of hand waving and avoided saying anything specific that could reasonable be answered with anything other than "maybe?".

330kHz was the one I used for simulations on Ltspice using a pulse wave generator. Arduino probably will be tricky to implement if it actually works. Its worth the try though.

Yes it is useless.

There are plenty of buck /boost IC’s around that will do the job .