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.

TMS320F28335: Standalone system does not work properly

Part Number: TMS320F28335


Dear experts,

I have been working on tms320f28335 for inverter applications. The algorithm has been successfully realised on Flash by following instructions in C2000 teaching rom. However , there are couple of issues I am facing.

1. Once the program is burned on the flash, the plant(3 phase inverter) achieves it's steady state values and works like a dream for the very first time the program is loaded in the flash. Nevertheless, after it is reset it doesn't work as how it supposed to work like a standalone system. However, there is a LED blink that flashes at 1 sec which indicates the program is running and I can assure it's blinking after it is reset. In other words, the program is being executed as per the algorithm, but the plant trips due to high currents. I assure there is no problem with the algorithm because it works after it is loaded in the flash. Only issue is it doesn't work after subsequent CPU reset and start the system. I suspect the variables used for the inverter system that controller had been calculating were not getting reset and they were only initialized to zero when the program is loaded it again from the CCS.

2. The second issue I face is, microcontroller hangs when there is a physical disturbance or the power fluctuation despite the watchdog timer is initialised.

Regards,

Rajesh BN.

  • Hi Rajesh,

    I am assigned to review your post now.  

    1. The flash plugin might be initializing some modules like clock, flash etc.  Also, the gel file might be doing some configuration.  Your application might be missing those configurations that you need.  Please check.  Since you said the application is blinking after the power cycle, I think the boot mode pins are configured for flash boot correctly.  

    2. Regarding the variable initialization, do you have codestartbranch.asm included in your application? This will call c_init routine to initialize the global variables.  

    3. When you say hang, do you mean that the device is getting reset?  If the physical disturbance or the power fluctuation causes the device to operate out of the operating conditions listed in the datasheet, device will go through reset.  Please monitor the voltage lines to make sure that they are always with in the operating conditions.

    If above does not help, I will ask our F28335 expert to help you further.

    Thanks and regards,
    Vamsi

  • Hi Vamsi,

    As you mentioned about codestartbranch, it has been added in the program but I am not sure if it has to be called in some section of the program. If you look into the program, there are some variables that are not initialized globally but some are initialised in a sub program named "Init_ADC" that is called in the main program. Can it be done that way? 

    Furthermore, I'm confused whether to link Headers_nonBIOS.cmd or F28335.cmd on the properties -> general

    The next aspect of my original question regarding "hang", microcontroller actually doesn't even resets, but all the GPIO's go high and stay at that condition although the watchdog timer has been enabled.

    I attached code as well as the screenshot of the program to let you know the files that are added to the program. However, program related to algorithm are omitted from the adc interrupt subroutine as it is irrelevant.

    Regards,

    Rajesh BN.

    #include "DSP2833x_Device.h"
    
    #define GLOBAL_Q 24
    
    
    
    
    #include "IQmathLib.h"
    
    #define PI 6.2831853f
    
    
    
    
    _iq iq,jq,kq=0;
    
    _iq cons,kr,ky,kb,sr,sy,sb,t,tr,ty,tb,t1,t2=0;
    
    _iq sino,coso=0;
    
    _iq a1,a2,a3,b2,b3,c1,c2=0;
    
    _iq vr_a,vy_a,vb_a=0;
    
    _iq valpha_act,vbeta_act,vd_a,vq_a=0;
    
    _iq ir_a,iy_a,ib_a=0;
    
    _iq vd_set,vq_set=0;
    
    _iq ialpha_act,ibeta_act,id_a,iq_a=0;
    
    _iq vd_ref,vq_ref,valpha_ref,vbeta_ref=0;
    
    _iq vr_ref,vy_ref,vb_ref=0;
    
    _iq id_ref,iq_ref=0;
    
    _iq P1,I1,P2,I2=0;
    
    _iq vd_e,vd_e1,vq_e,vq_e1=0;
    
    _iq id_ref1,iq_ref1=0;
    
    _iq vd_ref1,vq_ref1=0;
    
    _iq id_e,iq_e,id_e1,iq_e1=0;
    
    _iq id_af,id_af1,id_a1=0;
    
    _iq iq_af,iq_af1,iq_a1=0;
    
    _iq vd_af,vd_af1,vq_af,vq_af1,vd_a1,vq_a1=0;
    
    _iq EvdL,EvqL=0;
    
    _iq F1,F2,F3=0;
    
    _iq VH,VL,IH,IL,EdL,EqL=0;
    
    
    
    
    #define AdcBufLen 39
    
    extern void InitPieVectTable(void);
    
    extern void InitPieCtrl(void);
    
    extern void InitSysCtrl(void);
    
    extern void InitAdc(void);
    
    extern void InitFlash(void);
    
    
    
    
    // external symbols for section ramfuncs
    
    extern unsigned int RamfuncsLoadStart;
    
    extern unsigned int RamfuncsLoadEnd;
    
    extern unsigned int RamfuncsRunStart;
    
    
    
    
    
    
    
    void Gpio_Select(void);
    
    void Init_Timer0(void);
    
    void Init_PWM(void);
    
    void Init_ADC(void);
    
    
    
    
    
    
    
    interrupt void adc_eos_seq1_int(void);
    
    interrupt void timer0_int(void);
    
    interrupt void pwm4_ctr_0(void);
    
    
    
    
    
    
    
    float VR,VY,VB,IR,IY,IB,VDC,IDC=0;
    
    float VRa,VYa,VBa,IRa,IYa,IBa,Idca=0;
    
    float vref_r,vref_y,vref_b=0;
    
    int i=0;
    
    float srf,syf,sbf=0;
    
    float disp1,disp2,disp3=0;
    
    float vdref=0;
    
    int index=0;
    
    int Buf1[AdcBufLen];
    
    int Buf2[AdcBufLen];
    
    int Buf3[AdcBufLen];
    
    
    
    
    void main(void)
    
    {
    
    	
    
     InitSysCtrl();
    
     memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, &RamfuncsLoadEnd - &RamfuncsLoadStart);
    
     InitFlash(); // Speed up FLASH memory
    
    
    
    
     DINT; // disable all interrupts
    
     Gpio_Select();
    
     InitPieCtrl(); // basic setup of PIE table; from DSP2833x_PieCtrl.c
    
     InitPieVectTable(); // default ISR's in PIE
    
     InitAdc(); //TI provided function
    
     Init_ADC(); 
    
     Init_Timer0();
    
     Init_PWM();
    
    	
    
     EALLOW;
    
     PieVectTable.TINT0 = &timer0_int;
    
        PieVectTable.SEQ1INT = &adc_eos_seq1_int;
    
        PieVectTable.EPWM4_INT = &pwm4_ctr_0;
    
        EDIS;
    
        
    
        PieCtrlRegs.PIEIER1.bit.INTx1 = 1;
    
     PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
    
     PieCtrlRegs.PIEIER3.bit.INTx4 = 1;
    
    
    
    
     IER |= 5; //00000101
    
     EINT;
    
     ERTM;
    
    
    
    
     EALLOW;
    
        SysCtrlRegs.WDCR= 0x002F; // enable the watchdog
    
        EDIS;
    
    	
    
     CpuTimer0Regs.TCR.bit.TSS = 0; // GO!!!
    
    	
    
     while(1)
    
     {
    
      EALLOW; //reset watchdog
    
      SysCtrlRegs.WDKEY = 0x55;
    
      SysCtrlRegs.WDKEY = 0xAA;
    
      EDIS;
    
    
    
    
     }
    
    }
    
    
    
    
    void Gpio_Select(void)
    
    {
    
     EALLOW;
    
     GpioCtrlRegs.GPAMUX1.all = 0;  
    
     GpioCtrlRegs.GPAMUX2.all = 0;  
    
     GpioCtrlRegs.GPBMUX1.all = 0;  
    
     GpioCtrlRegs.GPBMUX2.all = 0; 
    
     GpioCtrlRegs.GPCMUX1.all = 0; 
    
     GpioCtrlRegs.GPCMUX2.all = 0; 
    
     GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; //EPWM1A DSUB PL4
    
     GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; //EPWM1B
    
     GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1; //EPWM2A
    
     GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1; //EPWM2B
    
     GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 1; //EPWM3A
    
     GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 1; //EPWM3B
    
     GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 1; //PWM4A pin as GPIO for generating SOC to ADC
    
    
    
    
     GpioCtrlRegs.GPAMUX1.bit.GPIO12= 1; //TZ1
    
     GpioCtrlRegs.GPAMUX1.bit.GPIO13= 1; //TZ2
    
     GpioCtrlRegs.GPAMUX1.bit.GPIO14= 1; //TZ3
    
    	
    
    
    
    
    
    
    
     GpioCtrlRegs.GPADIR.all = 0;
    
     GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 0; //PWM4B as GPIO
    
     GpioCtrlRegs.GPADIR.bit.GPIO7 = 1;
    
    
    
    
    
    
    
    
    
    
     GpioCtrlRegs.GPADIR.bit.GPIO21 = 1; //LED7 o/p
    
    
    
    
    	
    
     GpioCtrlRegs.GPBDIR.all = 0; //(GPIO 48, GPIO 49, GPIO 50, GPIO 51)-External Contacts, GPIO 34 (Thermal trip)
    
     GpioCtrlRegs.GPBDIR.bit.GPIO60 = 1; //Relays (Check Relays RL 1-4)
    
     GpioCtrlRegs.GPBDIR.bit.GPIO61 = 1;
    
     GpioCtrlRegs.GPBDIR.bit.GPIO62 = 1;
    
     GpioCtrlRegs.GPBDIR.bit.GPIO63 = 1;
    
     GpioCtrlRegs.GPCDIR.all = 0; 
    
     EDIS;
    
    }
    
    
    
    
    void Init_Timer0(void)
    
    {
    
     CpuTimer0Regs.PRD.half.LSW = 0x0008;
    
     CpuTimer0Regs.PRD.half.MSW = 0x0022;
    
     CpuTimer0Regs.TPR.bit.TDDR = 0x0010;
    
     CpuTimer0Regs.TCR.bit.TIE = 1;
    
     CpuTimer0Regs.TCR.bit.TRB = 0; //reload after counter is zero
    
     CpuTimer0Regs.TCR.bit.TSS = 1; //stop timer; Enable when SET GO!!!
    
     CpuTimer0Regs.TCR.bit.FREE = 0;
    
    }
    
    
    
    
    void Init_PWM(void)
    
    {
    
    	
    
     EPwm1Regs.TBCTL.all = 0x0000;
    
     EPwm1Regs.TBCTL.bit.CTRMODE = 2;
    
     EPwm1Regs.TBCTL.bit.PRDLD = 0;
    
     EPwm1Regs.TBCTL.bit.SYNCOSEL = 1; // Master
    
     EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1;
    
    	
    
    
    
    
     EPwm1Regs.TBPRD = 7212; //Fsw = 5.2KHz
    
     EPwm1Regs.AQCTLA.all = 0x0060;
    
     EPwm1Regs.AQCTLB.all = 0x0090;
    
     
    
     EPwm1Regs.TBPHS.all = 0;
    
                   
    
               //Dead Band
    
     EPwm1Regs.DBCTL.bit.IN_MODE=0;
    
     EPwm1Regs.DBCTL.bit.POLSEL=2;
    
     EPwm1Regs.DBCTL.bit.OUT_MODE=3;
    
     EPwm1Regs.DBRED = 100;
    
     EPwm1Regs.DBFED = 100;
    
    
    
    
     //EPwm2Regs.TBCTL.all = 0x2086; //00 1(UP after SYNC) 000(CLK/1) 001(CLK/1) 0() 00(EPWM1 SYNCI Source) 0(Load @ CTR =0) 1(CTR = TBPHS on SYNCI Signal) 10(UP-DOWN counter)
    
     EPwm2Regs.TBCTL.all = 0x0000;
    
     EPwm2Regs.TBCTL.bit.CTRMODE = 2;
    
     EPwm2Regs.TBCTL.bit.PRDLD = 0;
    
     EPwm2Regs.TBCTL.bit.SYNCOSEL = 0; // Slave
    
     EPwm2Regs.TBCTL.bit.HSPCLKDIV = 1;
    
    	
    
     EPwm2Regs.AQCTLA.all = 0x0060;
    
     EPwm2Regs.AQCTLB.all = 0x0090;
    
     EPwm2Regs.TBPRD = 7212;
    
     EPwm2Regs.TBPHS.all = 0;
    
    	
    
     //Dead Band
    
     EPwm2Regs.DBCTL.bit.IN_MODE=0;
    
     EPwm2Regs.DBCTL.bit.POLSEL=2;
    
     EPwm2Regs.DBCTL.bit.OUT_MODE=3;
    
     EPwm2Regs.DBRED = 100;
    
     EPwm2Regs.DBFED = 100;
    
    
    
    
    
    
    
    
    
    
    
    
    
     //EPwm3Regs.TBCTL.all = 0x2086; //0010 0000 1000 110
    
     EPwm3Regs.TBCTL.all = 0x0000;
    
     EPwm3Regs.TBCTL.bit.CTRMODE = 2;
    
     EPwm3Regs.TBCTL.bit.PRDLD = 0;
    
     EPwm3Regs.TBCTL.bit.SYNCOSEL = 0; // Slave
    
     EPwm3Regs.TBCTL.bit.HSPCLKDIV = 1; // SYSCLK/(2*1) 150M/2
    
    
    
    
     EPwm3Regs.AQCTLA.all = 0x0060;
    
     EPwm3Regs.AQCTLB.all = 0x0090;
    
     EPwm3Regs.TBPRD = 7212;
    
    
    
    
    
    
    
     //Dead Band
    
     EPwm3Regs.DBCTL.bit.IN_MODE=0;
    
     EPwm3Regs.DBCTL.bit.POLSEL=2;
    
     EPwm3Regs.DBCTL.bit.OUT_MODE=3;
    
     EPwm3Regs.DBRED = 100;
    
     EPwm3Regs.DBFED = 100;
    
    
    
    
     //ADC-EPWM4A
    
     EPwm4Regs.TBCTL.all = 0x0000;
    
     EPwm4Regs.TBCTL.bit.CTRMODE = 2;
    
     EPwm4Regs.TBCTL.bit.PRDLD = 0;
    
     EPwm4Regs.TBCTL.bit.SYNCOSEL = 0; // Slave
    
        EPwm4Regs.TBCTL.bit.HSPCLKDIV = 1;
    
    
    
    
        EPwm4Regs.TBPRD = 2403; //=Fsw/3
    
     EPwm4Regs.TBPHS.all = 0;
    
    
    
    
     EPwm4Regs.ETSEL.bit.INTSEL = 1; //Interrupt @ CTR = 0
    
     EPwm4Regs.ETSEL.bit.INTEN = 1; // Interrupt Enable
    
     EPwm4Regs.ETSEL.bit.SOCAEN = 1;
    
     EPwm4Regs.ETSEL.bit.SOCASEL = 1; //SOCA @ CTR = 0
    
     EPwm4Regs.ETPS.bit.SOCAPRD = 1;
    
     EPwm4Regs.ETPS.bit.INTPRD = 1;
    
    }
    
    
    
    
    
    
    
    void Init_ADC(void)
    
    {
    
     AdcRegs.ADCTRL1.all = 0;
    
     AdcRegs.ADCTRL1.bit.SEQ_CASC =1; // 1=cascaded sequencer
    
     AdcRegs.ADCTRL1.bit.CPS = 0; // divide by 1    
    
     AdcRegs.ADCTRL1.bit.ACQ_PS = 6; // 6 ADC clock cycles HOLD
    
    	
    
     AdcRegs.ADCTRL2.all = 0;  
    
     AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 =1; // 1=SEQ1 start from ePWM_SOCA trigger 
    
     AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // 1=enable SEQ1 interrupt 
    
     AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1 = 0; // 0= interrupt after every end of sequence
    
    	
    
     AdcRegs.ADCTRL3.bit.SMODE_SEL = 1;
    
    	
    
     AdcRegs.ADCTRL3.bit.ADCCLKPS = 6; //In the InitiSystem function, HISPCP is initialized as "0". which means the clk to the ADC peripheral is 150MHz.
    
     AdcRegs.ADCREFSEL.bit.REF_SEL = 0x0;
    
    	
    
     AdcRegs.ADCMAXCONV.all = 5; // (no. of conversions + 1) as simultaneous sampling is 2*2
    
     AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0; //A0 - 0, B0 -1
    
     AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 1; //A1 - 2, B1 -3
    
     AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 2; //A2 - 4, B2 -5
    
     AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 3; //A3 - 6, B3 -7
    
     AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 7; //A4 - 8, B4 -9
    
     AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 5; //A5 - 10,B5-11
    
     AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 6; //A6 -12, B6- 13
    
     AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 4; //A7 -14, B7 -15 //pot on A7
    
    
    
    
     cons = _IQ(39); // 39 sets the fundamental frequency 400
    
    
    
    
        a1 = _IQ(0.66666667);
    
        a2 = _IQ(0.33333333);
    
        a3 = _IQ(0.33333333);
    
    
    
    
        b2 = _IQ(0.5773503);
    
        b3 = _IQ(0.5773503);
    
    
    
    
        c1 = _IQ(-0.500000);
    
        c2 = _IQ(0.8660254);
    
    
    
    
        //PI voltages constants
    
        P2 = _IQ(0.1000);
    
        I2 = _IQ(0.09998);
    
    
    
    
        //PI current constants
    
        P1 = _IQ(0.1002);
    
        I1 = _IQ(0.09985);
    
    
    
    
        vd_set = _IQ(18.00);
    
        vq_set = _IQ(0.00);
    
        // low pass filter (Tustin method)
    
        F1 = _IQ(0.00745);
    
        F2 = _IQ(0.985);
    
        F3 = _IQ(0.007495);
    
    
    
    
        VH = _IQ(40.0000); //limit to the voltage references at the end
    
        VL = _IQ(-20.0000);
    
        IH = _IQ(30.0000); //limit for current reference
    
        IL = _IQ(-25.0000);
    
    
    
    
    
    
    
    }
    
    #pragma CODE_SECTION(adc_eos_seq1_int, "ramfuncs");
    
    void adc_eos_seq1_int(void)
    
    {
    
    algorithm 
    
      EALLOW;
    
      SysCtrlRegs.WDKEY = 0x55;
    
      SysCtrlRegs.WDKEY = 0xAA;
    
      EDIS;
    
    
    
    
     }
    
    
    
    
    
    
    
      IR = AdcMirror.ADCRESULT0; //A0
    
      IY = AdcMirror.ADCRESULT2; //A1
    
      IB = AdcMirror.ADCRESULT4; //A2
    
      IDC= AdcMirror.ADCRESULT6; //A3
    
    
    
    
      VR = AdcMirror.ADCRESULT1;//B1
    
      VY = AdcMirror.ADCRESULT3;//B2
    
      VB = AdcMirror.ADCRESULT5;//B3
    
      
    
    
    
    
      Idca= IDC*79/4095;
    
     EALLOW; //reset watchdog
    
     SysCtrlRegs.WDKEY = 0x55;
    
     SysCtrlRegs.WDKEY = 0xAA;
    
     EDIS;
    
    //reset the gpio7 for latency check
    
      GpioDataRegs.GPACLEAR.bit.GPIO7 = 1;
    
    }
    
    
    
    
    #pragma CODE_SECTION(timer0_int, "ramfuncs");
    
    void timer0_int(void)
    
    { 
    
    
    
    
      GpioDataRegs.GPATOGGLE.bit.GPIO21 = 1;
    
      CpuTimer0Regs.TCR.bit.TIF = 1;
    
      
    
    
    
    
      PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    
    
    
    
      EALLOW; //reset watchdog
    
      SysCtrlRegs.WDKEY = 0x55;
    
      SysCtrlRegs.WDKEY = 0xAA;
    
      EDIS;
    
    }
    
    
    
    
    #pragma CODE_SECTION(pwm4_ctr_0, "ramfuncs");
    
    void pwm4_ctr_0(void)
    
    {
    
    
    
    
     GpioDataRegs.GPASET.bit.GPIO7 = 1;
    
    
    
    
    
    
    
      EPwm4Regs.ETCLR.bit.INT = 1;
    
      PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
    
    
    
    
      EALLOW; //reset watchdog
    
      SysCtrlRegs.WDKEY = 0x55;
    
      SysCtrlRegs.WDKEY = 0xAA;
    
      EDIS;
    
    }

  • Hi Rajesh,

    If the codestartbranch.asm is included, and if your linker command file has codestart mapped to the flash entry point (BEGIN), then you should be good in terms of calling the c_init routine.

    You said that the watchdog is enabled -> Is your application servicing it or not?  If not, the watchdog can cause reset.  

    Sorry, I may not be able to review your code.  As long as the variables are initialized before using them, it should be good I think.

    See if this helps you: https://www.ti.com/lit/pdf/spra958  

    Thanks and regards,
    Vamsi

  • The watch dog is being serviced. But I don't understand why the micro-controller gets hanged and to make normal I have to switch it OFF and ON. Besides, I am not able to look into any variables during running as emulator gets disconnected.

    Regards,

    Rajesh BN.

  • Hi Rajesh,

    You said you have to do a power cycle (OFF/ON) to bring the device out of hang scenario.  What happens once you power cycle?  Does the application work as intended after the power cycle?

    Thanks and regards,
    Vamsi

  • Hi Rajesh,

    Just to confirm: Application works fine immediately after the program operation with debugger connected.  It does not work when you issue a reset with debugger connected (what reset did you give? - debugger reset?).  However, it works if you do a power cycle without debugger connected.

    Is the summary correct?

    Thanks and regards,
    Vamsi

  • Hi Vamsi,

    I've made an observed that this condition(hanging) occurs when the emulator is connected to the board. Coming to the standalone issue, I assume at this point that it has been sorted out. Actually, it has worked after F28335.cmd file is linked in the properties page replacing the Headers_nonBIOS.cmd file.

  • Hi Rajesh,

    Thank you for the detail.

    I will ask our F28335 expert to help you further.

    Thanks and regards,
    Vamsi

  • Looking forward!

    Thank you,

    Rajesh BN.

  • Rajesh,

    I'm wondering if we are running into the code security module, you mention that the JTAG disconnects when you run, if the CSM is activated and we attempt to step through a secure memory(all flash and L0-L3 memories) it will break the JTAG connection.  Even if you have not programmed a password, you will still need to do a dummy read of the CSM password locations to de-activate security.

    I code in an unsecure region attempts to directly read into a secure region it will return all 0x0000s, which could cause some issues in the code.  

    Can you confirm there is a read of addresses 0x33 FFF8 -0x33 FFFF near the beginning of your code to disable the CSM?  Even if we want to use CSM in the final product I'd like to remove that from the potential list of issues.

    The other option is that when the emulator is connected we are going to use the GEL file that does some pre-work that the BROM would normally do.  If you perform a reset with the debugger connected, can you see how far you get when single stepping before we either lose connection or get stuck before jumping to "main"?

    Best,

    Matthew