# 3-phase sine wave generator(pwm)---finished design

This topic is not a request for help on my project, im simply posting code for my most recent project.

Any one having trouble creating (or are looking for) code to make a muliphase sine wave generators? I know i was, and thanks to the help of tmd3, my design is finally finished. Anyone who needs such code feel free to download it, and once again, THANK YOU tmd3 for all your help! this woud’ve never been possible without your help! so thanks!

The generator has 3 outputs: out1, out2, out3. It also has 2 inputs: enable (pin 8), and freqpin (pin A0). the enable pin (pin 8), enables the generator whenever its value is HIGH. Remember to connect this pin to a resistor connected to gnd, or the board wont be able to tell if the input is HIGH or LOW. The freqpin (pin A0) is connected to the center(second) pin of a pot, which has its first pin connected to 5v and the 3rd to gnd.

READ THIS IF YOU WANT TO MODIFY THE CODE:

-The frequency of the generator is controlled by a pot. The specific code for that is the delay in the loop, which should come up as delay(freqpin). If the pot isnt making the generator operate at a high enough frequency, change delay(freqpin) to delay(freqpin/#) the number of course being an integer. the greater the integer, the higher the frequency. The same thing applies to lowing the frequency, only instead of dividing by #, you muliply, and the greater the number for that, the lower the frequency.

-The resolution of the sine wave is controlled by const float y = pi/30. I RECOMMEND THAT YOU DO NOT TAMPER WITH THIS VALUE. if you want to change the resolution, however, MAKE SURE THE EQUATION IS AS FOLLOWS: const flat y = (#1)pi/3(#2). The greater the value of #1 is, or the lower the value of #2 is(NOT COUNTING 0), the lower the sine wave resolution will be. To increase the resolution, increase the value of #2 and decrease the value of #1(NOT COUNTING 0). Make sure that #1 and #2 are POSITIVE WHOLE NUMBERS.

_3phasesine.ino (878 Bytes)

Thanks for sharing! Do you think this code will work for brushless dc motors? In my opinion, it should work the same but, maybe require slower ramp rates depending on the application.

i’m pretty sure it should work on brushless dc motors. in fact, its for this very reason i created this code. i havent tested it out on a dc motor yet, but i have tested it out on led’s, which seem to work exactly as they would from a 3 phase pwm sine wave.

just remember to hook up each of the 3 motor inputs with a low pass filter, which should smooth up the operation a little.

Wonderful to hear! I have some interest of building a ESC for a quadcopter but, it is down the list.

I think it would be nice to have a single ESC with microprocessor that could run four channels so that the component cost an count would be much smaller.

I am not sure it would be possible with 16MHz chip but, it should be easy with a faster Arm style chip.

If you feel like building a board, it would be interesting to see and try to help with that too.

I am trying to generator 20hz sinewave with this code and can’t seem to change output with potentiometer. Any thoughts?

Hello, first of all, thanks you for sharing your work, till now helped me a lot to understand how is the way to go.

There is any option to change the frequency of the pwm (output) , keeping the 50Hz of the sine wave?