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.
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
- 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
- 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.