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.

TMS320C28341: wrong addition result

Part Number: TMS320C28341


I am trying to control a device using PWM by TMS320C28027 due to absence of this part number I choose 28341, I think they should be smilar, In below code I got wrong results for pwmval parameter in the line "  int pwmval=32000+pI;". the code:

    int error=(*setval_pos-(Uint16)ECap1Regs.CAP1);
    if(abs(error)<1000)
    {
        EPwm3Regs.CMPA.half.CMPA=32000;
    }
    else
    {
        int32 pI=2*error;
        int pwmval=32000+pI;
        if(pwmval<0xFFFF && pwmval>0)
        EPwm3Regs.CMPA.half.CMPA=(Uint16)pwmval;

}

I have tested "int32 pwmval=32000+pI" with no success.