Go Down

Topic: Can Arduino output 20kHz PWM with varying duty cycle? (Read 3235 times) previous topic - next topic

dawnzh

Aug 20, 2013, 03:37 am Last Edit: Aug 20, 2013, 02:55 pm by dawnzh Reason: 1
Hi,
I am trying to control a full bridge IGBT inverter from PC. I am not sure whether I can use Arduino as my interface.
I need to output 6 PWM waves at 20kHz to switch the IGBT module. And the PWM waveform has different duty cycle for each period. The waveform are shown in the attachment.
I also need two analog inputs that can read 20kHz signal as feedback loop.

Does anyone know for sure whether arduino is capable of doing that?

Thanks in advance.

Nick Gammon

You could do three easily enough on the Atmega328 (it has three timers). I'm not sure about 6 different outputs. Why six?

http://www.gammon.com.au/forum/?id=11504
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

dawnzh


You could do three easily enough on the Atmega328 (it has three timers). I'm not sure about 6 different outputs. Why six?

http://www.gammon.com.au/forum/?id=11504



Thank you very much for your reply. I am controlling 6 IGBT full-bridge power module, so I need 6 PWMs to control each IGBT. Do you think there is any other version of Arduino board that can output 6 PWMs? Or is it better to use 2 boards?

Nick Gammon

Do they each need a different duty cycle?

If 31.25 kHz is acceptable you have access to 6 counters on the Atmega328 (eg. the Uno) because they count up to 256 in certain modes and then you just control the duty cycle. In this case you have a resolution of 256 in the duty cycle (ie. you can vary in lots of 1/256).

Or you could run at a lower clock speed and have a 15.625 kHz frequency.

Quote
Can Arduino output 20kHz PWM with varying frequency?


Do you mean varying frequency or varying duty cycle?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

tmd3

I think that you're developing a variable-voltage, variable-frequency, three phase power supply, akin to a variable-frequency drive for a motor.  Is that what you're working on?


dawnzh


I think that you're developing a variable-voltage, variable-frequency, three phase power supply, akin to a variable-frequency drive for a motor.  Is that what you're working on?




Yes, I am. But I am not progressing well. Do you think Arduino Uno is enough as my interface? Thank you.

tylernt

#6
Aug 21, 2013, 05:31 pm Last Edit: Aug 21, 2013, 05:34 pm by tylernt Reason: 1
According to this:
http://playground.arduino.cc/Main/TimerPWMCheatsheet
You can have 62.5kHz, 31.25kHz, 7.8kHz, or 3.9kHz with the stock Arduino 16MHz clock speed.

According to this:
http://arduino.cc/en/Reference/analogRead
analogRead() maxes out at 10kHz for your feedback. But typically you'll want your analog sampling rate to be several times (say, 10 times?) your signal rate to get meaningful information back. For your application, it looks like your analog feedback slowly reacts to the PWM though, taking several PWM cycles to rise and fall? so a 7.8kHz PWM freq with 10kHz analog feedback might just work.

Also, depending on your application, if you don't need to "see" the whole waveform feedback, you may be able to time your sample with each PWM pulse. If you always sample in perfect sync with the PWM pulse, you can get an incomplete (but perhaps complete enough), idea of what's happening on the output.

tmd3

Do you think Arduino Uno is enough as my interface?


Which Arduino?  I think it would be challenging on the Uno.  The Mega, with its plethora of 16-bit timers, offers more attractive options. 

Let's probe.

Safety first:

  • Do you intend to control a motor? If so, what will it be doing?

  • What's the operating voltage?

  • How much power do you intend to deliver?



If your intent is, say, to operate a 25 horsepower fan at 480V, that makes for high voltages, and a lot of available energy.  It's unlikely that you'll get the output right on the first try.  I can envision a bright flash with flying chunks of hot metal, and it's a disturbing image.  I secretly hope that you've located a 12V, 3 watt, three-phase motor for experiments; IGBT's, as opposed to MOSFET's, make me think that you want to control an industrial-sized gizmo.

So tell us:  How will you preserve yourself, the structure you work in, and its other occupants, while you carry out this project?

