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.

How to change the interrupt source of DPLib routine?

Other Parts Discussed in Thread: CONTROLSUITE

HI,

 

I am now using the template “C:\ti\controlSUITE\development_kits\TemplateProjects\DPLibv3_4Template-F2803x” inside the controlSUITE on my F28069 Piccolo Experimenter Kit.

 

Initially, I set the duty cycle of the ePWM2 to be 0.2 at the main()

Duty2A =_IQ24(0.2);

 

And then I add one more line at C1 task:

void C1(void)      

//------------------------------------------------------

{

     Duty2A =_IQ24(0.6);

 

     //-----------------

     //the next time CpuTimer2 'counter' reaches Period value go to C2

     C_Task_Ptr = &C2;

     //-----------------

 

}

 

I observed from the CRO that the duty of ePWM2 is 0.6, which is expected.

 

And then, I would like to change the interrupt source of DPLib from ePWM2 Int to ePWM4 Int. I made the following changes:

 

The external variable and variable inside main.c

// PWMDRV_1ch

extern volatile long *PWMDRV_1ch_Duty4;       // instance #2, EPWM4

volatile long Duty4A;

 

the init function of ePWM changed from 2 to 4

PWM_1ch_CNF(4, 300,0,0);

 

The init value inside main()

Duty4A =_IQ24(0.2);

 

The updated value inside C1 task:

Duty4A =_IQ24(0.6);

 

 

The Interrupt setting

// Set up C28x Interrupt

 

//Also Set the appropriate # define's in the {ProjectName}-Settings.h

//to enable interrupt management in the ISR

        EALLOW;

    PieVectTable.EPWM4_INT = &DPL_ISR;           // Map Interrupt

    EPwm4Regs.ETSEL.bit.SOCAEN     = 1;

     PieCtrlRegs.PIEIER3.bit.INTx4 = 1;            // PIE level enable, Grp3 / Int4

     EPwm4Regs.ETSEL.bit.INTSEL = ET_CTR_PRD;    // INT on PRD event

     EPwm4Regs.ETSEL.bit.INTEN = 1;              // Enable INT

    EPwm4Regs.ETPS.bit.INTPRD = ET_1ST;         // Generate INT on every event

 

    IER |= M_INT3;                             // Enable CPU INT3 connected to EPWM1-6 INTs:

    EINT;                                     // Enable Global interrupt INTM

    ERTM;                                           // Enable Global realtime interrupt DBGM

        EDIS;     

 

The Init and  the run time function inside ProjectName-DPL-ISR.asm

 

PWMDRV_1ch_INIT 4     ; PWM4A

 

 

PWMDRV_1ch 4              ; PWM4A

 

I observed from the CRO again and found that the duty of ePWM4 is 0.2 not 0.6, which implies the DPLib routine can only run one time, the updated value inside C1 task cannot be pass to the DPLib routine. I am pleasure if anyone can help, thank you.

 

