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.

LAUNCHXL-F28379D: Update EPWM_setCounterCompareValue in CLA task

Part Number: LAUNCHXL-F28379D
Other Parts Discussed in Thread: C2000WARE

Hi, 

I am trying to update epwm duty cycle inside CLA task on LAUNCHXL-F28379D . I have taken example cla_ex4_pwm_control for my reference, my epwm1 is running at 12.5khz and epwm2 at 8.3khz. While debugging, I am able to trigger breakpoint in CLA task but it doesn't update compareA reg value when this EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A,1000) is called.

This is my CLA task

__interrupt void Cla1Task1 ( void )
{

    __mdebugstop();

    EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A,
                                1000);

    //
    // Clear EPWM2 interrupt flag so that next interrupt can come in
    //
    EPWM_clearEventTriggerInterruptFlag(EPWM2_BASE);
}

Below code is for my CLA and EPWM init functions

//
// CLA_configClaMemory - Configure CLA memory sections
//
void CLA_configClaMemory(void)
{
    extern uint32_t Cla1funcsRunStart, Cla1funcsLoadStart, Cla1funcsLoadSize;
    EALLOW;

#ifdef _FLASH
    //
    // Copy over code from FLASH to RAM
    //
    memcpy((uint32_t *)&Cla1funcsRunStart, (uint32_t *)&Cla1funcsLoadStart,
           (uint32_t)&Cla1funcsLoadSize);
#endif //_FLASH

    //
    // Initialize and wait for CLA1ToCPUMsgRAM
    //
    MemCfg_initSections(MEMCFG_SECT_MSGCLA1TOCPU);
    while (!MemCfg_getInitStatus(MEMCFG_SECT_MSGCLA1TOCPU)){};

    //
    // Initialize and wait for CPUToCLA1MsgRAM
    //
    MemCfg_initSections(MEMCFG_SECT_MSGCPUTOCLA1);
    while (!MemCfg_getInitStatus(MEMCFG_SECT_MSGCPUTOCLA1)){};

    //
    // Select LS4RAM and LS5RAM to be the programming space for the CLA
    // First configure the CLA to be the master for LS4 and LS5 and then
    // set the space to be a program block
    //
    MemCfg_setLSRAMMasterSel(MEMCFG_SECT_LS4,MEMCFG_LSRAMMASTER_CPU_CLA1);
    MemCfg_setCLAMemType(MEMCFG_SECT_LS4,MEMCFG_CLA_MEM_PROGRAM);
    MemCfg_setLSRAMMasterSel(MEMCFG_SECT_LS5,MEMCFG_LSRAMMASTER_CPU_CLA1);
    MemCfg_setCLAMemType(MEMCFG_SECT_LS5,MEMCFG_CLA_MEM_PROGRAM);
    //
    // Next configure LS0RAM and LS1RAM as data spaces for the CLA
    // First configure the CLA to be the master for LS0(1) and then
    // set the spaces to be code blocks
    //
    MemCfg_setLSRAMMasterSel(MEMCFG_SECT_LS0,MEMCFG_LSRAMMASTER_CPU_CLA1);
    MemCfg_setCLAMemType(MEMCFG_SECT_LS0, MEMCFG_CLA_MEM_DATA);

    MemCfg_setLSRAMMasterSel(MEMCFG_SECT_LS1,MEMCFG_LSRAMMASTER_CPU_CLA1);
    MemCfg_setCLAMemType(MEMCFG_SECT_LS1, MEMCFG_CLA_MEM_DATA);

    EDIS;
}