Technical:

  • What are you hoping to accomplish by reading analog values?  This statement
    Quote
    ... two analog inputs that can read 20kHz signal as feedback loop

    isn't particularly clear.  I suspect that you want to read an AC power-frequency-ish voltage and maybe a current from somewhere.  If you're hoping to identify, say, RMS values of voltage and current from harmonic-rich analog inputs, the calculation burden might be more than the horse can pull.  Can you clarify your analog requirements?

  • What's the source of the 20 kHz requirement?  Looking at Toshiba's industrial VFD's, I find a bunch of them adjustable from 0.5 to 16 kHz, but nothing as fast at 20 kHz.  As Nick notes, 20 kHz is an unwieldy PWM frequency for the Uno.

  • What have you tried so far?


Here's a link to a senior project report from an electrical engineering student at California Polytechnic:  http://digitalcommons.calpoly.edu/cgi/viewcontent.cgi?article=1129&context=eesp.  I think that the CalPoly project is different from the one you contemplate, but not completely different.

dawnzh

Guys, thank you so much for all your replies.

Sorry for not explainning things clear enough.

My project is about designing a current-controlled AC-AC inverter and control this inverter from PC. The inverter is to be used for motor control.It needs to take in 240V, 50Hz wall source voltage as input and output variable frequency (up to 500Hz) voltage at 500V,20A that can be fed into motor.

I am now focusing on  the DC to AC inverter part now.

It consists of a three-phase full bridge IGBT power module which is switched at 20kHz from PC terminal via USB DAQ or stuff like Arduino to control the output frequency.

Certainly, the PC interface will be isolated with the high power IGBT module by opto-isolator.

As for analog input(ADC), I need to measure two phases of the three-phase output current(up to 500Hz ) as feedback at 20kHz.

I need the switching frequency at 20kHz so that the PWM functions which can only output frequency at 31.25kHz are not useful for me.

I have found some functions on this website http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

I am wondering whether I can do it with digitalWrite() and delayMicrosecond. Because I am not sure whether the digitalwrite() is able to give me variable duty cycle 20kHz.

I was working with another board before, but it turns out that it's not able to output PWM with 20kHz.So I have to make sure Arduino can do my job before I spend time on it.

Thank you!

dancombine

Hi,

It's better you access the Timer registers directly, rather than through the Arduino libraries.
That way you have more control.

Suppose you use Arduino Mega, which has 4x 16-bit timers (Timer1/3/4/5). You need 3 timers.
Each timer has 3 OCR registers.
If you use OCRnA as TOP, this sets your frequency.
At 16MHz (=62.5ns), no timer prescaler, and needing 20kHz (=50000ns) PWM frequency, you need to set OCRnA to 800 (=50000/62.5).
This will give you exactly 20kHz.

Per timer, you have 2 compare registers (OCRnA and OCRnB) to control your duty cycle, AND to have the 'compare' output to the designated pins.
Use an ISR() to set your compare registers, as per your desired duty cycle.

-Dan

tmd3

Your question is: "Is the Arduino an appropriate platform for this project?"

I think that the consensus is that the Arduino Mega 2560 can perform the PWM functions that you need.  It has an adequate number of timer/counters with appropriate resolution for your purpose.  You will have to program right down to the bare metal, though - digitalWrite() and delaMicroseconds()won't give you the speed and accuracy that you need for this project.

I don't know that Arduino Mega 2560 is up to your analog requirements, though. 

You say: "I need to measure two phases of the three-phase output current(up to 500Hz ) as feedback at 20kHz."  I don't know what that means.  Do you need to sample two signals 20,000 times a second, or do you need to sample two currents that are generated by a 20 kHz PWM at some lower frequency?    Will you sample the waveforms directly and calculate something, like RMS values?  Will you calculate the error of the system at 20 kHz?

If you really need two analogs at 20 kHz each, there won't be much time to do calculations.  You'll have to update the PWM outputs at 20 kHz, and I figure it will take about 150 processor cycles to save the processor state, manipulate the pointers, fetch the samples, output them, update the phase counter, and restore the processor state.   It'll take about 60 or 70 cycles to manage each analog reading.  At 16 MHz, all this will happen every 800 cycles.  That leaves about 500 cycles, for each pair of analog readings, for calculations at 20 kHz.

You'll also want to consider other analog requirements besides speed.  The AT Mega 2560 has a 10-bit analog to digital converter.  According to the datasheet, it will give 10-bit resolution at 15,000 samples per second.  You need may two values at 20K per second - almost three times that fast.  I think that you can count on getting 8-bit accuracy at that speed, but probably not more.

