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 properly call HAL_setupeCAP(HAL_Handle handle) ?

Other Parts Discussed in Thread: MOTORWARE, CONTROLSUITE

Hi,

I followed one recent post about eCAP here in INSTASPIN forum ("Help with eCAP INT?") and set up all files according with that post.

However for below function in hal.c I am not sure I call it properly in main():

void HAL_setupeCAP(HAL_Handle handle)
{
     HAL_Obj *obj = (HAL_Obj *)handle;
     CAP_setModeCap(obj->capHandle); // set mode to CAP
     CAP_clearInt(obj->capHandle,CAP_Int_Type_CEVT1); // clear the CEVT1 int
     CAP_disableSyncIn(obj->capHandle);
     CAP_setCapEvtPolarity(obj->capHandle,CAP_Event_1,CAP_Polarity_Rising);
     CAP_setCapEvtPolarity(obj->capHandle,CAP_Event_2,CAP_Polarity_Falling);
     CAP_setCapEvtPolarity(obj->capHandle,CAP_Event_3,CAP_Polarity_Rising);
     CAP_setCapEvtPolarity(obj->capHandle,CAP_Event_4,CAP_Polarity_Falling);
     CAP_setCapEvtReset(obj->capHandle,CAP_Event_1,CAP_Reset_Enable);
     CAP_setCapEvtReset(obj->capHandle,CAP_Event_2,CAP_Reset_Enable);
     CAP_setCapEvtReset(obj->capHandle,CAP_Event_3,CAP_Reset_Enable);
     CAP_setCapEvtReset(obj->capHandle,CAP_Event_4,CAP_Reset_Enable);
     CAP_setCapContinuous(obj->capHandle);
     //CAP_setRunMode(obj->capHandle);
     CAP_setStopWrap(obj->capHandle,CAP_Stop_Wrap_CEVT4);
     CAP_enableCaptureLoad(obj->capHandle);
     //CAP_enableInt(obj->capHandle,CAP_Int_Type_CEVT1);
     CAP_enableInt(obj->capHandle,CAP_Int_Type_CEVT4);
     CAP_enableTimestampCounter(obj->capHandle);
        // enable eCAP interrupt
          PIE_enableInt(obj->pieHandle, PIE_GroupNumber_4, PIE_InterruptSource_ECAP1);
          CPU_enableInt(obj->cpuHandle, CPU_IntNumber_4);
     return;
} // end of HAL_setupCAP() function

I used lab01a and latest motorware.

In main()  I call the function with   HAL_setupeCAP(halHandle);

Compilation is OK but in debug mode, in REGISTER window, under eCAP1, all registers (especially control registers) have value 0.

How to inform compiler that in HAL_setupeCAP(HAL_Handle handle),  eCAP1 is the one I need registers to be set? ( In controlSuite is for example something like

 ECap1Regs.ECCTL2.bit.CONT_ONESHT = 1;      // One-shot)

Regards,

Sergiu

  • did you enable the eCAP clock in hal?
    CLK_disableEcap1Clock(obj->clkHandle);
  • Hi Chris,

    Thank you for your help.

    All I did so far:

    in proj_lab01.c:

    in main() I added
    HAL_setupeCAP(halHandle);

    also the isr:
    interrupt void ecapISR(void)
    {
    CAP_rearm(halHandle->capHandle);
    CAP_clearInt(halHandle->capHandle, CAP_Int_Type_CEVT4);
    PIE_clearInt(halHandle->pieHandle, PIE_GroupNumber_4);
    }


    in hal.c:

    void HAL_setupeCAP(HAL_Handle handle)
    {
    HAL_Obj *obj = (HAL_Obj *)handle;
    CAP_setModeCap(obj->capHandle); // set mode to CAP
    CAP_clearInt(obj->capHandle,CAP_Int_Type_CEVT1); // clear the CEVT1 int
    CAP_disableSyncIn(obj->capHandle);
    CAP_setCapEvtPolarity(obj->capHandle,CAP_Event_1,CAP_Polarity_Rising);
    CAP_setCapEvtPolarity(obj->capHandle,CAP_Event_2,CAP_Polarity_Falling);
    CAP_setCapEvtPolarity(obj->capHandle,CAP_Event_3,CAP_Polarity_Rising);
    CAP_setCapEvtPolarity(obj->capHandle,CAP_Event_4,CAP_Polarity_Falling);
    CAP_setCapEvtReset(obj->capHandle,CAP_Event_1,CAP_Reset_Enable);
    CAP_setCapEvtReset(obj->capHandle,CAP_Event_2,CAP_Reset_Enable);
    CAP_setCapEvtReset(obj->capHandle,CAP_Event_3,CAP_Reset_Enable);
    CAP_setCapEvtReset(obj->capHandle,CAP_Event_4,CAP_Reset_Enable);
    CAP_setCapContinuous(obj->capHandle);
    //CAP_setRunMode(obj->capHandle);
    CAP_setStopWrap(obj->capHandle,CAP_Stop_Wrap_CEVT4);
    CAP_enableCaptureLoad(obj->capHandle);
    //CAP_enableInt(obj->capHandle,CAP_Int_Type_CEVT1);
    CAP_enableInt(obj->capHandle,CAP_Int_Type_CEVT4);
    CAP_enableTimestampCounter(obj->capHandle);
    // enable eCAP interrupt
    PIE_enableInt(obj->pieHandle, PIE_GroupNumber_4, PIE_InterruptSource_ECAP1);
    CPU_enableInt(obj->cpuHandle, CPU_IntNumber_4);
    CLK_enableEcap1Clock(obj->clkHandle);

    return;
    } // end of HAL_setupCAP() function

    in HAL_Handle HAL_init(void *pMemory,const size_t numBytes)
    // added
    // init eCAP
    obj->capHandle = CAP_init((void *)CAP1_BASE_ADDR,sizeof(CAP_Obj));

    in void HAL_setupGpios(HAL_Handle handle)
    //modified
    GPIO_setMode(obj->gpioHandle,GPIO_Number_19,GPIO_19_Mode_ECAP1);


    in HAL_obj.h:
    //added
    #include "sw/drivers/cap/src/32b/f28x/f2806x/cap.h"
    in
    typedef struct _HAL_Obj_
    {
    //added
    CAP_Handle capHandle;
    .........
    ADC_Handle adcHandle; //!< the ADC handle
    .........


    in HAL.h:
    #include "sw/drivers/cap/src/32b/f28x/f2806x/cap.h"

    // the globals

    extern interrupt void mainISR(void);

    //added
    extern interrupt void ecapISR(void);

    in static inline void HAL_initIntVectorTable(HAL_Handle handle)

    //added
    pie->ECAP1_INT = &ecapISR;

    also at line 1300
    void HAL_setupeCAP(HAL_Handle handle);

    Did I miss something?
  • Hi Sergiu,

    When you step though your HAL_setupeCAP() function, can you see anything change in the registers window? If nothing seems to be changing, go into the HAL_setupPeripheralClks() and make sure that CLK_enableEcap1Clock() is being called somewhere. This is most likely the cause.

    At the moment, I don't see any issues with the code you've posted, but we can take a closer look once you've confirmed whether or not you're enabling the eCAP1 clock using CLK_enableEcap1Clock().

    Thanks,
    Whitney
  • Hi Whitney,

    I did as you suggested and moved CLK_enableEcap1Clock() in hal.c to line 1370.

    Now eCAP1 is working properly !

    Thank you and Chris for help.

    Regards,

    Sergiu