Shop OBEX P1 Docs P2 Docs Learn Events
magic sinewaves — Parallax Forums

magic sinewaves

Tracy AllenTracy Allen Posts: 6,660
edited 2007-02-28 14:21 in Propeller 1
Hi Phil,

continued from Duty mode output to drive Power MosFET or IGBT


Here is one diagram from www.tinaja.com/glib/msinexec.pdf

attachment.php?attachmentid=45607

which shows a 28 pulse waveform, 7 per quadrant. It is efficient for power drive, because there are very few transitions, and that means the driver spends most of its time either full on or full off and very little time in the power wasting transition zone.

Here is another figure from the same document, showing the harmonic content, showing the fundamental (at 60 hertz) and the first significant harmonics at the 29th and above. This is hard to reconcile inuitively with the ON OFF waveform above, but it makes sense that it is made up primarily of a component at roughly 28 times the fundamental. The accomplishment is the fine tuning of the pulse positions and widths to bring those middle harmonics to zero.

attachment.php?attachmentid=45608


Phil Pilgrim (PhiPi) said...
Regarding the "magic sinewaves" approach: I wonder if it's really necessary to analyze the goodness-of-fit in the frequency domain. It seems like it might be easier to model the lowpass filtering (first-order IIR, at least) in the time domain and use a sum-of-squares error function to determine fitness.

Modelling in the frequency domain does have the advantage of not having to consider the filtering until after the fact, but computing the error function for each candidate pulse stream is more computationally complex.

-Phil

The fact that the analysis can be done without considering the filter parameters is why Don Lancaster chose to do it that way. The calculations are complicated, but Don has gone to all that trouble for us! What a great guy. I practically learned electronics from the TTL and CMOS Cookbooks. Don lays out the theory, but then he makes it easy with his Javascript calculators. I wish I could implement a calculator for it in Excel, but the underlying matrices of Chebyshev are daunting, and there are other steps he has taken too, like the Monte Carlo optimization procedure.

I think you are probably right, that it would be possible to acheive the result by running it through some sort of filter and using least squares measure of fit to a good sine wave. But the frequency domain analysis avoids that and gets right to the harmonic distortion without assuming anything about the filters. I don't see where Don talks much about filtering at all, except to say that the inductance and the intertia of a motor will make a great multipole filter when the lower harmonics are so much reduced.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com

Post Edited (Tracy Allen) : 2/25/2007 5:05:46 AM GMT
595 x 196 - 6K
592 x 269 - 7K