The answer - whether the Arduino Mega 2560 is adequate for your project - will depend on the particulars of your analog requirements, I think.

selfonlypath

If you need to have a 3-phases or 3 full H-bridge with 6 igbt's at such speed (20 KHz) along with digital PLL (Phase Locked Loop), I think not possible even with arduino mega.

I've been using mega to generate isolated TTL signals controlling full H-bridge, loose coupled flyback ringing at peaks of 800V and 10A at 20 KHz and more thanks to the 16-bit timers but it only works on 2 phases or 2 legs full H-bridge (4 igbt's), requires as suggested by dancombine to directly program the timer registers otherwise forget it.

Even if you forget about the control loop, PLL, it seems the arduino mega timer are not meant to generate 3 phases full H-bridge, maybe arduino due could do it !

Resinator

#12
Sep 08, 2013, 11:40 am Last Edit: Sep 08, 2013, 12:00 pm by Resinator Reason: 1
In a nutshell

8 Bit uC arent really up to the job of motor control its the realm of 32 bit processors  and a 20kHz PWM switching frequency is pretty standard in the drives world

I have built a motor drive with Arduino Uno's in the past but it could only manage an hysteresis drive using hall current sensors and I had to use multiple Uno's one for each leg of the three phase inverter

First tip is to use a gate drive chip with complementary outputs so that only 3 PWM signals are required and the chips also do dead time as a built in feature

Check out HVIC gate drive chips say the IR21834 thats a good choice

If you want to do space vector modulation then you need something like an STM32F4, thats an ideal choice to take fast readings, in my work with AVR's I could get the ADC conversion times down to about 17us which isn't good at all, the STM32F4 has 3 separate ADC's and it takes it in the region of 1-2us (IIRC) to do a conversion

I have space vector modulation functions for different applications both balanced and unbalanced outputs it takes a bit of getting into but it is quite simple once you understand what you need to do, however centre aligned PWM is the method of choice this splits the PWM time period in half so for a 20kHz PWM frequency you need to interrupt and update the modulation index every 25us, its a bit much for an AVR to do anything useful

Measuring high frequency PWM voltages presents its own problems, its quite a challenge of academic interest, in vector drives for instance its common to filter the pulses to smooth them out

I wouldn't attempt to measure the raw PWM pulses but with a motor connected to the output the motor filters the PWM and your left with sinusoid

Really interesting work I love power electronics and drives the theory is very rich, the practical is full off pitfalls and problems, actually switching mains voltages is full of its own problems  and is quite hard to make a PCB to handle such harsh transients, the dv/dt or di/dt stresses are a serious threat, the buzz I get when I overcome these difficulties takes some beating

selfonlypath

The issue is not really 8 bit uC or 32 bit uC when driving 3PH transformer or motor.

Take arduino mega, it is 8 bit uC but it does have few 16 bits timer being similar as independent uC specialized unit or virtual uC. So once you low level or assembly program one of these timers, you have 16 bits precision. In my own projects, got very good results using them on 2 phases power transformer and motor, I mean with few KVARs and KWs at frequency beyond 20 KHz.

The HUGE problem with 3 phase drivers and arduino mega: the 16 bits register command of the mega 2560 are not meant for this but they're really good for 2 phases.

I do have an arduino due, still not tried to look at its timers possibilities and see if I can go after 3 phase power electronic project.

Albert


Resinator

Quote
The issue is not really 8 bit uC or 32 bit uC when driving 3PH transformer or motor.


Not directly I understand what your saying, the timers have the required resolution so as not to introduce nasty harmonics due to stepping when the mod index is changed, the issue comes from execution times 32 bit uC are well adapted to do the advanced maths thats needed in minimum times many have dedicated FPU's to do this

Clock speeds are much faster so the hardware works much quicker, one day when I have spare time I do plan on trying to do SVM with an AVR it would be possible I am sure but its a definite challenge, at 17us per ADC conversion it will be open loop V/Hz control thats for sure

Quote

I mean with few KVARs and KWs at frequency beyond 20 KHz.


But the power rating of the machine thats controlled is irrelevant to the processor, its the hardware (inverter)that has to be man enough to run the machine surely thats a different discussion all together? or did I misunderstand??

Quote


see if I can go after 3 phase power electronic project


What modulation strategy did you use? what strategy would you like to use?


Go Up