SOLVED How to generate SINE PWM SOLVED

fewer sampels= lower resoultion of the sine wave

Sure but what does it matter if as you say:-

cause I will actually uses the signals to drive an H bridge.

So why even bother with a sin wave anyway because the h bridge will turn that back into a square wave so you might just as well have a square wave driving your bridge.

The current will be about 2A.

Well filtering the direct drive square output is not going to be very cheap, I am not sure if you have thought this through.

I haven't been following this thread much, but if you're trying to drive a three phase motor, you need three equally spaced phases to do it. The Arduino due will only give you two.

Variable frequency drives very the frequency Of three sine wave generators. They do not actually use PWM.

My advice is to change the motor to a single phase or DC motor. Or get a external Sine wave generator that will produce three Phase.
Joe.

promacjoe:
I haven't been following this thread much, but if you're trying to drive a three phase motor, you need three equally spaced phases to do it. The Arduino due will only give you two.

Variable frequency drives very the frequency Of three sine wave generators. They do not actually use PWM.

My advice is to change the motor to a single phase or DC motor. Or get a external Sine wave generator that will produce three Phase.
Joe.

Sorry, you have not been reading the thread. We are using PWM here to create a sin wave, we are not using PWM to directly drive the motor.
While there are only two DACs in the Due you can use the PWM pins to create an analogue output.

@Gumpy_Mike

So why even bother with a sin wave anyway because the h bridge will turn that back into a square wave so you might just as well have a square wave driving your bridge.

Well I need a pwm signal to drive my h bridge. The output of my H bridge will be filterd in order to generate a sine wave. The 3 sine waves will control a 3 phase motor.

So now you know what I mean

So as I asked before is it possible to vary the frequency of the sine waves in a better way than the index items ??

Thanks in advance

Well I need a pwm signal to drive my h bridge.

No you do not drive a h-bridge with a sin wave.
You might drive a class B amplifier but not a H-bridge.

So now you know what I mean

No, you seem to have driving circuits confused.

So as I asked before is it possible to vary the frequency of the sine waves in a better way than the index items

Only that and the delays. Over what range do you want it to vary?

Not sure exactly what you're trying to do, and from what I have read not many that has responded understand it either.
I do know that PWM Voltage control is directly related to the current draw Versus the current input in the circuit. The voltage is maintained by maintaining the current input.
Not directly regulating the voltage.

There are ICs out there that I believe will do what you need. This one might work for you.
http://www.ebay.com/itm/FCM8282-x2-3-Phase-Sinusoidal-Brushless-DC-motor-controller-FCM8282QY-/181228852417?pt=LH_DefaultDomain_0&hash=item2a3214d4c1.

Note: I have no information on this chip other than what the website gives me. This is just an example of what is out there. And at that price it should be cheap enough to experiment with.

Hope this helps.

Joe.

promacjoe:
Not sure exactly what you're trying to do, and from what I have read not many that has responded understand it either.
Joe.

Hi Joe, op is trying to control a three-phase AC induction motor. All very possible and a fun project. Many who have read it probably did not bother responding because of the beginner nature of the discourse.

As you have observed there are dedicated chips (you referenced a BLDC controller). But what is the fun of that?

IMO, the types of people that were playing with Holley 600 four-barrel carburetors in the 1970's are playing with just this type of circuit today. The GM EV1, Tesla Roadster, and Tesla Model S all have 3-phase AC induction motors with this type of controller.

Additionally, white goods (household washing machines, dryers, etc.) can be made better and cheaper with this same technology (Example, Whirlpool Duet runs on 120VAC, has a three phase 200V AC induction motor, ebay cheap).

Additionally, advanced features include software reverse (just swap two phases). Regen mode (software controlled generator).

I understand the fun of hacking something to do something else. Your mention of the Holley carburetor is not really applicable, since the Holley carburetor was designed to do one thing, deliver the proper amount of fuel versus air mixture.. No matter how much you tweak it, it does the exact same thing as it was designed to do. Nothing more.
No microcontroller can be all things to all needs. There's always going to be something that it needs help with. And that's all I'm suggesting.

