I am working on a sensorless vector control scheme, I am using a Texas processor but I am having an issue with some code and I just can not see what the hell the problem is

I initialise a table, 720 values making up sinreference with a third harmonic added

No issue here

float sin_table[721]={0};

for(i>=0; i<=720; i++) { sin_table[i]=1.1547*MAXMODINDEX*(sin(i*0.5*PI/180)+sin(3*i*0.5*PI/180)/6.0); // }

I use a count n to determine sample time, I update n in an interrupt and call the SPWM function every interrupt

void Third_SPWM(count) { volatile float theta1= (2*fref*count*TS)*360; volatile float theta2= (theta1 - 2.0/3.0)*360; volatile float theta3= (theta1 + 2.0/3.0)*360; float moda = (fref/FREFMAX)*(sin_table[(int)theta1]); float modb = (fref/FREFMAX)*(sin_table[(int)theta2]); float modc = (fref/FREFMAX)*(sin_table[(int)theta3]); ...... ........ }

The above compiles with no error but its not finished, theta1, theta2 and theta3 are actually the number of 0.5 degrees hence with a 720 table it is the index but I need to stop the index being negative or exceeding 720 so I need to make it loop which should be so easy

Theta 2 is lagging theta1 so it can only be negative never more, theta 3 is leading so it will exceed 720 and needs to go back to 0

It should be so easy (in my mind)

if(theta2<0) { theta2=720-theta2; } if(theta3>720) { theta3=theta3-720;; }

But if I try

volatile float theta1= (2*fref*count*TS)*360; volatile float theta2= (theta1 - 2.0/3.0)*360; volatile float theta3= (theta1 + 2.0/3.0)*360; if(theta2<0) { theta2=720-theta2; } if(theta3>720) { theta3=theta3-720;; } float moda = (fref/FREFMAX)*(sin_table[(int)theta1]); float modb = (fref/FREFMAX)*(sin_table[(int)theta2]); float modc = (fref/FREFMAX)*(sin_table[(int)theta3]); ...... ........ }

It unleashes a world of crap

#28 expression must have a constant value

#68 expected a }

and lower down its starts telling me things are not defined when they clearly are

Any help is much appreciated