This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28377S: Case statement in CLA

Part Number: TMS320F28377S

My application requires a 1MHz control loop along with data acquisition. In my current code, the ADC triggers both a CLA task and an ISR in the main CPU. The CLA task implements the control, while the ISR does the data acquisition. Depending on a state machine in the CPU, the CLA must change the type of control algorithm that is running. To implement this, I define integers in the CPU to CLA message RAM and use them as flags for a case statement in the CLA task. My problem is that the results of this implementation are not consistent. The case statements seem to work sometimes, but other times I can see the value of the flag variable in CCS but the CLA doesn't seem to enter that case.

My suspicion is that the problem is related to the arbitration between CLA and CPU over reading/writing the flag variable but I am not sure. Is there an obvious problem with this strategy? Is there a better way to implement communication between CPU and CLA to determine which control algorithm is implmented.

Code from the CLA task is below (mode_cla is the flag variable defined in the CPU to CLA message RAM):

switch(mode_cla)
{
case 0: //no control, no sine (IDLE, SERVO, PRECHARGE, BUCKUP, ERROR)

rk = VBatt_volts;
rk2 = 0.0;
t = 0;
break;
case 1: //inner control, no sine (CTRLUP, ZTEST)
rk = VBatt_volts;
rk2 = 0.0;
t = 0;

uki = DCL_runPIc(&ctrl_inner_pi, rk,ak);
uk_cmp = (long)(uki * 6553600 );
EPwm1Regs.CMPA.all = uk_cmp;
break;
case 2: //innter+outer control, no sine (EISSETUP, SEND)
rk = VBatt_volts;
rk2 = 0.0;
t = 0;

uko = DCL_runPIc(&ctrl_outer_pi, rk2,yk);
uki = DCL_runPIc(&ctrl_inner_pi, uko,ak);
uk_cmp = (long)(uki * 6553600 );
EPwm1Regs.CMPA.all = uk_cmp;
break;
case 3: //inner control, sine (ZTEST_RUN)
fResult = CLAsin((float)t*Tcontrol*TWO_PI/Tperturb[0]);
rk = VBatt_volts + fResult*amplitude;
rk2 =fResult*amplitude;
last = 3;
uki = DCL_runPIc(&ctrl_inner_pi, rk,ak);
uk_cmp = (long)(uki * 6553600 );
EPwm1Regs.CMPA.all = uk_cmp;
break;
case 4: //inner+outer control, sine (RUN)
fResult = CLAsin((float)t*Tcontrol*TWO_PI/Tperturb[0]);
rk = VBatt_volts + fResult*amplitude;
rk2 =fResult*amplitude;

uko = DCL_runPIc(&ctrl_outer_pi, rk2,yk);
uki = DCL_runPIc(&ctrl_inner_pi, uko,ak);
uk_cmp = (long)(uki * 6553600 );
EPwm1Regs.CMPA.all = uk_cmp;
break;

}