Edit: haha, here's a shorter version that does the same thing.
Here's the space vector part of the code:
Va, Vb, and Vc are the 3 phase voltages. pdc1, 2, and 3 are temp variables for the 3 duties. So, at the end you would do
PDC1 = pdc1;
PDC2 = pdc2;
PDC3 = pdc3;
Code:
void SpaceVectorModulation() {
// I know you can do it faster than this, but I just want it to work. I'll optimize later.
// if Vc is smallest of the 3, then do the following...
if (Vc <= Va && Vc <= Vb) { // Vc <= Vb <= Va or Vc <= Va <= Vb. They both have the same
// Q1 & Q2.
pdc1 = Va-Vc;
pdc2 = Vb-Vc;
pdc3 = 0;
}
else if (Va <= Vc && Va <= Vb) { // Va is smallest
// Q3 & Q4
pdc1 = 0;
pdc2 = Vb - Va;
pdc3 = Vc - Va;
}
else if (Vb <= Va && Vb <= Vc) { // Vb is smallest
// Q5 & Q6
pdc1 = Va-Vb;
pdc2 = 0;
pdc3 = Vc-Vb;
}
}