i am triying to make a SMPS inverter with Two different chips (TL494), one controlling the low side at 50Khz and one controlling the high side at 50hz. This task is getting difficult because the frequency of one chip affects the other and is not something that results in stable output. So i want to use Arduino (am new at Arduino), i just want to know if IT IS possible to have One pair of the pwm outputs with 50Khz frequency (one being phase shifted respect to the other to drive a pair of mosfets in totem pole configuration) and another pair outputs running at 50hz (again phase shifted). Can Arduino do that without problems? The range of frequencys is too different to make that possible? I would like to use an Arduino Nano because it is chepaer.

  • \$\begingroup\$ No. You need to access the AVR at a lower level to do that. \$\endgroup\$ Sep 8, 2016 at 17:17
  • \$\begingroup\$ How accurately must the PWM signals be 50Hz and 50kHz? Do they need to be adjusted, and if so, roughly how much and what level of precision? Do you need the Arduino to do anything else other than generate the two pairs of PWM signals? \$\endgroup\$
    – gbulmer
    Sep 8, 2016 at 18:12
  • \$\begingroup\$ Not too accurately, in fact i don't plan (at first at least) to have some kind of feedback (for pwm and have a regulated supply). Only that the 50hz stays at 50+-3Hz i'll be fine. The low side (the one with 50khz) doen't need that much precision, the transformers i use seem to be quite independt of frequency as long as i stay in the Khz region. And they do not have to be adjusted, i need them at those values all the time. \$\endgroup\$ Sep 8, 2016 at 19:24

1 Answer 1


The Arduino Nano/UNO hardware could generate two PWM signals, with their complements, at 50Hz and 50kHz. The ATmeg328 contains three hardware timers, which can autonomously produce PWM signals over a reasonably wide range of frequencies.

However, the standard Arduino library does not provide any way to control the frequency of the timers, so you will need to understand how to use them directly. That involves reading the ATmega328 datasheet, and maybe asking questions if you have problems.

The ATmega328's timers are not ideal for this task, but there several practical approaches.

A timer has several parts (simplified a bit):

  • 'Prescaler' divides the MCU clock to produce the basic 'tick' rate
  • Counter which , in combination with the prescaler, sets the fundamental frequency of the PWM signal. Ideally the counter can be reset at any count value so that, in combination with the prescaler, it can generate any frequency.
  • Compare/Match register which sets the PWM signals ratio of High to Low, and so produces the signal for the Waveform Generator
  • Waveform Generator which interprets the Compare/Match signal to set an output pin High or Low, and hence whether the output follows the Compare/Match signal, or is instead its complement.

The ATmega328's timers are not ideal. Either they can

  1. generate complementary outputs, but only for disjoint frequencies, i.e. it can't produce every possible frequency, there are 'holes' in the frequency range, or
  2. generate a better (smaller holes) range of frequencies, but for only one output pin.

As long as their isn't much else happening, issue 2 can be overcome by using interrupts to trigger software to set the complementary output pins. The amount of error ('jitter') can be removed when their is no other (interrupt driven) processing. The disadvantage of this approach is, if you want to add extra processing, or even just debugging messages, the jitter may increase significantly. My interpretation of your acceptable levels of drift or jitter is that this should still be okay as long as you don't rely on debugging messages.

If you have familiarity with MCUs and C/C++ programming in general, and are only new to Arduino, then you might want to get a better MCU, with better timers for the job. If this is the case, and you want a small form factor, I'd recommend looking at mbed compatible MCU development boards. Mbed has a harder-to-use IDE and library than Arduino. However, it gives much better access to the hardware of much better MCUs.

As a concrete example, look at ST Micro Nucleo-32. They can do everything you can do with Arduino Nano hardware, and much more. They are longer than an Arduino Nano, but have a very similar pin-out. ST Nucleo-32 are ARM CPUs, and have much better timers, which should not only be able to generate those PWM signals with a small error (better than +/- 0.1% for 50kHz) but will be autonomous, so no jitter. Some ST parts have timers which can generate 'dead' time between the complementary signals, which may be useful. All have ADC about 100x faster, or better, than an Arduino Nano (Nano is worse than 10k samples/second). Some also have several analogue comparators and DACs, so generating a feedback signal may be much easier too.

  • \$\begingroup\$ Wow that was really helpful. I will try to get that ST Nucleo you recomended, and try the arduino since i don't need any debugging messages or so, so thank you very much. \$\endgroup\$ Sep 11, 2016 at 2:56

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.