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.

TMS320F28035: Timer Base counter fail ?

Part Number: TMS320F28035
Other Parts Discussed in Thread: DRV8837, CONTROLSUITE

Hello,

I use epwm1 to feed a DRV8837 (based on 2xDC motor example).

I use ADCs to sense motor current and 3 other signals.

ADC is sync on epwm1 to catch motor current.

 

It used to work fine for months but since the last update of my firmware I got a strange behaviour...

I don't think my changes are the real cause of this trouble see below

Initial code:

        // Compute filtered value of initial guide sensor position
        for(j = SIGNAL_LENGTH; j > 0; j--)
        {
            iirHall.input = AdcResult.ADCRESULT1 << 3;                              // SOC1, IQ12 to 15
            iirHall.calc(&iirHall);
            DELAY_US(40);
        }

        // Compute filtered value of initial paddle value
        for(j = SIGNAL_LENGTH; j > 0; j--)
        {
            iirClick.input = (AdcResult.ADCRESULT3 - AdcResult.ADCRESULT2) << 3;    // SOC3 - SOC2, IQ12 to 15
            iirClick.calc(&iirClick);
            DELAY_US(40);
        }

Changes:

        // Compute filtered value
        for(j = SIGNAL_LENGTH; j > 0; j--)
        {
            // Initial guide sensor position
            iirHall.input = AdcResult.ADCRESULT1 << 3;                              // SOC1, IQ12 to 15
            iirHall.calc(&iirHall);
            // Initial paddle value
            iirClick.input = (AdcResult.ADCRESULT3 - AdcResult.ADCRESULT2) << 3;    // SOC3 - SOC2, IQ12 to 15
            iirClick.calc(&iirClick);
            DELAY_US(40);
        }

In some unknown conditions, the ADCs do not start conversions (stays at offset value 80 after AdcOffsetSelfCal) or start later.

The TBCLKSYNC is enabled but the TBCTR is not always counting when starting from reset.

The following code make the issue even more frequent (not the case if TBCLKSYNC is enabled from DeviceInit() and no more changed)

    // Self calibration on internal ref
    AdcInit();

    // Enable 5V
    // Note: external 3.3V ref needs 2ms settling time
    GpioDataRegs.GPASET.bit.GPIO10 = 1;
    DELAY_US(2000.0L);

    // Initialize PWM module
    pwm1.PeriodMax = PWM_PRD_MAX;

    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
    EDIS;

    PWM_INIT_MACRO(pwm1)

    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
    EDIS;

    // Initialize ADC module
    ADC_MACRO_INIT()

 

The ADC conversions run well after a CCS restart in debug mode but neither after a reset.

On "release" run, the TMS320 is held around 800ms in reset by a MSP430 through XRS before starting.

If the MSP430 is reset, the TMS320 is reset again by the MSP430.

I guess this behaviour has been around since a while as the change seems so insignificant but now the TMS320 fail to start conversion frequently after reset.

Any idea on what may set the Timer Base module in trouble ?

Is there any other recommendation in order setting of ADC calibration, ePWM1 and ADCs soc ?

Is there any recommendation in case of using external ref for ADC after self calibration with internal bandgap ?

Config: CCS9.3 and ti-cgt-c2000_18.12.7.LTS