Even if he does not use a chip of this type, if this type of control is what he needs, At least we will better understand what his needs are.

Joe.

Grumpy_Mike has this well-in-hand.

Drive the H bridge drives with the PWM signals directly. Don't filter anywhere. Let the inductance of the motor windings and the mechanical inertia of the rotor filter it.

promacjoe:
I do know that PWM Voltage control is directly related to the current draw Versus the current input in the circuit. The voltage is maintained by maintaining the current input.
Not directly regulating the voltage.

No that is not what PWM is at all!

It stands for pulse width modulation and the average voltage is controlled by turning a signal on and off. It has absoloutly nothing to do with current.

If you would like to know what it is then please read this:-
http://www.thebox.myzen.co.uk/Tutorial/PWM.html

@ Grupy Mike

So why even bother with a sin wave anyway because the h bridge will turn that back into a square wave so you might just as well have a square wave driving your bridge.

Well its a standard way to drive an asynchronus machine. It will be a big project to. I will have to drive a 3 phase motor due to the Field oriented control method... but firestly I have to start.

My H bridg will be driven with normal PWM signals. But if you drive a motor @ 30 KHz with a square wave like pwm you will have losts esc.. this is why I will filter the output of my H brigde to get a sine wave.

I hope that you understand now what I mean

This is why I look for a better way to vary the frequency of the sine wave than delay or less sine items

I hope that you understand now what I mean

I do, but I don't think you understand the consequences of trying to filter a signal with such a current drive with a capacitor.

But if you drive a motor @ 30 KHz with a square wave like pwm you will have losts

Do you mean losses? You always have losses driving anything magnetic, get over it.

This is why I look for a better way to vary the frequency of the sine wave than delay or less sine items

You still have not said what range of frequency you need. I am assuming that it isn't going fast enough for you.
The only other way with the technique of using a processor to do the generation is to vary the clock frequency, but you don't want to go there for many reasons. Or you could get a faster processor.

It looks like using a Due is a dead end for your project.

@Gumpy_Mike

You still have not said what range of frequency you need. I am assuming that it isn't going fast enough for you.
The only other way with the technique of using a processor to do the generation is to vary the clock frequency, but you don't want to go there for many reasons. Or you could get a faster processor.

It looks like using a Due is a dead end for your project.

The range of my sine wave should be between 30 KHz and 80 Khz

Its is possible with the due but I just dont know the technique I can make it with

Look up "magic sinewave" by Don Lancaster. Oh, heck, here is the link:

The idea is that it is an already encoded PWM, done in such a way that nearly all the frequency components outside of the fundamental sine wave are far above the fundamental frequency and therefore easier to filter.

I am wondering if eddy current losses will be enough of an issue to go to the trouble of filtering.

@Polymporph.

I am wondering if eddy current losses will be enough of an issue to go to the trouble of filtering.

I dont care about the hardware at the moment...

The range of my sine wave should be between 30 KHz and 80 Khz

This would most likely be the switching frequency of the PWM. There would be a hidden, "modulated" sine wave that would appear after appropriate filtering. The sine frequency would be much lower ... i.e. 50 to 60 Hz and would depend on the update rate of the PWM duty cycle.

Its is possible with the due but I just don't know the technique I can make it with

You're correct that its possible with the Due, but at this stage you're only at the tip of the iceberg.

Note that the Due has 2 types of PWM outputs. The type you are using has a single pin for each PWM and can be controlled using Arduino commands.

For your project, I'm quite sure you'll need to use the complementary PWM outputs, which are driven in pairs (PWMH0,PWML0), (PWMH1,PWML1), (PWMH2,PWML2), etc. These cannot be controlled using the existing Arduino commands. A library would need to be developed that involves controlling the required SAM3X registers and providing new functions. Also, a main consideration would be the shoot-through or dead-time specification for the H-bridge module or circuit. Another consideration would be understanding the power losses involved and filter requirements.