//
// CLA_initCpu1Cla1 - Initialize CLA1 task vectors and end of task interrupts
//
void CLA_initCpu1Cla1(void)
{
    //
    // Compute all CLA task vectors
    // On Type-1 CLAs the MVECT registers accept full 16-bit task addresses as
    // opposed to offsets used on older Type-0 CLAs
    //
    EALLOW;

    // Suppressing #770-D conversion from pointer to smaller integer
    // The CLA address range is 16 bits so the addresses passed to the MVECT
    // registers will be in the lower 64KW address space. Turn the warning
    // back on after the MVECTs are assigned addresses
#pragma diag_suppress=770

    CLA_mapTaskVector(CLA1_BASE,CLA_MVECT_1,(uint16_t)&Cla1Task1);
    CLA_setTriggerSource(CLA_TASK_1, CLA_TRIGGER_EPWM2INT);

#pragma diag_warning=770

    //
    // Enable the IACK instruction to start a task on CLA in software
    // for all  8 CLA tasks. Also, globally enable all 8 tasks (or a
    // subset of tasks) by writing to their respective bits in the
    // MIER register
    //
    CLA_enableIACK(CLA1_BASE);
    CLA_enableTasks(CLA1_BASE,CLA_TASKFLAG_1);


}

void initEPWM1()
{
    //
    // Set-up TBCLK
    //
    EPWM_setTimeBasePeriod(EPWM1_BASE, EPWM1_TIMER_TBPRD);
    EPWM_setPhaseShift(EPWM1_BASE, 0U);
    EPWM_setTimeBaseCounter(EPWM1_BASE, 0U);

    //
    // Set Compare values
    //
    EPWM_setCounterCompareValue(EPWM1_BASE,
                                EPWM_COUNTER_COMPARE_A,
                                EPWM1_MIN_CMPA);
    EPWM_setCounterCompareValue(EPWM1_BASE,
                                EPWM_COUNTER_COMPARE_B,
                                EPWM1_MAX_CMPB);

    //
    // Set up counter mode
    //
    EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_UP_DOWN);
    EPWM_disablePhaseShiftLoad(EPWM1_BASE);
    EPWM_setClockPrescaler(EPWM1_BASE,
                           EPWM_CLOCK_DIVIDER_1,
                           EPWM_HSCLOCK_DIVIDER_1);

    //
    // Set up shadowing
    //
    EPWM_setCounterCompareShadowLoadMode(EPWM1_BASE,
                                         EPWM_COUNTER_COMPARE_A,
                                         EPWM_COMP_LOAD_ON_SYNC_CNTR_ZERO);//EPWM_COMP_LOAD_ON_CNTR_ZERO);
    EPWM_setCounterCompareShadowLoadMode(EPWM1_BASE,
                                         EPWM_COUNTER_COMPARE_B,
                                         EPWM_COMP_LOAD_ON_SYNC_CNTR_ZERO);//EPWM_COMP_LOAD_ON_CNTR_ZERO);

    //
    // Set actions
    //
    EPWM_setActionQualifierAction(EPWM1_BASE,
                                  EPWM_AQ_OUTPUT_A,
                                  EPWM_AQ_OUTPUT_HIGH,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
    EPWM_setActionQualifierAction(EPWM1_BASE,
                                  EPWM_AQ_OUTPUT_A,
                                  EPWM_AQ_OUTPUT_LOW,  //LOW
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
    EPWM_setActionQualifierAction(EPWM1_BASE,
                                  EPWM_AQ_OUTPUT_B,
                                  EPWM_AQ_OUTPUT_HIGH,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);
    EPWM_setActionQualifierAction(EPWM1_BASE,
                                  EPWM_AQ_OUTPUT_B,
                                  EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPB);

    //
    // Set up EPWM2 to
    // - run on a base clock of SYSCLK
    // - have a period of EPWM2_PERIOD
    // - run in count up mode
    EPWM_setClockPrescaler(EPWM2_BASE, EPWM_CLOCK_DIVIDER_1,
                           EPWM_HSCLOCK_DIVIDER_1);
    EPWM_setTimeBasePeriod(EPWM2_BASE, EPWM2_TIMER_TBPRD);
    EPWM_setTimeBaseCounterMode(EPWM2_BASE, EPWM_COUNTER_MODE_UP_DOWN);
    EPWM_setTimeBaseCounter(EPWM2_BASE, 0U);

    //
    // Enabling EPWM2 interrupt at TBCTR = 0 to trigger
    // CLA task
    //
    EPWM_setInterruptSource(EPWM2_BASE, EPWM_INT_TBCTR_ZERO);
    EPWM_enableInterrupt(EPWM2_BASE);
    EPWM_setInterruptEventCount(EPWM2_BASE, 1U);

    //
    // EPWM 1 and 2 should run freely in emulation mode
    //
    EPWM_setEmulationMode(EPWM1_BASE, EPWM_EMULATION_FREE_RUN);
    EPWM_setEmulationMode(EPWM2_BASE, EPWM_EMULATION_FREE_RUN);
}

  • Hi,

    Are you including epwm/driverlib header file in your .cla file? Also have your first tried using the example as-it-is and it works for you? You can also refer to this application report which talks about this example on CLA: 

    If my reply answers your question please click on "This resolved my issue" button located at the bottom of my post.

    Regards

    Himanshu

  • I tried using cla_ex4_pwm_control example as it is but i get error while building. I change target to F29379d and CLA type to CLA1, as the project is for F28004x. I get this error: #20 identifier "CLA_O_SOFTINTFRC" is undefined. 

    Also, I have included epwm.h in my .cla file. But including #include "driverlib.h" gives me same error message mentioned above.

  • Hi,

    Yes by default the example supports F28004x device so you may have to port it to F2837x, please look at rest of the examples provide for CLA on F2837x as reference. My suggestion would be to go through the application report that I have shared in my last response and also you may find find the CLA software guide useful to learn build solutions on CLA:

    If my reply answers your question please click on "This resolved my issue" button located at the bottom of my post.

    Regards

    Himanshu

  • Hi,

    I have already gone through documents and examples regarding F28379d and CLA. I have done most debugging, cant understand why the value of CMPA register not updating in CLA task.

    Regards,

    Mohit

  • Hi,

    Okay it may be difficult to figure out the root cause for this because ideally the CMPA update from CLA should be straightforward, so you may to share the complete software project with us to reproduce the issue on our side. Once you share that, I will have a look and try to get back to you next week.

    If my reply answers your question please click on "This resolved my issue" button located at the bottom of my post.

    Regards

    Himanshu

  • Hi,

    Attaching project file for your refrence.

    Regards

    Mohitepwm.zip

  • Hi,

    Thanks for sharing the files, I will try to analyze and reproduce the issue at my end and will get back to you.

    Regards

    Himanshu

  • Hi,

    I don't see the driver header files included in the shared header of your example, so can you also try including below:

    #include "driverlib.h"
    #include "device.h"

    Also are you using the driverlib files from latest C2000Ware version for this example?

    If my reply answers your question please click on "This resolved my issue" button located at the bottom of my post.

    Regards

    Himanshu

  • Hi,

    If I try to include "driverlib.h" and "device.h" in my shared file, I get this error : #20 identifier "CLA_O_SOFTINTEN" is undefined. Also, I am using latest 2000ware.

  • Hi,

    Actually SOFTINTEN/SOFTINTFRC bits can be written only from CLA so I think since you are including the driverlib header in the common shared file so it is trying the compile these for C28x side too and that's it gives a build error since it is not defined for C28x. Can you try to insert the below directly in .cla file and see if it helps to solve your issue.

    #include "driverlib.h"
    #include "device.h"

    If my reply answers your question please click on "This resolved my issue" button located at the bottom of my post.

    Regards

    Himanshu

  • Hi,

    Earlier these 2 header were included in my main file. When i tried including it directly into .cla file and commented in the main file, it gave more errors.

  • Hi,

    You need to include the headers in both .c and .cla files as they are needed for both C28x and CLA compiler. I would really like to suggest taking a look at the existing examples of CLA on F2837x like cla_ex1_asin and cla_ex2_atan because that would really help to solve these type of build issues on your own. Also if you take one of the existing example of CLA on F2837x as the starting point and then go about just replacing the software with your desired configuration, it would be easier to develop.

    If my reply answers your question please click on "This resolved my issue" button located at the bottom of my post.

    Regards

    Himanshu