View Single Post
Old 11-22-2014, 05:34 PM   #1337 (permalink)
MPaulHolmes
PaulH
 
MPaulHolmes's Avatar
 
Join Date: Feb 2008
Location: Maricopa, AZ (sort of. Actually outside of town)
Posts: 3,832

Michael's Electric Beetle - '71 Volkswagen Superbeetle 500000
Thanks: 1,362
Thanked 1,202 Times in 765 Posts
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;
	}	
}
__________________
kits and boards

Last edited by MPaulHolmes; 11-24-2014 at 01:34 PM..
  Reply With Quote
The Following 3 Users Say Thank You to MPaulHolmes For This Useful Post:
cts_casemod (11-23-2014), e*clipse (11-24-2014), mpgmike (02-06-2022)