I noticed now that my programm is wrong. Without the sine look up table every thing works and i can generate 3 pwms with variable duty cycle and frequency... but when I add the sine look up table it dosent work anymore. I believe its cause my for loops just work all the time...I thinkg that my sine wave and my pwm ar not cuppeld together some how can anyonhelp me ?

#include "pwm01.h"



int sine[] = {2048,2305,2557,2802,3034,3251,3449,3625,3777,3901,3995,4059,4092,4092,4060,3996,3902,3778,3628,3452,3254,3037,2805,2560,2308,2051,1795,1542,1297,1065,847,649,473,321,197,102,37,4,4,35,99,193,316,466,642,839,1056,1288,1533,1785,2041};

static int k = sizeof(sine)/sizeof(int)/3; //length of the sine table =51 
static int j= k*2; //(2/3)*50 length of the sine table
//static int test= sizeof(sine)/sizeof(int) ;



void setup() 
{
   // uint32_t  pwm_duty =0.5* 65535;//2^16=65536
    uint32_t  pwm_freq2 = 30000;

    // Set PWM Resolution
    pwm_set_resolution(16);  

    // Setup PWM Once (Up to two unique frequencies allowed
    //-----------------------------------------------------    

    pwm_setup( 7, pwm_freq2, 2);  // Pin 7 freq set to "pwm_freq2" on clock B
    pwm_setup( 8, pwm_freq2, 2);  // Pin 8 freq set to "pwm_freq2" on clock B
    pwm_setup( 9, pwm_freq2, 2);  // Pin 9 freq set to "pwm_freq2" on clock B
      
    // Write PWM Duty Cycle Anytime After PWM Setup
    //-----------------------------------------------------    
   // pwm_write_duty( 7, pwm_duty );  // 75% duty cycle on Pin 7


   // delay(30000);  // 30sec Delay; PWM signal will still stream
        
    // Force PWM Stop On All Pins
    //-----------------------------    
 
 /* pwm_stop( 6 );
    pwm_stop( 7 );
    pwm_stop( 8 );
    pwm_stop( 9 );*/
}

void loop() 
{  
  while(1){
   for(int i = 0; i<50;i++){
    pwm_write_duty( 7, sine[i]*16 );  // 16 is a factor to improve the resoultion of the sine wave
    pwm_write_duty( 8, sine[(i+k)%51]*16);  // 75% duty cycle on Pin 8
    pwm_write_duty( 9, sine[(i+j)%51]*16 );  // 75% duty cycle on Pin 9
    
    delay(5); // The sine wave frequency is determinded in this way Sine index = 51*10 milli seconds delay= 510, Frequncy=1/510
   
     } 
     }
  
}

The range of my sine wave should be between 30 KHz and 80 Khz

OK lets look at that for a moment.
80KHz is a wave every 12.5uS. Then you have 50 samples in your wave so a sample is needed every 0.25uS.
If you have 12 bit samples that that is 4096 divisions of time in the PWM.
That means each division of time will be 0.25 uS / 4096 = 61.03 pS per division of time.
This translates into a PWM clock of around 16 GHz which for an 80MHz processor is a bit outside what it can be done.

Its is possible with the due but I just dont know the technique I can make it with

Do you watch the Simpsons? As Nelson Muntz would say Har Har

What ever 'it' is it is not PWM.

Why are you looping for 50 iterations when the sine table is length 51?

What ever 'it' is it is not PWM.

The OP has already seen and copied code from reply#8 here. This example is only the initialization part of some of the Complementary PWM outputs available on the Due. I'm interfacing the Due with this module. The example is part of an incomplete project that is a programmable AC power source, but the module can be used in many applications, including motor control.

Anyhow, I've successfully used Complementary PWM on the Due with PWM frequency of 15KHz and duty cycle resolution of 5600. Using a sine table of length 9000 (one quadrant), I am able to control the phase from 0 to 360 deg with 0.001 deg resolution. The dead time was matched to the module specification of 2 us.

Note: For the Due, if the Complementary PWM frequency is changed to 30 KHz, the maximum duty cycle resolution would become 2800. Pwm01.h is not used as it does not configure Complementary PWM.