3 phase sine waves

Discussion in 'Embedded Systems and Microcontrollers' started by Terud, Dec 20, 2011.

  1. Terud

    Thread Starter New Member

    Dec 20, 2011
    Hi. I have just found this forum. Looks fantastic.

    My problem (challenge).

    I wish to generate 3 phase sine waves (120 deg apart) at 1 – 60 Hz.

    I have attempted this using a Microchip processer implementing AN889. It doesn’t work. I have found basic flaws in the coding.

    Please if anybody has any ideas how to do this using whatever technology I would be very grateful if you would share it with me.

    I don’t know if this is appropriate on this forum but Compliments of the Season and a Happy Healthy and Prosperous New Year to all.
  2. praondevou

    AAC Fanatic!

    Jul 9, 2011
    You should really stick to the uC for PWM generation. Start with one sinewave if it's to complex.

    To give you an idea how much is needed to only create stepwaves for two phases have a look HERE at post 53. And there is still missing something to bring it to PWM. Another option are EPROM lookup tables, but the circuit is also big.

    I you have a uC creating 3 PWMs the work is almost done.

    There are some programmers here that might help you.
    Terud likes this.
  3. codehead


    Nov 28, 2011
    OK, so you've identified a problem with the application note code. I'm not sure if you're looking for code for that processor, or more of a theory of operation. I can help with the latter—I don't have time to deal with implementation details for a processor I'm not familiar with.

    It's a pretty simple problem, though. I suppose that you have a sine table, or can incorporate one easily enough. You'll want to generate a "phasor"—a phase accumulator—which is basically a counter. Generating a single sine wave is a matter of adding an increment (which will be your rate control) to the counter.

    Let's say that the sine table of a full sine wave has 512 values. (You could do it with a quarter-wave table and appropriate adjustments in your code.) A rate increment of 1 at whatever sampling rate you're using would give you a certain frequency, and and increment of 3 would give you three times that frequency. To get arbitrary rates, you'd need to have more precision on your phasor and increment—such as using floating point, or a fixed-point scheme where you have one value as the integer part, and another as the fractional part. To implement fractional lookup, just grab the integer-part offset from the sine table, and the next higher one, then do linear interpolation based on the fractional increment. Note that you can now also have an increment less than one to go lower in frequency than a rate of 1.

    It's pretty easy—you just increment your phasor every time you need a sample; if the phasor becomes greater than the table length (512 here), subtract the table length from it (it'll look like you're generating a sawtooth or ramp wave); put that phasor increment and wrap in a subroutine if you want, for easy debugging.

    Next, look up the sine value. Make that a subroutine too—pass it the integer and fractional part of the phasor, and have the routine grab the two points for interpolation (remember to see if you need to wrap around the table to grab the second point for interpolation—that's a bug waiting to happen), and return the interpolated since value.

    OK, but we need three phases. So call that routine again, but first add the sine table length divided by three to a copy of the phasor (don't forget that you need to wrap that too, by subtracting the table length from the integer part if the integer part is greater than or equal to the table length—but you could put that part in the sine lookup subroutine, which will make things a little easier). Then do another call to the sine subroutine but add another 512/3 to the phasor copy. There are your three phases.

    It's trivial to do all of this in floating point, but it's really not much harder to do it in integer.

    Sine waves are pretty smooth, so linear interpolation works well—I imagine a 256-value table would be good enough for the sine in this case—I used 512 to make you think more about counter size. For instance, with a 256 full-sine table and an 8-bit register, you could use the upper byte as the integer part, making the phasor implementation trivial. With 8-bit words, you would use one byte for the integer and one for the fraction, and have more book-keeping to do when incrementing. Note that with a 16-bit word for the phasor, you could handle a 512-value sine table by shifting the word 7-bits to the right to get the integer part, and using the lower 7 bits as the fraction.

    (edited for typos)
    Last edited: Dec 22, 2011
  4. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    That app note doesn't have the sine table included.

    Is that the problem the OP is having?
    Terud likes this.
  5. atferrari

    AAC Fanatic!

    Jan 6, 2004
    I have just completed the redesign of 3-phase sine wave generator from 10 to 998 Hz.

    Until I post the whole on the web, you could investigate this idea: three CD4015 shift registers driving each one 6 resistors (weighted to have a sinewave-like output).

    The key point here is the number 6. The first drives the next with the output at 1/3 of the period and the second in turn does the same with the next.

    Smoothing of the steplike sinewaves is done with three LMF100 filters. For that you need two clocks tracking each other. Solved with a 18F4431.

    Sounds complex but it is simple (and it was pure fun to develope).
    Terud likes this.
  6. Terud

    Thread Starter New Member

    Dec 20, 2011
    Thank you for your very comprehensive reply. I will break it down to some flow charts and take it from there.