Sine vs Space Vector PWM, and creating a lookup table for Sine PWM

Hello All,

I'm learning to program a self-balancing robot, and I've come to the point where I need to understand SPWM or SVPWM to create a lookup table to drive two brushless motors and offset the motors phase by 120 degrees.

I've been struggling with the calculations and concepts behind these two things for the past couple weeks, and that's why I've come here for help!

Firstly, what is the difference between sine PWM and space vector PWM? Why use one over the other?

Secondly, how do I calculate a lookup table for each one? I get the feeling there are multiple ways of doing it, and because of rounding I assume tables can end up looking slightly different. I'm going to include the code I was going off of as an example, which uses SVPWM, but I started trying to tackle things from the SPWM direction because it seemed like an intuitive enough concept to just use a sine wave, and I could follow the logic.

I made a Desmos graph that visualizes my attempt at visualizing and understanding SPWM. I took a sine wave, translated it up 127.5 units, and gave it an amplitude of 127.5 units, so together we have a wave 255 units high (8 bits). I divided 2 pi by 255, the amount of entries in the lookup table, and got .012, the value I put in the slider for "a" although it seems like that number is too small for desmos to accurately "step".

Here is the lookup table that I am using as an example, it uses SVPWM.

// Space Vector PWM lookup table
// using uint8_t overflow for stepping
int8_t pwmSinMotor[] = {0,  5,  10, 16, 21, 27, 32, 37, 43, 48, 53, 59, 64, 69, 74, 79, 84, 89, 94, 99, 104,  109, 
111,  112,  114,  115,  116,  118,  119,  120,  121,  122,  123,  123,  124,  125,  125,  126,  126,  126,  127,  
127,  127,  127,  127,  127,  126,  126,  126,  125,  125,  124,  123,  123,  122,  121,  120,  119,  118,  116,  
115,  114,  112,  111,  110,  112,  113,  114,  116,  117,  118,  119,  120,  121,  122,  123,  124,  124,  125,  
125,  126,  126,  126,  127,  127,  127,  127,  127,  126,  126,  126,  125,  125,  124,  124,  123,  122,  121,  
120,  119,  118,  117,  116,  114,  113,  112,  110,  106,  101,  97, 92, 87, 82, 77, 72, 66, 61, 56, 51, 45, 40, 
35, 29, 24, 18, 13, 8,  2,  -2, -8, -13,  -18,  -24,  -29,  -35,  -40,  -45,  -51,  -56,  -61,  -66,  -72,  -77,  
-82,  -87,  -92,  -97,  -101, -106, -110, -112, -113, -114, -116, -117, -118, -119, -120, -121, -122, -123, -124, 
-124, -125, -125, -126, -126, -126, -127, -127, -127, -127, -127, -126, -126, -126, -125, -125, -124, -124, -123, 
-122, -121, -120, -119, -118, -117, -116, -114, -113, -112, -110, -111, -112, -114, -115, -116, -118, -119, -120, 
-121, -122, -123, -123, -124, -125, -125, -126, -126, -126, -127, -127, -127, -127, -127, -127, -126, -126, -126, 
-125, -125, -124, -123, -123, -122, -121, -120, -119, -118, -116, -115, -114, -112, -111, -109, -104, -99,  -94,  
-89,  -84,  -79,  -74,  -69,  -64,  -59,  -53,  -48,  -43,  -37,  -32,  -27,  -21,  -16,  -10,  -5, 0};

Furthermore, the author of this code also made a spreadsheet that calculates SPWM and SVPWM, but funnily enough the numbers don't match up to the SVPWM table here they made, which needless to say has confused me even more.

Here is a good starting point for Space Vector PWM:
http://www.spacevector.net/

This whole thread should be deleted as sales spam!

Mark

holmes4:
This whole thread should be deleted as sales spam!

Why? The original post seems to ask a question and the first response provides a reference that may answer the OP question. Just because the reference needs to be paid for does not make it "sales spam".

ard_newbie:
Here is a good starting point for Space Vector PWM:
http://www.spacevector.net/

This sounds like a great resource but the option to buy the handbook seems to be broken. It seems the DNS address is missing. Do you know of any free resources like this? Does anyone have this handbook and would be willing to share with me for free :wink: ?

ShayS:
Furthermore, the author of this code also made a spreadsheet that calculates SPWM and SVPWM, but funnily enough the numbers don't match up to the SVPWM table here they made, which needless to say has confused me even more.

Did you see the note in cell M2 that you have to change the value in A3 from 255 to 294 (for some reason) to get the right SVPWM values in Column M?

I did see it, and yes I changed it. I found out it has to do with the fact that the spreadsheet calculates SPWM and SVPWM every one degree (360 degrees, 360 values), while the author of the code I was going off of interpolated that to only 256 values for 360 degrees.