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.

Use CLA in F28069 to update the ePWM model

I use the CLA to updata the CMPA Reg in ePWM model. and i seem have some problem to do this.

first i set up the  cla like this to use the EPWM1INT to trigger the task1 of the CLA

Cla1Regs.MVECT1 = (Uint16) (&Cla1Task1 - &Cla1Prog_Start)*sizeof(Uint32);
Cla1Regs.MPISRCSEL1.bit.PERINT1SEL = CLA_INT1_EPWM1INT;
Cla1Regs.MMEMCFG.bit.PROGE = 1;
Cla1Regs.MMEMCFG.bit.RAM1E = 1;
Cla1Regs.MMEMCFG.all = CLA_PROG_ENABLE|CLARAM0_ENABLE|CLARAM1_ENABLE|CLARAM2_ENABLE|CLA_RAM1CPUE;
Cla1Regs.MCTL.bit.IACKE = 1;
Cla1Regs.MIER.all = (M_INT8 | M_INT7 | M_INT1);// Enable Task 7 and Task 1

and then I set up the ePWM model for INT signal like below

EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;     // Select INT on Zero event
EPwm1Regs.ETSEL.bit.INTEN = PWM1_INT_ENABLE;  // Enable INT
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;           // Generate INT on 1st event
EPwm1Regs.ETCLR.bit.INT    = 1;

and i`ve also setup the EPWMCFG.bit.CONFIG Reg.

in the CLA task1 i use the code in asm like this

_Cla1Task1:
	MNOP
	MNOP
    MDEBUGSTOP
;Clear EPWM Flag if PWM1 triggers the CLA task
	MMOVXI		MR0,#0x01
	MMOV16      @_EPwm1Regs.ETCLR, MR0
	MMOV32      @_EPwm1Regs.CMPA, MR0
    MNOP
    MNOP
    MSTOP
    MNOP
    MNOP
    MNOP
_Cla1T1End:

when I debug my program i cannot get to the debugstop in task1.but i can get to the debugstop of other task. and the value of EPwm1Regs.CMPA don`t change  at all.

please help me with any kind of language. i can find to little material in Chinese. so i come here. 