Comments

  • GavinGavin Posts: 134
    edited 2007-02-25 12:40
    Thanks for digging this up, I had run into it years ago and forgotten all about it.
    Wanted it for BLDC but never got around to using it and so forgot all about magic sin waves.
    The prop maybe good enough to do it for BLDC, nice high freq clock and 32 bit counters.

    Gavin
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2007-02-26 17:45
    Hi Gavin, what is BLDC?

    Attached is a demo object for a 28 pulse magic sine wave. A cog counter sets the frequency and provides the phase reference, and there is a table of 2*28 phase points where the pulses are to start and end. The values in the table come from one of Don Lancaster's Java calculators as linked above. The asm sequencer program reads through the table ias phase advances and sets or clears the two output pins that are supposed to drive the half bridges.

    Here is an example table:

    attachment.php?attachmentid=45641

    The start and stop points from the java calculator are phase in degrees, which have to be translated to Propeller counter phsa from zero to 2^32-1. Don emphasises that the transition timing has to be precise, within one microsecond, in order to achieve the best suppression of the low harmonics. The Prop clocked at 80mhz can achieve that easily.

    The program that polls the counter phsa register. The latency is less than 8 clock cycles, 100 nanoseconds. Even greater time precision could be achieved by using a table of delta values with waitcnt, instead of the counter module. That could get the latency down to one clock cycle, but with that method it would be hard to adjust the sinus frequency. The method using the counter module makes it easy to adjust that on the fly.

    I haven't looked at this on a scope with filtering. When slowed down of course it looks very course, DUTY mode or a higher frequency standard PWM can in contrast give a very smooth appearane because of the very rapid switching, at thousands or more events per cycle. This uses only 28 pulses per cycle which IK guess is what makes it attractive for efficient motor drive.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
    580 x 460 - 17K
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-02-26 18:21
    BLDC stands for Brushless-DC motor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • rokickirokicki Posts: 1,000
    edited 2007-02-26 19:03
    Wow, that's cool. If you precalculate the clock count in an array, I'll bet you could do this entirely in Spin quite easily!
    Two close pulses can trivially be generated with 12.5ns resolution with a counter, so you can do the edges in pairs (for
    the most part).

    On the other hand, the nice thing about your assembly code routine is you can change FRQ on the fly and the code just
    "magically" does the right thing.

    Very sweet. Has Dan done anything like this for sigma-delta ADC, to reduce the edge count there?
  • Ching LinChing Lin Posts: 11
    edited 2007-02-27 14:51
    Hi Tracy,

    Trying to digest your magsines2.spin.
    1)Why both outputs are upside down?
    2)I got odd output waveforms when I use afreq:=3221.
    3)Why there are two :loop0?
    4)what "rdlong clkf,0" does @ entry
    5)Can you explain on "shl t0,#4"?

    Thanks,
    Ching

    Post Edited (Ching Lin) : 2/27/2007 7:45:55 PM GMT
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2007-02-27 22:56
    Hi Ching,

    1) I'm not sure what you mean by both outputs being upside down. The way I see it, each one is like the picture from the first post in this thread.

    2) I attached an o'scope picture (tek THS720) from the output. This is with output frequency 60hz, frqa=3221. The top trace is the output that comes directly from bit31 of phsa, in NCOmode. The bottom trace comes from the two output pins, with the scope probe bridged between the two pins. Do you see something different?

    3) the Propeller syntax allows local labels that start with a colon. The scope of a local label lies between two normal labels. It is convenient for these short wait loops.

    4) the rdlong clkf,0 is not used by this program. Sorry, remnant. If the program needs to specify a frequency in absoulte Hertz, that clkf value would be used to find the frqa value based on the desired hertz value.

    5) The object of this code that follows the last pulse in the cycle of 28 is to detect when the phsa register rolls back to zero phase.

    finish                            ' time to start over at the top of the table 
                  mov t0,hz60           'set window to detect rollover of phsa
                  shl t0,#4              '<--------------------- find 16*hz60 (=16*frqa)
                  mov ptr,#s1           ' point to beginning of sequence table
                  shr xpin,#1          ' back to original pin for phase < 180
    :loop0                             ' wait for phsa to roll back past zero
                  cmp t0,phsa   wc   ' <------------detected as wait for phsa < 16*frqa
            if_c  jmp #:loop0
                  jmp #sequencer       'back to beginning of cycle
    



    The phsa can advance by 8*frqa during time it takes to execute the polling in :loop0, that being because there are four clocks per instruction, times two instructions, while phsa advances on every clock. I made it 16*frqa just to be on the safe side. In retrospect, it should simply test phsa(31) and wait for it to go back to zero.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 2/28/2007 12:21:36 AM GMT
    681 x 511 - 87K
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2007-02-27 23:15
    Don Lancaster sent me this link, to his new demo javascript calculator
    www.tinaja.com/demo28a.asp

    Paul, thanks for the defination, "brushless DC motor" = BLDC. I'm clueless about which types of motors and what applicatons this would be used for. (I just like making waves!) It seems like a lot of these motors require overlapping phases around 120 degrees apart. The prop could do that too, I think.

    The Art of Electronics has an example, the 61 inch sidereal telescope drive motor which needs to be operated by an accurately settable frequency from 55 to 65 hertz. In that case, the digitally synthesized sine wave goes through a linear amplifier to the motor. The prop could handle the synthesis with much less trouble, but not best via magic sines.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Ching LinChing Lin Posts: 11
    edited 2007-02-28 14:07
    Hi Tracy,

    Everything looks great now.
    I was confused by measuring the waveforms from the demo board headphone amp outputs.

    Thank you so much for the help.
    Ching Lin
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-02-28 14:21
    Tracy,

    Brushless motors get used a lot in model aircraft with awesome performance, they also work well in electric vehicles. Generally they are not driven sinusoidally but rather just with pulses which are turned into trapizoids by the motor inductance. Hall sensors or back emf is used to decide when to energize the specific windings. So most of the time they are just emulating DC motors really with the speed dictated by the load.

    I'm interested in making a low speed high torque motor for an electric unicycle, I'd use a quad encoder for the feedback as it would allow commutation down to zero speed.

    If you wanted to put some of these nice waves into practise you will find BLDC motors in every CD-ROM and HD.

    I love TAOE, a cracking book but please don't insert the paperback version into the front wheel of your racing bike. Don't ask but lets just say I now have, two lumps of paper back and 5 less spokes on that particular wheel.

    Graham
Sign In or Register to comment.