Thank you

  • ePWM1

    /* ==================================================================================
    File name:        F2803xPWM.H
                        
    Originator:	 Digital Control Systems Group
    			 Texas Instruments
    			 C:\ti\controlSUITE\libs\app_libs\motor_control\drivers\f2803x_v2.1
    Description: Header file containing data type, object, macro definitions and 
    			 initializers. This file is specific to PM302.510 PCB and configure ePWM 1
    
    Target: TMS320F280x family
                  
    =====================================================================================
    History:
    -------------------------------------------------------------------------------------
     07-28-2010	Version 1.0
    ------------------------------------------------------------------------------------*/
    
    #ifndef __F280X_PWM_H__
    #define __F280X_PWM_H__
    
    //#include "f2803xbmsk.h"
    
    /*----------------------------------------------------------------------------
    Initialization constant for the F280X Time-Base Control Registers for PWM Generation. 
    Sets up the timer to run free upon emulation suspend, count up-down mode
    prescaler 1.
    ----------------------------------------------------------------------------*/
    #define PWM_INIT_STATE ( FREE_RUN_FLAG +         \
                             PRDLD_IMMEDIATE  +       \
                             TIMER_CNT_UPDN +         \
                             HSPCLKDIV_PRESCALE_X_1 + \
                             CLKDIV_PRESCALE_X_1  +   \
                             PHSDIR_CNT_UP    +       \
                             CNTLD_DISABLE )
    
    /*----------------------------------------------------------------------------
    Initialization constant for the F280X Compare Control Register. 
    ----------------------------------------------------------------------------*/
    #define CMPCTL_INIT_STATE ( LOADAMODE_ZRO + \
                                LOADBMODE_ZRO + \
                                SHDWAMODE_SHADOW + \
                                SHDWBMODE_SHADOW )
    
    /*----------------------------------------------------------------------------
    Initialization constant for the F280X Action Qualifier Software Force Register. 
    ----------------------------------------------------------------------------*/
    #define AQSFRC_INIT_STATE	( RLDCSF_PRD )
    //#define AQSFRC_INIT_STATE	( RLDCSF_PRD + ACTSFA_CLEAR + ACTSFB_CLEAR + 0x04 + 0x20)
    
    /*----------------------------------------------------------------------------
    Initialization constant for the F280X Action Qualifier Output A Register. 
    ----------------------------------------------------------------------------*/
    #define AQCTLA_INIT_STATE	( CAU_SET + CAD_CLEAR )
    #define AQCTLB_INIT_STATE	( CAU_SET + CAD_CLEAR )
    
    /*----------------------------------------------------------------------------
    Initialization constant for the F280X Dead-Band Generator registers for PWM Generation. 
    Sets up the dead band for PWM and sets up dead band values.
    ----------------------------------------------------------------------------*/
    #define DBCTL_INIT_STATE	(BP_DISABLE)
    
    /*----------------------------------------------------------------------------
    Initialization constant for the F280X PWM Chopper Control register for PWM Generation. 
    ----------------------------------------------------------------------------*/
    #define  PCCTL_INIT_STATE	(CHPEN_DISABLE)
    
    /*----------------------------------------------------------------------------
    Initialization constant for the F280X Trip Zone Select Register 
    ----------------------------------------------------------------------------*/
    #define  TZSEL_INIT_STATE	(DISABLE_TZSEL)
    							            
    /*----------------------------------------------------------------------------
    Initialization constant for the F280X Trip Zone Control Register 
    ----------------------------------------------------------------------------*/
    //#define  TZCTL_INIT_STATE ( TZA_FORCE_LO + TZB_FORCE_LO + \
                                DCAEVT1_HI_Z + DCAEVT2_HI_Z + \
                                DCBEVT1_HI_Z + DCBEVT2_HI_Z )
                                                                     
    /*-----------------------------------------------------------------------------
    	Define the structure of the PWM Driver Object 
    -----------------------------------------------------------------------------*/
    typedef struct {   
            Uint16 PeriodMax;     // Parameter: PWM Half-Period in CPU clock cycles (Q0)
            int16 MfuncPeriod;    // Input: Period scaler (Q15) 
            int16 MfuncC1;        // Input: EPWM1 A&B Duty cycle ratio (Q15)
    		int16 PWM1out;
            } PWMGEN ;    
    
    /*-----------------------------------------------------------------------------
    	Define a PWMGEN_handle
    -----------------------------------------------------------------------------*/
    typedef PWMGEN *PWMGEN_handle;
    
    /*------------------------------------------------------------------------------
    	Default Initializers for the F280X PWMGEN Object 
    ------------------------------------------------------------------------------*/
    #define F280X_FC_PWM_GEN    { 1000,   \
                                  0x7FFF, \
                                  0x4000, \
    							  0x4000, \
                                 }
                                  
    
    #define PWMGEN_DEFAULTS 	F280X_FC_PWM_GEN
    
    /*------------------------------------------------------------------------------
    	PWM Init & PWM Update Macro Definitions
    ------------------------------------------------------------------------------*/
    #define PWM_INIT_MACRO(v)													\
    	     /* Setup Sync */													\
             EPwm1Regs.TBCTL.bit.SYNCOSEL = 0;       /* Pass through */			\
            																	\
             /* Allow each timer to be sync'ed */								\
             EPwm1Regs.TBCTL.bit.PHSEN = 1;										\
    																			\
             /* Init Timer-Base Period Register for EPWM1 */					\
             EPwm1Regs.TBPRD = v.PeriodMax;										\
    																			\
             /* Init Compare Register for EPWM1 */								\
             EPwm1Regs.CMPA.half.CMPA = v.PeriodMax;							\
    																			\
             /* Init Timer-Base Phase Register for EPWM1 */						\
             EPwm1Regs.TBPHS.half.TBPHS = 0;									\
    																			\
             /* Init Timer-Base Control Register for EPWM1 */					\
             EPwm1Regs.TBCTL.all = PWM_INIT_STATE;								\
    																			\
             /* Init Compare Control Register for EPWM1 */						\
             EPwm1Regs.CMPCTL.all = CMPCTL_INIT_STATE;							\
    																			\
             /* Init Action Qualifier Output A Register for EPWM1 */			\
             EPwm1Regs.AQCTLA.all = AQCTLA_INIT_STATE;							\
    																			\
             /* Init Action Qualifier Output B Register for EPWM1 */			\
             EPwm1Regs.AQCTLB.all = AQCTLB_INIT_STATE;							\
    																			\
             /* Init Action Qualifier S/W Force Register for EPWM1 */			\
             EPwm1Regs.AQSFRC.all = AQSFRC_INIT_STATE;							\
    																			\
             /* Init Dead-Band Generator Control Register for EPWM1 */			\
             EPwm1Regs.DBCTL.all = DBCTL_INIT_STATE;							\
    																			\
             /* Init PWM Chopper Control Register for EPWM1 */					\
             EPwm1Regs.PCCTL.all = PCCTL_INIT_STATE;							\
    																			\
             EALLOW;                       /* Enable EALLOW */					\
             /* Init Trip Zone Select Register */								\
             EPwm1Regs.TZSEL.all = TZSEL_INIT_STATE;							\
             /* Init Trip Zone Control Register */								\
             /*EPwm1Regs.TZCTL.all = TZCTL_INIT_STATE;	*/						\
             EDIS;                         /* Disable EALLOW */

    ADCs soc

    /* ==================================================================================
    File name:       F2803XADC.H
                        
    Originator:	Digital Control Systems Group
    			Texas Instruments
    			C:\ti\controlSUITE\libs\app_libs\motor_control\drivers\f2803x_v2.1
    
    Description: This header file contains macro definition for ADC initialization within PM 302
    
    Target: TMS320F2803x family
                  
    =====================================================================================
    History:
    -------------------------------------------------------------------------------------
     07-28-2010	Version 1.0 
    -----------------------------------------------------------------------------------*/
    
    #ifndef __F2803XADC_H__
    #define __F2803XADC_H__
    
    //#include "f2803xbmsk.h"
    
    /*-----------------------------------------------------------------------------------
     ADC Initialization Macro Definition 
    -----------------------------------------------------------------------------------*/
    #define ADC_usDELAY         1000L   // according to "SPRUI10 Technical Reference Manual"
    
    extern void DSP28x_usDelay(unsigned long Count);
    
    /*-----------------------------------------------------------------------------------
     Errata:
     - Avoid using ACQPS = 6 or 7
    
     Calibration:
     - Offset trim registers are erased upon an ADC master reset
         -> Do not perform ADC master reset else Device_cal() will be needed again
    
     ADC Power Modes:
    
        Mode A (operating)   Mode B (quick wake-up)  Mode C (Comparator)    Mode D (Off)
        13mA                  4mA                     1.5mA                 0.075mA
    
        BG ON                 BG ON                   BG ON                 BG OFF
        REF ON                REF ON                  REF OFF               REF OFF
        ADC ON                ADC OFF                 ADC OFF               ADC OFF
    -----------------------------------------------------------------------------------*/
    
    #define ADC_MACRO_INIT()																		\
    																								\
    	/*DELAY_US(ADC_usDELAY);*/																	\
    	/*AdcRegs.ADCCTL1.bit.RESET       = 1;	    Needs 2 cycles */						        \
    	/*asm(" NOP ");*/																			\
    	/*asm(" NOP ");*/    																		\
    																								\
    	EALLOW;																						\
    	                                                                                            \
    	AdcRegs.ADCCTL1.bit.ADCREFSEL	= 1;	/* External ref */									\
       	AdcRegs.ADCCTL1.bit.ADCREFPWD	= 1;	/* Power up reference */							\
       	AdcRegs.ADCCTL1.bit.ADCBGPWD    = 1;    /* Power up band gap */                             \
       	AdcRegs.ADCCTL1.bit.ADCPWDN 	= 1;	/* Power up rest of ADC */							\
    	AdcRegs.ADCCTL1.bit.ADCENABLE	= 1;	/* Enable ADC */									\
    	                                                                                            \
    	DELAY_US(ADC_usDELAY);                  /* Delay before performing the first conversion */  \
    																								\
    	asm(" RPT#100 || NOP");					/* useful ? */  									\
    																								\
    	AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;	/* Interrupt pulse 1 cycle prior latching result */	\
    	AdcRegs.ADCCTL1.bit.TEMPCONV 	= 0;	/* No temperature conversion (A5) */				\
    	AdcRegs.ADCCTL2.bit.ADCNONOVERLAP = 1;  /* Overlap of sample is not allowed */              \
    																								\
    	/*DELAY_US(ADC_usDELAY);                    not useful... */            					\
    																								\
    	/******* CHANNEL SELECT *******/		                                                    \
    	/* Errata: Avoid using ACQPS value 6 and 7 */												\
    	AdcRegs.ADCSOC0CTL.bit.CHSEL 	= 1;   	/* ChSelect: ADC A1-> Motor current */ 			    \
    	AdcRegs.ADCSOC0CTL.bit.TRIGSEL 	= 5;	/* Set SOC0 start trigger on EPWM1A */				\
    	AdcRegs.ADCSOC0CTL.bit.ACQPS 	= 63;	/* Set SOC0 S/H Window to 64 ADC Clock Cycles, (63 ACQPS plus 1) */	\
    																								\
    	AdcRegs.ADCSOC1CTL.bit.CHSEL 	= 2;	/* ChSelect: ADC A2-> VHall Out */					\
    	AdcRegs.ADCSOC1CTL.bit.TRIGSEL  = 5;	/* Set SOC1 start trigger on software? */			\
    	AdcRegs.ADCSOC1CTL.bit.ACQPS 	= 63;	/* Conversion time 1283ns */	                    \
    																								\
    	AdcRegs.ADCSOC2CTL.bit.CHSEL    = 6;    /* ChSelect: ADC A6-> Click Down */ 				\
    	AdcRegs.ADCSOC2CTL.bit.TRIGSEL  = 5;	/* Set SOC2 start trigger on software? */			\
    	AdcRegs.ADCSOC2CTL.bit.ACQPS 	= 63;	/* Conversion time 1283ns */						\
    																								\
    	AdcRegs.ADCSOC3CTL.bit.CHSEL 	= 4;    /* ChSelect: ADC A4-> Click Up */					\
    	AdcRegs.ADCSOC3CTL.bit.TRIGSEL 	= 5;	/* Set SOC3 start trigger on software? */			\
    	AdcRegs.ADCSOC3CTL.bit.ACQPS 	= 63;	/* Conversion time 1283ns */						\
    	           																					\
    	EDIS;																						\
    																								\
    																								\
        /* Set up Event Trigger with CNT_zero enable for Time-base of EPWM1 */						\
        EPwm1Regs.ETSEL.bit.SOCAEN = 1;     /* Enable SOCA */										\
        EPwm1Regs.ETSEL.bit.SOCASEL = 1;    /* Enable CNT_zero event for SOCA */					\
        EPwm1Regs.ETPS.bit.SOCAPRD = 1;     /* Generate SOCA on the 1st event */					\
    	EPwm1Regs.ETCLR.bit.SOCA = 1;       /* Clear SOCA flag */									\
    																								\
    
    #endif // __F2803XADC_H__

    The TMS is running on INTOSC1 at 40MHz (wait on PLL lock).

  • Which example project are you based on? And please just show the changes on the example codes that help us to understand your question quickly.

    The ADC conversions run well after a CCS restart in debug mode but neither after a reset.

    Do you click "RESET" first, and then click on "RESTART" within CCS?

    Any idea on what may set the Timer Base module in trouble ?

    You might check if the PWM registers are set correctly, and the clock for the ePWM module is enabled.

    Is there any recommendation in case of using external ref for ADC after self calibration with internal bandgap ?

    You might refer to the example in controlSUITE as below. You just need to change the ADC control register for using the external reference.

    C:\ti\controlSUITE\device_support\f2803x\v130\DSP2803x_examples_ccsv5\adc_soc

  • Hi,

    The problem seems solved... I know what code part but not exactly why.

    What I changed is to move a gpio settings out of DeviceInit() and put it after AdcInit(). This GPIO goes high to enable a 5V buckboost which powers motor, coder and OPAs. The OPA are routed on the ADCIN of the TMS320 to read some sensors and one of them give a non-zero signal before the TMS320 has started (which is still the case).

    void main(void)
    {
        DeviceInit();   // Device Life support & GPIO
        InitSciGpio();  // SCI specific GPIO option
    
        // Self calibration on internal ref
        AdcInit();
    
        // Initialize PWM module
        // Note: disable and re-enable TBCLKSYNC to set PWM decrease liability (whatever datasheet says...)
        pwm1.PeriodMax = PWM_PRD_MAX;
        PWM_INIT_MACRO(pwm1)
    
        // Enable 5V
        // Note: external 3.3V ref needs 2ms settling time
        GpioDataRegs.GPASET.bit.GPIO10 = 1;
        DELAY_US(2000.0L);
    
        // Initialize ADC module
        ADC_MACRO_INIT()

    To respond your questions:

    • I clicked either Restart or Reset + Restart
    • The PWM clock is enabled and well configured

    My question about ADC ref setting was about the necessity to power down bandgap, ADC and REF before changing REF source or not.