Thanks a lot.

  • Hi Chang,

    It sounds very much like task 1 is not being triggered. If you were to enable the EPWM1INT in the PIE and setup an EPWM1_ISR, does it go to the ISR?

  • I`ve test that. if i set the code "IER |= M_INT3;" then the EPW1INT will be send to the PIE. and i will run into the EPWdefaultISR. but that`s not what i want.
    by the way,
    if i want to realize the function of "i%600", but how can i realize it in assemble code more quickly? i is a Uint 16 value.
    now i am trying to change it to float and calculate and change back to Uint.
    Thanks a lot!
  • I'm looking into writing an assembly routine for unsigned modulus, Ill post the code once (or if) i get it working.

    As for the task not hitting the MDEBUGSTOP, im not quite sure why that happens. We can check a couple of things.

    After you setup task 1, enable the IACKE bit in MCTL and then force task 1 (using Cla1ForceTask1AndWait()) and see if its hitting the MDEBUGSTOP - also check the value of MPC and make sure that it pulls the correct offset for task 1. If you do hit the debugstop, then the CLA setup is correct and the problem lies with the EPWM interrupt generation.
  • ;;#############################################################################
    ;; \file cla_unsigned_modulus.asm
    ;;
    ;; \brief  Unsigned Modulus
    ;; \date   Jan 22, 2015
    ;; 
    ;;
    ;; Group: 			C2000
    ;; Target Family:	F2837x
    ;;
    ;;(C)Copyright 2015, Texas Instruments, Inc.
    ;;#############################################################################
    ;;$TI Release: F2837xD Support Library v110 $
    ;;$Release Date: Mon Apr  7 10:35:37 CDT 2014 $
    ;;#############################################################################
    
    ;;*****************************************************************************
    ;; includes
    ;;*****************************************************************************
    
    ;;*****************************************************************************
    ;; defines
    ;;*****************************************************************************
    ;// To include an MDEBUGSTOP (CLA breakpoint) as the first instruction
    ;// of each task, set CLA_DEBUG to 1.  Use any other value to leave out
    ;// the MDEBUGSTOP instruction.
    
    CLA_DEBUG          .set  1
    
    ;;*****************************************************************************
    ;; function definitions
    ;;*****************************************************************************
    ;// CLA code must be within its own assembly section and must be
    ;// even aligned.  Note: since all CLA instructions are 32-bit
    ;// this alignment naturally occurs and the .align 2 is most likely
    ;// redundant
    
    	.global		_cla_unsigned16_mod
    	.sect	"Cla1Prog:_cla_unsigned16_mod"
    	.align	 2
    __cla_unsigned_mod_sp	.usect	".scratchpad:Cla1Prog:_cla_unsigned16_mod",2,0,1
    ;***************************************************************
    ;* FNAME: _cla_unsigned_mod             FR SIZE:   2           *
    ;*                                                             *
    ;* FUNCTION ENVIRONMENT                                        *
    ;*                                                             *
    ;* FUNCTION PROPERTIES                                         *
    ;*                                          2 Auto,  1 SOE     *
    ;***************************************************************
    _cla_unsigned16_mod:
    	.if			CLA_DEBUG == 1
    	MDEBUGSTOP
    	MNOP
    	MNOP
    	MNOP
    	.endif
    	MMOV32		@__cla_unsigned_mod_sp + 0, MR3
    	MMOVIZ		MR3, #0
    	MMOVXI		MR3, #1							; MR3 = 1
    	MLSL32		MR1, #16						; den = den << 16
    	; the accumulator has the numerator on the first iteration
    	.asg		0, N
    	.loop
    	MLSL32		MR0, #1							; acc <<= 1
    	MSUB32		MR2, MR0, MR1					; temp = (acc << 1) - (den << 16) (set flag)
    	MADD32		MR2, MR2, MR3					; temp += 1 (could change flag)
    	MMOV32		MR0, MR2, GT					; if(temp >0) acc = temp+1
    	                                            ; else        acc <<= 1
    	.eval		N + 1, N
    	.break		N == 16
    	.endloop
    	.unasg		N
    	MRCNDD		UNCF
    	MMOV32		MR3, @__cla_unsigned_mod_sp + 0
    	MNOP
    	MNOP
    
    ;; End of file
    

    This works just like the SUBCU instruction of the C28x, the input is signed 16-bit, but the algorithm will work as if its unsisgned- the output will have both quotient and remainder: you call the functions as follows:

    	uint32_t temp = cla_unsigned16_mod(num, den);
    	rem = (temp >> 16) & 0xFFFF;
    	quo = temp & 0xFFFF;

    Here is the code to do the 16-bit modulus

  • Thanks very much.  There must be somthing wrong with my email,  so I did know whether someone has answer my quetions.

    Fortunately,  I have found the answer. The code below should be add to the initialization of  the CLA module.

    EALLOW;
    SysCtrlRegs.EPWMCFG.bit.CONFIG = 1; //ePWM DMA/CLA Configuration Register
    EDIS;
    

    It will allow the CLA has the access to the EPWM Regs.

    This is a very important Reg which seems never be metioned in the TMS320x2806x Piccolo Technical Reference Guide. Hope it will be add to the guide.

  • Chang Liu1 said:
    This is a very important Reg which seems never be metioned in the TMS320x2806x Piccolo Technical Reference Guide. Hope it will be add to the guide

    Looks like the register is listed in some of the tables, but its bit field description is missing. Thanks for pointing this out- I have notified our docs publishing team to add this to the next revision of the TRM. 

    Also, FYI if you find any discrepancies in any documentation you can always submit feedback directly to the documentation team by clicking on the blue link right at the start of the document.

  • How could setting CONFIG bit to 1 solve the ePWM issue? According to the F2806x TRG shown below, the bit should be 0 for CLA to control ePWM, shouldn't it? Besides, this register is not EALLOW protected.

    I'm not picking on your posting, in fact, I'd like to find useful information to solve my issue that ePWM compare registers do not change values when CLA writes different values to them. What was the actual cause and solution?

  • Sorry for late reply. I remember I set it to 1 for access to CLA bus, then every thing goes well. But I have no idea about the description in the new reference guide. It seems that it should be 0. Maybe I should do some experiment some time later to verify this register.