Pages: 1 2 3 [4] 5   Go Down
Author Topic: DUE PWM Frequency  (Read 19177 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 124
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the AVR has so-called "accurate PWM mode" to facilitate this h-bridge control (pulse is always centered around a unique determined point in the PWM period). it seems the Due's SAM has what Atmel call "complementary" mode. this is only available on the four PWM pins. the other pins are called TC (Timer/Counter) and do not feature complementary mode.

btw. . changing TC_FREQUENCY does not  mess up delay() or micros(). i'm a happy man smiley

Logged

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

shit this sounds complicated to drive an h bridge with arduino due
Logged

0
Offline Offline
God Member
*****
Karma: 25
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Usually H-bridge driving is done with a pair of PWM signals that have a "dead time" between them, rather than the overlapping "phase correct" type of signal on 8 bit AVR chips.

But then, who knows what's really needed here.  There's very little accurate description and a lot of complaining, which is hardly a good approach to asking for free tech support / help on a forum!
Logged

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

Hi thanks for your reply


I want to genrate 3  SINE PWM  signals with a variable duty cycle and frequency. Each one of the three signals shall be 120 degree in phase to the other one.

I hope I could explain what I actually need
Logged

0
Offline Offline
God Member
*****
Karma: 25
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Is that really all you need?  Just a moment ago you threw in a H-bridge requirement, but without specifying what signals it needs.

Maybe you really need 6 waveforms, with some sort of non-overlapping dead time?
Logged

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

yes to drive an asynchron motor you need 3 sine pwm signals in 120 degree phase shift
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Generating the sinewaves is pretty simple.
You need to generate a look-up table (simple array) with the sine values, and then do analogWrite(pin, value).
Code:
//Sinus lookup table
static int sinusTabelle[255] =
{
  128,131,134,137,141,144,147,150,153,156,159,162,165,168,171,174,177,180,
  183,186,189,191,194,197,199,202,205,207,209,212,214,217,219,221,223,225,
  227,229,231,233,235,236,238,240,241,243,244,245,246,248,249,250,251,252,
  252,253,254,254,255,255,255,255,255,255,255,255,255,255,255,255,254,254,
  253,253,252,251,250,249,248,247,246,245,243,242,240,239,237,236,234,232,
  230,228,226,224,222,220,218,215,213,211,208,206,203,201,198,195,193,190,
  187,184,181,179,176,173,170,167,164,161,158,155,152,148,145,142,139,136,
  133,130,126,123,120,117,114,111,108,104,101,98,95,92,89,86,83,80,77,75,
  72,69,66,63,61,58,55,53,50,48,45,43,41,38,36,34,32,30,28,26,24,22,20,19,
  17,16,14,13,11,10,9,8,7,6,5,4,3,3,2,2,1,1,0,0,0,0,0,0,0,1,1,1,2,2,3,4,4,
  5,6,7,8,10,11,12,13,15,16,18,20,21,23,25,27,29,31,33,35,37,39,42,44,47,
  49,51,54,57,59,62,65,67,70,73,76,79,82,85,88,91,94,97,100,103,106,109,
  112,115,119,122,125
};
Now since a three phase motor requires 120° phase shift, i did the following:
Define three counters (a, b, c) with a = 0, b = 85 and c = 170.
360° / 3 = 120°. Therefore 255 / 3 = 85. So if a looks at array position 0, b looks at  85 and c at 170, they are exactly 120° phase shifted.

Now you need a loop like
Code:
void loop()
{
analogWrite(PhaseU, sinusTabelle[a]);
analogWrite(PhaseV, sinusTabelle[b]);
analogWrite(PhaseW, sinusTabelle[c]);
a++;
b++;
c++;
if (a == 255), a = 0; //255 can be changed for whatever amount of samples is used in the sine look-up table
if (b == 255), b = 0;
if (c == 255), c = 0;
delayMicroseconds(X); //Factor X can be used to change frequency of the sine wave
}

/*If you also want to adjust the amplitude, you can add a divider in the analogWrite function.
For example */
analogWrite(PhaseU, sinusTabelle[a] / 2); //This would half your amplitude
Maybe someone with better programming skills could make it a bit neater. I am not really a good programmer, but the code works.
Logged

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

@Ewoodster
This guy is a bit of a time waster, he keeps asking the same questions and never ever states what his requirements are.
Over in this other thread we got to that sort of code you posted.
http://forum.arduino.cc/index.php?topic=225600.0
He wants to do the same thing but we managed to squeeze out of him that he wants an 80KHz sin wave made from PWM signals. He refuses to believe it can't be done.
You will also note that he refuses to believe that the only way of changing the frequency is to change the number of samples or change the sample rate, he insists there is another way but unsurprisingly does not know what it is.
Logged

0
Offline Offline
God Member
*****
Karma: 25
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This guy is a bit of a time waster, he keeps asking the same questions and never ever states what his requirements are.

Yes, you're absolutely right.  Many people ask questions in this very ineffective style, but this guy is particularly bad.

I keep hoping to find a way to impress on people like this how to better ask their questions.  Sticky threads help a bit, but obviously some people do not read them.  On the PJRC forum, I've been intending to look into how to edit the HTML templates for the forum, so posting guidelines can appear right above the text entry box when starting a new thread, and perhaps a reminder can appear right next to the button to submit the message.

These people not only ruin their own chances for getting useful help, but they waste a LOT of time from everyone else... time that could be better spent actually helping people who've posted sincere questions with adequate detail.

@so3ody - If you're still reading this, *why* have you posted so many questions with so little detail?  You seem to want help with your PWM waveforms.  Can you see how your poor writing has ruined your opportunity for good answers from knowledgeable and helpful people?  What words or messages might have inspired you to write better questions?

If anyone has any other ideas about what arrangements of pixels might somehow inspire people like this to write better questions, I'm really, really interested to hear.  It's a tough problem, and perhaps can never be fully solved, but even small improvements could really help a lot of people in the long run.
« Last Edit: March 21, 2014, 06:35:46 pm by Paul Stoffregen » Logged

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

Why Im  a time waster..
I asked questions and I posted the results but I still have some problem...And my post here wast older than the other post..As I didnt get any answer here I just asked a new question..I posted last week some results ! Thanks anyway..Im just new in dealing with arduino !
Logged

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

Quote
@so3ody - If you're still reading this, *why* have you posted so many questions with so little detail?  You seem to want help with your PWM waveforms.  Can you see how your poor writing has ruined your opportunity for good answers from knowledgeable and helpful people?  What words or messages might have inspired you to write better questions?

Well first of all english is not my mother tongue..

And secondly I just wanted to solve my problems in small steps this is why I didnt say from the bgegninning all what I need.. I thought that It could be a good way solving my problem..
Logged

0
Offline Offline
God Member
*****
Karma: 25
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

.... wanted to solve my problems in small steps this is why I didnt say from the bgegninning all what I need.. I thought that It could be a good way solving my problem..

What words or images could have shown you the error of this assumption?

When someone else comes here with questions and again would make this same mistake, how could this forum (or similar technical forums on other sites) instruct people to ask their questions in a more effective manner.

Obviously, this lengthy "How to use this forum" page did not help.  Did you ever see that page, or read it, before posting?  What could have helped you to understand the proper way to ask technical project questions?
Logged

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

Ok I will ask my questions  with more details esc.. Sorry for bothering anyone
Logged

0
Offline Offline
God Member
*****
Karma: 25
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You did not answer my question.

I want to improve how new people, like you (only days ago), see forums *before* posting their first question.  If you had known this before writing all those questions, you could have received better answers and avoided wasting so much time from the most knowledgeable and helpful people.

The question: how can these forums help new people, like you, to post better questions?

Please, consider you have consumed so much time from so many people.  The least you could do is offer a little help to improve the process for everyone in the future.

What could have shown you, only a few days ago, how to ask a better question *before* you wasted everyone's time?
Logged

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