Barry

  • Yes, the way you're updating the duty is erroneous. Can you attach the c file or screenshot?

    Regards,

    Gautam

  • Dear Gautam,

    Attached please find the files.

    BR,

    Barry

    //----------------------------------------------------------------------------------
    //	FILE:			ProjectName-Main.c
    //
    //	Description:	Sample Template file to edit
    //					The file drives duty on PWM1A using CLA and PWM2 using C28x
    //					These can be deleted and modified by the user
    //					CLA Task is triggered by the PWM 1 interrupt
    //					C28x ISR is triggered by the PWM 2 interrupt  
    //
    //	Version: 		3.4
    //
    //  Target:  		TMS320F2803x(PiccoloB)
    //
    //----------------------------------------------------------------------------------
    //  Copyright Texas Instruments �2004-2010
    //----------------------------------------------------------------------------------
    //  Revision History:
    //----------------------------------------------------------------------------------
    //  Date	  | Description / Status
    //----------------------------------------------------------------------------------
    // October 2012  - Sample template project with DPlibv3.4 (MB)
    //----------------------------------------------------------------------------------
    //
    // PLEASE READ - Useful notes about this Project
    
    // Although this project is made up of several files, the most important ones are:
    //	 "{ProjectName}-Main.c"	- this file
    //		- Application Initialization, Peripheral configuration,
    //		- Application management
    //		- Slower background code loops and Task scheduling
    //	 "{ProjectName}-DevInit_F28xxx.c
    //		- Device Initialization, e.g. Clock, PLL, WD, GPIO mapping
    //		- Peripheral clock enables
    //		- DevInit file will differ per each F28xxx device series, e.g. F280x, F2833x,
    //	 "{ProjectName}-CLA_Tasks.cla"
    //		- Initialization code for DPlib CLA Macros
    //		- CLA Task code
    //	 "{ProjectName}-Settings.h"
    //		- Global defines (settings) project selections are found here
    //		- This file is referenced by both C and ASM files.
    //	 "{ProjectName}-CLA_Shared.h"
    //		- Variable defines and header includes that are shared between CLA and C28x
    //
    // Code is made up of sections, e.g. "FUNCTION PROTOTYPES", "VARIABLE DECLARATIONS" ,..etc
    //	each section has FRAMEWORK and USER areas.
    //  FRAMEWORK areas provide useful ready made "infrastructure" code which for the most part
    //	does not need modification, e.g. Task scheduling, ISR call, GUI interface support,...etc
    //  USER areas have functional example code which can be modified by USER to fit their appl.
    //
    // Code can be compiled with various build options (Incremental Builds IBx), these
    //  options are selected in file "{ProjectName}-Settings.h".  Note: "Rebuild All" compile
    //  tool bar button must be used if this file is modified.
    //----------------------------------------------------------------------------------
    //Uint64
    #include "F2806x_Device.h"
    #include "ProjectName-CLA_Shared.h"
    #include "F2806x_EPwm_defines.h"
    #include "IQmathLib.h"
    
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    // FUNCTION PROTOTYPES
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    // Add prototypes of functions being used in the project here
    void DeviceInit(void);
    #ifdef FLASH		
    	void InitFlash();
    #endif
    void MemCopy();
    void CLA_Init();
    //-------------------------------- DPLIB --------------------------------------------
    void PWM_1ch_CNF(int16 n, Uint16 period, int16 mode, int16 phase);
    void ADC_SOC_CNF(int ChSel[], int Trigsel[], int ACQPS[], int IntChSel, int mode);
    // -------------------------------- FRAMEWORK --------------------------------------
    // State Machine function prototypes
    //----------------------------------------------------------------------------------
    // Alpha states
    void A0(void);	//state A0
    void B0(void);	//state B0
    void C0(void);	//state C0
    
    // A branch states
    void A1(void);	//state A1
    void A2(void);	//state A2
    void A3(void);	//state A3
    void A4(void);	//state A4
    
    // B branch states
    void B1(void);	//state B1
    void B2(void);	//state B2
    void B3(void);	//state B3
    void B4(void);	//state B4
    
    // C branch states
    void C1(void);	//state C1
    void C2(void);	//state C2
    void C3(void);	//state C3
    void C4(void);	//state C4
    
    // Variable declarations
    void (*Alpha_State_Ptr)(void);	// Base States pointer
    void (*A_Task_Ptr)(void);		// State pointer A branch
    void (*B_Task_Ptr)(void);		// State pointer B branch
    void (*C_Task_Ptr)(void);		// State pointer C branch
    //----------------------------------------------------------------------------------
    
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    // VARIABLE DECLARATIONS - GENERAL
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    // -------------------------------- FRAMEWORK --------------------------------------
    
    int16	VTimer0[4];					// Virtual Timers slaved off CPU Timer 0
    int16	VTimer1[4];					// Virtual Timers slaved off CPU Timer 1
    int16	VTimer2[4];					// Virtual Timers slaved off CPU Timer 2
    
    // Used for running BackGround in flash, and ISR in RAM
    extern unsigned int RamfuncsLoadStart, RamfuncsLoadSize, RamfuncsRunStart;
    
    // Used for ADC Configuration 
    int ChSel[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int	TrigSel[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int ACQPS[16] = {8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8};
    
    // Used to indirectly access all EPWM modules
    volatile struct EPWM_REGS *ePWM[] = 
     				  { &EPwm1Regs,			//intentional: (ePWM[0] not used)
    				  	&EPwm1Regs,
    					&EPwm2Regs,
    					&EPwm3Regs,
    					&EPwm4Regs,
    					&EPwm5Regs,
    					&EPwm6Regs,
    					&EPwm7Regs,
    				  };
    
    // Used to indirectly access all Comparator modules
    volatile struct COMP_REGS *Comp[] = 
     				  { &Comp1Regs,			//intentional: (Comp[0] not used)
    					&Comp1Regs,				  
    					&Comp2Regs,
    					&Comp3Regs, 
    				  };
    // ---------------------------------- USER -----------------------------------------
    // ---------------------------- DPLIB Net Pointers ---------------------------------
    // Declare net pointers that are used to connect the DP Lib Macros  here 
    
    // PWMDRV_1ch
    extern volatile long *PWMDRV_1ch_Duty4;		// instance #2, EPWM2
    
    // ---------------------------- DPLIB Variables ---------------------------------
    // Declare the net variables being used by the DP Lib Macro here 
    
    // PWMDRV_1ch_CLA_C
    extern volatile float32 CLA_Duty1;	// instance #1, EPWM1
    
    volatile float Duty1A; 
    volatile long Duty4A;
    
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    // VARIABLE DECLARATIONS - CCS WatchWindow / GUI support
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    // -------------------------------- FRAMEWORK --------------------------------------
    
    //GUI support variables
    // sets a limit on the amount of external GUI controls - increase as necessary
    int16 	*varSetTxtList[16];					//16 textbox controlled variables
    int16 	*varSetBtnList[16];					//16 button controlled variables
    int16 	*varSetSldrList[16];				//16 slider controlled variables
    int16 	*varGetList[16];					//16 variables sendable to GUI
    int16 	*arrayGetList[16];					//16 arrays sendable to GUI	
    int16  LedBlinkCnt;
    
    // ---------------------------------- USER -----------------------------------------
    
    // Monitor ("Get")						// Display as:
    
    // Configure ("Set")
    
    // History arrays are used for Running Average calculation (boxcar filter)
    // Used for CCS display and GUI only, not part of control loop processing
    
    //Scaling Constants (values found via spreadsheet; exact value calibrated per board)
    
    // Variables for background support only (no need to access)
    int16	i;								// common use incrementer
    Uint32	HistPtr, temp_Scratch; 			// Temp here means Temporary
    
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    // MAIN CODE - starts here
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    void main(void)
    {
    //=================================================================================
    //	INITIALIZATION - General
    //=================================================================================
    
    	// The DeviceInit() configures the clocks and pin mux registers 
    	// The function is declared in {ProjectName}-DevInit_F2803/2x.c,
    	// Please ensure/edit that all the desired components pin muxes 
    	// are configured properly that clocks for the peripherals used
    	// are enabled, for example the individual PWM clock must be enabled 
    	// along with the Time Base Clock 
    
    	DeviceInit();	// Device Life support & GPIO
    
    //-------------------------------- FRAMEWORK --------------------------------------
    
    // Only used if running from FLASH
    // Note that the variable FLASH is defined by the compiler with -d FLASH
    
    #ifdef FLASH		
    // Copy time critical code and Flash setup code to RAM
    // The  RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
    // symbols are created by the linker. Refer to the linker files.
    	memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (Uint32) &RamfuncsLoadSize);
    //	MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
    
    // Call Flash Initialization to setup flash wait-states
    // This function must reside in RAM
    	InitFlash();	// Call the flash wrapper initialization function
    #endif //(FLASH)
    
    // Timing sync for background loops
    // Timer period definitions found in PeripheralHeaderIncludes.h
    	CpuTimer0Regs.PRD.all =  mSec1;		// A tasks
    	CpuTimer1Regs.PRD.all =  mSec10;	// B tasks
    	CpuTimer2Regs.PRD.all =  mSec100;	// C tasks
    
    // Tasks State-machine init
    	Alpha_State_Ptr = &A0;
    	A_Task_Ptr = &A1;
    	B_Task_Ptr = &B1;
    	C_Task_Ptr = &C1;
    
    	VTimer0[0] = 0;	
    	VTimer1[0] = 0;
    	VTimer2[0] = 0;
    	LedBlinkCnt = 5;
    
    // ---------------------------------- USER -----------------------------------------
    //  put common initialization/variable definitions here
    
    
    //===============================================================================
    //	INITIALIZATION - GUI connections
    //=================================================================================
    // Use this section only if you plan to "Instrument" your application using the 
    // Microsoft C# freeware GUI Template provided by TI
    /*
    	//"Set" variables
    	//---------------------------------------
    	// assign GUI variable Textboxes to desired "setable" parameter addresses
    	varSetTxtList[0] = &Gui_TxtListVar;
    	varSetTxtList[1] = &Gui_TxtListVar;
    	varSetTxtList[2] = &Gui_TxtListVar;
    	varSetTxtList[3] = &Gui_TxtListVar;
    	varSetTxtList[4] = &Gui_TxtListVar;
    	varSetTxtList[5] = &Gui_TxtListVar;
    	varSetTxtList[6] = &Gui_TxtListVar;
    	varSetTxtList[7] = &Gui_TxtListVar;
    	varSetTxtList[8] = &Gui_TxtListVar;
    	varSetTxtList[9] = &Gui_TxtListVar;
    	varSetTxtList[10] = &Gui_TxtListVar;
    	varSetTxtList[11] = &Gui_TxtListVar;
    
    	// assign GUI Buttons to desired flag addresses
    	varSetBtnList[0] = &Gui_BtnListVar;
        varSetBtnList[1] = &Gui_BtnListVar;
    	varSetBtnList[2] = &Gui_BtnListVar;
    	varSetBtnList[3] = &Gui_BtnListVar;
    	varSetBtnList[4] = &Gui_BtnListVar;
    
    	// assign GUI Sliders to desired "setable" parameter addresses
    	varSetSldrList[0] = &Gui_SldrListVar;
    	varSetSldrList[1] = &Gui_SldrListVar;
    	varSetSldrList[2] = &Gui_SldrListVar;
    	varSetSldrList[3] = &Gui_SldrListVar;
    	varSetSldrList[4] = &Gui_SldrListVar;
    
    	//"Get" variables
    	//---------------------------------------
    	// assign a GUI "getable" parameter address
    	varGetList[0] = &Gui_GetListVar;
    	varGetList[1] = &Gui_GetListVar;
    	varGetList[2] = &Gui_GetListVar;
    	varGetList[3] = &Gui_GetListVar;
    	varGetList[4] = &Gui_GetListVar;
    	varGetList[5] = &Gui_GetListVar;
    	varGetList[6] = &Gui_GetListVar;
    	varGetList[7] = &Gui_GetListVar;
    	varGetList[8] = &Gui_GetListVar;
    	varGetList[9] = &Gui_GetListVar;
    	varGetList[10] = &Gui_GetListVar;
    	varGetList[11] = &Gui_GetListVar;
    	varGetList[12] = &Gui_GetListVar;
    	varGetList[13] = &Gui_GetListVar;
    	varGetList[14] = &Gui_GetListVar;
    	varGetList[15] = &Gui_GetListVar;
    
    	// assign a GUI "getable" parameter array address
    	arrayGetList[0] = &DBUFF1;  	//only need to set initial position of array,
    	arrayGetList[1] = &DBUFF2;		//  program will run through it accordingly
    	arrayGetList[2] = &DBUFF3;
    	arrayGetList[3] = &DBUFF4;
    */
    
    //==================================================================================
    //	INCREMENTAL BUILD OPTIONS - NOTE: selected via {ProjectName-Settings.h
    //==================================================================================
    // ---------------------------------- USER -----------------------------------------
    
    //----------------------------------------------------------------------
    #if (INCR_BUILD == 1) 	// Open Loop Two Phase Interleaved PFC PWM Driver
    //----------------------------------------------------------------------
    	
    	// Configure PWM2 for 200Khz switching Frequency
    	//Period Count= 60Mhz/200Khz = 300 
    	PWM_1ch_CNF(4, 300,0,0);
       	
       	// Configure ADC to be triggered from EPWM1 Period event 
       	//Map channel to ADC Pin
       	ChSel[0]=14;		//Map channel 0 to pin ADC-B6
       	// for additional ADC conversions modify below
       	/*ChSel[1]=n;		//An
       	ChSel[2]=n;			//An
       	ChSel[3]=n;			//An
       	ChSel[4]=n;			//An
       	ChSel[5]=n;			//An
       	ChSel[6]=n;			//An
       	ChSel[7]=n;			//An
       	ChSel[8]=n;			//An
       	ChSel[9]=n;			//An
       	ChSel[10]=n;		//An
       	ChSel[11]=n;		//An
       	ChSel[12]=n;		//An
       	ChSel[13]=n;		//An
       	ChSel[14]=n;		//An
       	ChSel[15]=n;		//An
       	*/
       	
       	// Select Trigger Event for ADC conversion 
       	TrigSel[0]= ADCTRIG_EPWM1_SOCA;
       	// associate the appropriate peripheral trigger to the ADC channel
       	/*TrigSel[1]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[2]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[3]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[4]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[5]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[6]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[7]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[8]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[9]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[10]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[11]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[12]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[13]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[14]= ADCTRIG_EPWMn_SOCA;
       	TrigSel[15]= ADCTRIG_EPWMn_SOCA;*/
       	
       	// Configure the ADC with auto interrupt clear mode
       	// ADC interrupt after EOC of channel 0
       	ADC_SOC_CNF(ChSel,TrigSel,ACQPS,0,2); 
       	
       	// Configure the EPWM1 to issue the SOC 
    	EPwm1Regs.ETSEL.bit.SOCAEN 	= 1;
    	EPwm1Regs.ETSEL.bit.SOCASEL = ET_CTR_PRD;	// Use PRD event as trigger for ADC SOC 
        EPwm1Regs.ETPS.bit.SOCAPRD 	= ET_1ST;        // Generate pulse on every event 
    	
    	// Digital Power CLA(DP) library initialization
    	DPL_CLAInit();
    	DPL_Init();
    	
    	// Lib Module connection to "nets" 
    	//----------------------------------------
    	// Connect the PWM Driver input to an input variable, Open Loop System
    	PWMDRV_1ch_Duty4     = &Duty4A;
    	
    	// Initialize the net variables
    	CLA_Duty1 =(float32)(0.5);
    	Duty4A =_IQ24(0.2);
    		
    	CLA_Init();
    	
    #endif // (INCR_BUILD == 1)
    
    //====================================================================================
    // INTERRUPTS & ISR INITIALIZATION (best to run this section after other initialization)
    //====================================================================================
    
    // Set Up CLA Task
    
    // Task 1 has the option to be started by either EPWM1_INT or ADCINT1 
    // In this case we will allow ADCINT1 to start CLA Task 1
        EALLOW;
        
    	// Configure PWM1 to issue interrupts
    	EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_PRD;  	// INT on PRD event
       	EPwm1Regs.ETSEL.bit.INTEN = 1;              // Enable INT
        EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;         // Generate INT on every event
    	
    	Cla1Regs.MPISRCSEL1.bit.PERINT1SEL = CLA_INT1_EPWM1INT ;		// 0=ADCINT1    1=none    2=EPWM1INT
    	
    	// Configure the interrupt that would occur each control cycles
        Cla1Regs.MIER.all = M_INT1;
      
    	asm("   RPT #3 || NOP"); 
    	
    	EDIS;
    	
    // Set up C28x Interrupt
    
    //Also Set the appropriate # define's in the {ProjectName}-Settings.h 
    //to enable interrupt management in the ISR
    	EALLOW;
        PieVectTable.EPWM4_INT = &DPL_ISR;      	// Map Interrupt
        EPwm4Regs.ETSEL.bit.SOCAEN 	= 1;
       	PieCtrlRegs.PIEIER3.bit.INTx4 = 1;      	// PIE level enable, Grp3 / Int2
       	EPwm4Regs.ETSEL.bit.INTSEL = ET_CTR_PRD;  	// INT on PRD event
       	EPwm4Regs.ETSEL.bit.INTEN = 1;              // Enable INT
        EPwm4Regs.ETPS.bit.INTPRD = ET_1ST;         // Generate INT on every event
    
        IER |= M_INT3;                          	// Enable CPU INT3 connected to EPWM1-6 INTs:
        EINT;                                   	// Enable Global interrupt INTM
        ERTM;                                   	// Enable Global realtime interrupt DBGM
    	EDIS;      
    
    //=================================================================================
    //	BACKGROUND (BG) LOOP
    //=================================================================================
    
    //--------------------------------- FRAMEWORK -------------------------------------
    	for(;;)  //infinite loop
    	{
    		// State machine entry & exit point
    		//===========================================================
    		(*Alpha_State_Ptr)();	// jump to an Alpha state (A0,B0,...)
    		//===========================================================
    
    
    
    	}
    } //END MAIN CODE
    
    /**
     * Configure hardware peripherals used by the CLA.
     */
    void DPL_CLAInit(){
    	// Configure PWM1 for 200Khz switching Frequency
    	// Period Count= 60Mhz/200Khz = 300
    
    	PWM_1ch_CNF(1, 300,1,0);
    }
    
    
    
    //=================================================================================
    //	STATE-MACHINE SEQUENCING AND SYNCRONIZATION
    //=================================================================================
    
    //--------------------------------- FRAMEWORK -------------------------------------
    void A0(void)
    {
    	// loop rate synchronizer for A-tasks
    	if(CpuTimer0Regs.TCR.bit.TIF == 1)
    	{
    		CpuTimer0Regs.TCR.bit.TIF = 1;	// clear flag
    
    		//-----------------------------------------------------------
    		(*A_Task_Ptr)();		// jump to an A Task (A1,A2,A3,...)
    		//-----------------------------------------------------------
    
    		VTimer0[0]++;			// virtual timer 0, instance 0 (spare)
    	}
    
    	Alpha_State_Ptr = &B0;		// Comment out to allow only A tasks
    }
    
    void B0(void)
    {
    	// loop rate synchronizer for B-tasks
    	if(CpuTimer1Regs.TCR.bit.TIF == 1)
    	{
    		CpuTimer1Regs.TCR.bit.TIF = 1;				// clear flag
    
    		//-----------------------------------------------------------
    		(*B_Task_Ptr)();		// jump to a B Task (B1,B2,B3,...)
    		//-----------------------------------------------------------
    		VTimer1[0]++;			// virtual timer 1, instance 0 (spare)
    	}
    
    	Alpha_State_Ptr = &C0;		// Allow C state tasks
    }
    
    void C0(void)
    {
    	// loop rate synchronizer for C-tasks
    	if(CpuTimer2Regs.TCR.bit.TIF == 1)
    	{
    		CpuTimer2Regs.TCR.bit.TIF = 1;				// clear flag
    
    		//-----------------------------------------------------------
    		(*C_Task_Ptr)();		// jump to a C Task (C1,C2,C3,...)
    		//-----------------------------------------------------------
    		VTimer2[0]++;			//virtual timer 2, instance 0 (spare)
    	}
    
    	Alpha_State_Ptr = &A0;	// Back to State A0
    }
    
    
    //=================================================================================
    //	A - TASKS
    //=================================================================================
    //--------------------------------------------------------
    void A1(void) 
    //--------------------------------------------------------
    {
    	
    	//-------------------
    	//the next time CpuTimer0 'counter' reaches Period value go to A2
    	A_Task_Ptr = &A2;
    	//-------------------
    }
    
    //-----------------------------------------------------------------
    void A2(void) 
    //-----------------------------------------------------------------
    {	 
    	//-------------------
    	//the next time CpuTimer0 'counter' reaches Period value go to A1
    	A_Task_Ptr = &A3;
    	//-------------------
    }
    
    //-----------------------------------------
    void A3(void)	
    //-----------------------------------------
    {
    	
    	//-----------------
    	//the next time CpuTimer0 'counter' reaches Period value go to A1
    	A_Task_Ptr = &A4;
    	//-----------------
    }
    
    
    //----------------------------------------------------------
    void A4(void) 
    //---------------------------------------------------------
    {
    	//-----------------
    	//the next time CpuTimer0 'counter' reaches Period value go to A1
    	A_Task_Ptr = &A1;
    	//-----------------
    }
    
    
    //=================================================================================
    //	B - TASKS
    //=================================================================================
    
    //----------------------------------- USER ----------------------------------------
    
    //----------------------------------------
    void B1(void)
    //----------------------------------------
    {
    	//-----------------
    	//the next time CpuTimer1 'counter' reaches Period value go to B2
    	B_Task_Ptr = &B2;	
    	//-----------------
    }
    
    //----------------------------------------
    void B2(void) // Blink LED on the control CArd
    //----------------------------------------
    {
    	if(LedBlinkCnt==0)
    		{
    			GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;	//turn on/off LD3 on the controlCARD
    			LedBlinkCnt=5;
    		}
    	else
    			LedBlinkCnt--;
    			
    	//-----------------
    	//the next time CpuTimer1 'counter' reaches Period value go to B3
    	B_Task_Ptr = &B3;
    	//-----------------
    }
    
    //----------------------------------------
    void B3(void)  
    //----------------------------------------
    {
    	//-----------------
    	//the next time CpuTimer1 'counter' reaches Period value go to B4
    	B_Task_Ptr = &B4;	
    	//-----------------
    }
    
    //----------------------------------------
    void B4(void) //  SPARE
    //----------------------------------------
    {
    	//-----------------
    	//the next time CpuTimer1 'counter' reaches Period value go to B1
    	B_Task_Ptr = &B1;	
    	//-----------------
    }
    
    
    //=================================================================================
    //	C - TASKS
    //=================================================================================
    
    //--------------------------------- USER ------------------------------------------
    
    //------------------------------------------------------
    void C1(void) 	 
    //------------------------------------------------------
    {
    	Duty4A =_IQ24(0.6);
    
    	//-----------------
    	//the next time CpuTimer2 'counter' reaches Period value go to C2
    	C_Task_Ptr = &C2;	
    	//-----------------
    
    }
    
    //----------------------------------------
    void C2(void) 
    //----------------------------------------
    {
    
    	//-----------------
    	//the next time CpuTimer2 'counter' reaches Period value go to C3
    	C_Task_Ptr = &C3;	
    	//-----------------
    }
    
    
    //-----------------------------------------
    void C3(void) 
    //-----------------------------------------
    {
    
    	//-----------------
    	//the next time CpuTimer2 'counter' reaches Period value go to C4
    	C_Task_Ptr = &C4;	
    	//-----------------
    }
    
    
    //-----------------------------------------
    void C4(void) //  SPARE
    //-----------------------------------------
    {
    
    	//-----------------
    	//the next time CpuTimer2 'counter' reaches Period value go to C1
    	C_Task_Ptr = &C1;	
    	//-----------------
    }
    
    
    
    

    0020.ProjectName-DPL-ISR.asm

    Gautam Iyer said:

    Yes, the way you're updating the duty is erroneous. Can you attach the c file or screenshot?

    Regards,

    Gautam

    Gautam Iyer said:

    Yes, the way you're updating the duty is erroneous. Can you attach the c file or screenshot?

    Regards,

    Gautam

  • Hello Barry!

    I have looked at your C-file. It seems you do something wrong.

    1

    // Connect the PWM Driver input to an input variable, Open Loop System
    PWMDRV_1ch_Duty4 = &Duty4A;

    // Initialize the net variables
    CLA_Duty1 =(float32)(0.5);// Why not 0.4? 
    Duty4A =_IQ24(0.2);//  if you want 0.6 then you should paste Duty4A =_IQ24(0.6);


    2

    //Also Set the appropriate # define's in the {ProjectName}-Settings.h
    //to enable interrupt management in the ISR
    EALLOW;
    PieVectTable.EPWM4_INT = &DPL_ISR; // Map Interrupt
    EPwm4Regs.ETSEL.bit.SOCAEN = 1;// Why do you do that? This was not in the source file ProjectName-Main.c.
    PieCtrlRegs.PIEIER3.bit.INTx4 = 1; // PIE level enable, Grp3 / Int2
    EPwm4Regs.ETSEL.bit.INTSEL = ET_CTR_PRD; // INT on PRD event
    EPwm4Regs.ETSEL.bit.INTEN = 1; // Enable INT
    EPwm4Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on every event

    void C1(void)
    //------------------------------------------------------
    {
    Duty4A =_IQ24(0.6);// You should comment this line

    //-----------------
    //the next time CpuTimer2 'counter' reaches Period value go to C2
    C_Task_Ptr = &C2;
    //-----------------

    }

     4

    Maybe I don't understand what do you wish and I'm wrong.

    Regards,

    Igor

  • HI Igor,

    Sorry that maybe I explain not clear. Let me describe the objective of the program:

    The purpose of this program is to test whether the DPLib routine can execute or not during runtime. To verify this, I add Duty4A =_IQ24(0.2); inside the main() and Duty4A =_IQ24(0.6) inside the C1(). If the DPLib routine can execute, the duty cycle of that ePWM will eventually change to from 0.2 to 0.6.

     

    At the beginning, I used ePWM1 and its interrupt to trigger the DPLib ISR. The duty is eventually changed to 0.6 observed by CRO.

     

    And then, I would like to use ePWM4 and its interrupt to trigger the DPLib ISR. I changed all necessary variables and registers. This time, I found that the duty is 0.2 not 0.6.

    Regarding Q2: EPwm4Regs.ETSEL.bit.SOCAEN = 1;// Why do you do that? This was not in the source file ProjectName-Main.c.

     

    I tried comment and uncomment this code, the result is the same. The problem should not come from this line, please ignore.

     

    Regarding Q2: CLA_Duty1 =(float32)(0.5);// Why not 0.4?, This is the duty of ePWM1 using CLA, the value of this will not affect this test.

     

    BR,

    Barry