Pages: 1 ... 3 4 [5] 6   Go Down
Author Topic: SOLVED How to generate SINE PWM SOLVED  (Read 6111 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Polymporph.
Quote
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...
Logged

Canada
Offline Offline
Sr. Member
****
Karma: 13
Posts: 423
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Electricity is really just organized lightning - George Carlin

Offline Offline
Full Member
***
Karma: 1
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?


Code:
#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
   
     }
     }
 
}
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 618
Posts: 33945
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Quote
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.
« Last Edit: March 20, 2014, 03:47:10 pm by Grumpy_Mike » Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12048
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

[ I won't respond to messages, use the forum please ]

Canada
Offline Offline
Sr. Member
****
Karma: 13
Posts: 423
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
« Last Edit: March 20, 2014, 01:08:58 pm by dlloyd » Logged

Electricity is really just organized lightning - George Carlin

Lacey, Washington, USA
Online Online
Edison Member
*
Karma: 155
Posts: 2337
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

30 to 80kHz sine wave? How fast is this turning? How many poles?

Did you really mean 30 to 80kHz clock for the PWM?
Logged

Steve Greenfield AE7HD
CET Consumer Electronics and Computer
Please don't read your attitudes into my messages

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 618
Posts: 33945
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Anyhow, I've successfully used Complementary PWM on the Due with PWM frequency of 15KHz and duty cycle resolution of 5600.
@dlloyd
This is like DC compared to what he is after.


Quote
30 to 80kHz sine wave? How fast is this turning?
At one cycle per revolution its - 4,800,000 RPM

Quote
Did you really mean 30 to 80kHz clock for the PWM?
No he meant it for the final waveform so the PWM is much faster than that.
« Last Edit: March 20, 2014, 04:33:23 pm by Grumpy_Mike » Logged

Canada
Offline Offline
Sr. Member
****
Karma: 13
Posts: 423
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This is like DC compared to what he is after.

Yeah, but what about the Due's embedded 480 MHz PLL?? (kidding).

For the longest time I was trying to figure out the term "SINE PWM" ... the best I could come up with is the process of taking a sine wave, then chopping it using PWM (with constant duty cycle), then filtering it to get a smaller sine wave. But as it turns out, it's kind of like the term "Amps AC" (Amps Alternating Current).
« Last Edit: March 20, 2014, 05:12:58 pm by dlloyd » Logged

Electricity is really just organized lightning - George Carlin

Canada
Offline Offline
Sr. Member
****
Karma: 13
Posts: 423
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@so3ody, It really seems that you're trying to develop a VFD (variable-frequency drive). If so, this really is one huge project. You've mentioned that you're not concerned with hardware now, but the hardware (type of motor and drive AC-AC, DC-AC, etc) will greatly affect the software required to control it. Take a look here.
« Last Edit: March 20, 2014, 09:04:09 pm by dlloyd » Logged

Electricity is really just organized lightning - George Carlin

Offline Offline
Full Member
***
Karma: 1
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@
dlloyd

I just want to get 3 PWM SINE waves with variable frequency and duty cycle... this is almot a standar part of any ac motor driver..
Logged

Lacey, Washington, USA
Online Online
Edison Member
*
Karma: 155
Posts: 2337
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What frequency is the drive - not the PWM, the drive frequency. The final resulting sine wave frequency.
Logged

Steve Greenfield AE7HD
CET Consumer Electronics and Computer
Please don't read your attitudes into my messages

Offline Offline
Full Member
***
Karma: 1
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi thanks for your reply. I actually wanted a variable frequency  between 30 and 80 KHz but after discussions here in this forum  I read that its not possible so I still dont know

what is actually the possible frequncy rang with arduino due ? sorry im really new dealing with arduino due and with microcontroller

Thanks in advance
Logged

Canada
Offline Offline
Sr. Member
****
Karma: 13
Posts: 423
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Due's clock is 84Mhz.

For 30 KHz PWM clock, you will have 2800 possible values for duty cycle (30K x 2800 = 84 MHz).
For 80 KHz PWM clock, you will have 1050 possible values for duty cycle (80K x 1050 = 84 MHz).

There's more than enough resolution to generate a sine wave, but one of the problems in your code its using 16-bit duty cycle resolution which is out of range of what's possible.

For 80 KHz PWM clock, the maximum value you should use for pwm_write_duty is 1050.
Logged

Electricity is really just organized lightning - George Carlin

Offline Offline
Full Member
***
Karma: 1
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@
dlloyd

Thanks for your reply. I will try to change the resoultion to get it to 32 bit.

But I still have the problem that I cant vary the pwm filtern output frequency when I add the sine wave array to it. It just doesnt work anymore

Its cause my 3 loops which are  for the 3 waves..the compiler reply them all the time ..can I make it in a nother way but without delays ?
Logged

Pages: 1 ... 3 4 [5] 6   Go Up
Jump to: