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.

CCS/TMS320F28027: Accessing ECFLG register from ECAP module.

Part Number: TMS320F28027
Other Parts Discussed in Thread: MOTORWARE

Tool/software: Code Composer Studio

Hi Team,

I am using Motorware .

I got to work my program of getting frequency on GPIO19 using CAP module.

Now the problem is I try to get Register value in to defined global variable.

Basically i am looking for the bit0 of the flag which is interrupt status bit.

But it is not reflecting in it.

I have tried with below methods:

1) attached cap.h file

cap.h

CAP_Handle myCap;

uint16_t TstStructAccess = myCap->ECEFLG;
uint16_t Tst5 = (myCap->ECEFLG) & 0xFFFF;

2) 

uint16_t one_pulse_time = CAP_getECEFLAG(myCap);

  • Jesal,

    locally we tested this struct and the lines of code shown below.

    CAP_Handle myCap;
    
    uint16_t TstStructAccess = myCap->ECEFLG;
    uint16_t Tst5 = (myCap->ECEFLG) & 0xFFFF;

    They seem to work just fine. How are you linking this? How are you assigning this struct to a pointer?

    Something is going wrong in your code, I expect this will take an amount of debug on your end. Try to figure out where things start to go wrong, and we can go from there.

    Regards,
    Cody 

     

  • Hi,

    I have attached cap.c and cap.h files .

    Please correct me if there is any problem with both the files.

    cap.h:

    // **************************************************************************
    // the includes
    
    // drivers
    #include "sw/modules/types/src/types.h"
    
    // modules
    
    //!
    //!
    //! \defgroup CAP CAP
    //!
    //@{
    
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    
    // **************************************************************************
    // the defines
    
    //! \brief Defines the base address of the capture (CAP) 1 registers
    //!
    #define CAP1_BASE_ADDR              (0x00006A00)
    
    //! \brief Defines the location of the FREE/SOFT bits in the ECCTL1 register
    //!
    #define CAP_ECCTL1_FREESOFT_BITS   (3 << 14)
    
    //! \brief Defines the location of the PRESCALE bits in the ECCTL1 register
    //!
    #define CAP_ECCTL1_PRESCALE_BITS   (31 << 9)
    
    //! \brief Defines the location of the CAPLDEN bits in the ECCTL1 register
    //!
    #define CAP_ECCTL1_CAPLDEN_BITS   (1 << 8)
    
    //! \brief Defines the location of the CTRRST4 bits in the ECCTL1 register
    //!
    #define CAP_ECCTL1_CTRRST4_BITS   (1 << 7)
    
    //! \brief Defines the location of the CAP4POL bits in the ECCTL1 register
    //!
    #define CAP_ECCTL1_CAP4POL_BITS   (1 << 6)
    
    //! \brief Defines the location of the CTRRST3 bits in the ECCTL1 register
    //!
    #define CAP_ECCTL1_CTRRST3_BITS   (1 << 5)
    
    //! \brief Defines the location of the CAP3POL bits in the ECCTL1 register
    //!
    #define CAP_ECCTL1_CAP3POL_BITS   (1 << 4)
    
    //! \brief Defines the location of the CTRRST2 bits in the ECCTL1 register
    //!
    #define CAP_ECCTL1_CTRRST2_BITS   (1 << 3)
    
    //! \brief Defines the location of the CAP2POL bits in the ECCTL1 register
    //!
    #define CAP_ECCTL1_CAP2POL_BITS   (1 << 2)
    
    //! \brief Defines the location of the CTRRST1 bits in the ECCTL1 register
    //!
    #define CAP_ECCTL1_CTRRST1_BITS   (1 << 1)
    
    //! \brief Defines the location of the CAP1POL bits in the ECCTL1 register
    //!
    #define CAP_ECCTL1_CAP1POL_BITS   (1 << 0)
    
    //! \brief Defines the location of the APWMPOL bits in the ECCTL2 register
    //!
    #define CAP_ECCTL2_APWMPOL_BITS   (1 << 10)
    
    //! \brief Defines the location of the CAP/APWM bits in the ECCTL2 register
    //!
    #define CAP_ECCTL2_CAPAPWM_BITS   (1 << 9)
    
    //! \brief Defines the location of the SWSYNC bits in the ECCTL2 register
    //!
    #define CAP_ECCTL2_SWSYNC_BITS    (1 << 8)
    
    //! \brief Defines the location of the SYNCO_SEL bits in the ECCTL2 register
    //!
    #define CAP_ECCTL2_SYNCOSEL_BITS  (3 << 6)
    
    //! \brief Defines the location of the SYNCI_EN bits in the ECCTL2 register
    //!
    #define CAP_ECCTL2_SYNCIEN_BITS   (1 << 5)
    
    //! \brief Defines the location of the TSCTRSTOP bits in the ECCTL2 register
    //!
    #define CAP_ECCTL2_TSCTRSTOP_BITS (1 << 4)
    
    //! \brief Defines the location of the REARM bits in the ECCTL2 register
    //!
    #define CAP_ECCTL2_REARM_BITS     (1 << 3)
    
    //! \brief Defines the location of the STOP_WRAP bits in the ECCTL2 register
    //!
    #define CAP_ECCTL2_STOP_WRAP_BITS (3 << 1)
    
    //! \brief Defines the location of the CONT/ONESHOT bits in the ECCTL2 register
    //!
    #define CAP_ECCTL2_CONTONESHOT_BITS (1 << 0)
    
    //! \brief Defines the location of the CTR=COMP bits in the ECCxxx register
    //!
    #define CAP_ECCxxx_CTRCOMP_BITS  (1 << 7)
    
    //! \brief Defines the location of the CTR=PRD bits in the ECCxxx register
    //!
    #define CAP_ECCxxx_CTRPRD_BITS   (1 << 6)
    
    //! \brief Defines the location of the CTROVF bits in the ECCxxx register
    //!
    #define CAP_ECCxxx_CTROVF_BITS   (1 << 5)
    
    //! \brief Defines the location of the CEVT4 bits in the ECCxxx register
    //!
    #define CAP_ECCxxx_CEVT4_BITS    (1 << 4)
    
    //! \brief Defines the location of the CEVT4 bits in the ECCxxx register
    //!
    #define CAP_ECCxxx_CEVT3_BITS    (1 << 3)
    
    //! \brief Defines the location of the CEVT4 bits in the ECCxxx register
    //!
    #define CAP_ECCxxx_CEVT2_BITS    (1 << 2)
    
    //! \brief Defines the location of the CEVT4 bits in the ECCxxx register
    //!
    #define CAP_ECCxxx_CEVT1_BITS    (1 << 1)
    
    //! \brief Defines the location of the INT bits in the ECCxxx register
    //!
    #define CAP_ECCxxx_INT_BITS      (1 << 0)
    
    //! \brief Defines the location of the INT bits in the ECFLG register
    //!
    #define CAP_ECEFLG_INT_BITS      (1 << 0)
    // **************************************************************************
    // the typedefs
    
    //! \brief Enumeration to define the capture (CAP) interrupts
    //!
    typedef enum
    {
        CAP_Int_Type_CTR_CMP = (1 << 7),     //!< Denotes CTR = CMP interrupt
        CAP_Int_Type_CTR_PRD = (1 << 6),     //!< Denotes CTR = PRD interrupt
        CAP_Int_Type_CTR_OVF = (1 << 5),     //!< Denotes CTROVF interrupt
        CAP_Int_Type_CEVT4 = (1 << 4),       //!< Denotes CEVT4 interrupt
        CAP_Int_Type_CEVT3 = (1 << 3),       //!< Denotes CEVT3 interrupt
        CAP_Int_Type_CEVT2 = (1 << 2),       //!< Denotes CEVT2 interrupt
        CAP_Int_Type_CEVT1 = (1 << 1),       //!< Denotes CEVT1 interrupt
        CAP_Int_Type_Global = (1 << 0),      //!< Denotes Capture global interrupt
        CAP_Int_Type_All = 0x00FF            //!< Denotes All interrupts
    } CAP_Int_Type_e;
    
    //! \brief Enumeration to define the capture (CAP) prescaler values
    //!
    typedef enum
    {
        CAP_Prescale_By_1 = (0 << 9),    //!< Divide by 1
        CAP_Prescale_By_2 = (1 << 9),    //!< Divide by 2
        CAP_Prescale_By_4 = (2 << 9),    //!< Divide by 4
        CAP_Prescale_By_6 = (3 << 9),    //!< Divide by 6
        CAP_Prescale_By_8 = (4 << 9),    //!< Divide by 8
        CAP_Prescale_By_10 = (5 << 9),   //!< Divide by 10
        CAP_Prescale_By_12 = (6 << 9),   //!< Divide by 12
        CAP_Prescale_By_14 = (7 << 9),   //!< Divide by 14
        CAP_Prescale_By_16 = (8 << 9),   //!< Divide by 16
        CAP_Prescale_By_18 = (9 << 9),   //!< Divide by 18
        CAP_Prescale_By_20 = (10 << 9),  //!< Divide by 20
        CAP_Prescale_By_22 = (11 << 9),  //!< Divide by 22
        CAP_Prescale_By_24 = (12 << 9),  //!< Divide by 24
        CAP_Prescale_By_26 = (13 << 9),  //!< Divide by 26
        CAP_Prescale_By_28 = (14 << 9),  //!< Divide by 28
        CAP_Prescale_By_30 = (15 << 9),  //!< Divide by 30
        CAP_Prescale_By_32 = (16 << 9),  //!< Divide by 32
        CAP_Prescale_By_34 = (17 << 9),  //!< Divide by 34
        CAP_Prescale_By_36 = (18 << 9),  //!< Divide by 36
        CAP_Prescale_By_38 = (19 << 9),  //!< Divide by 38
        CAP_Prescale_By_40 = (20 << 9),  //!< Divide by 40
        CAP_Prescale_By_42 = (21 << 9),  //!< Divide by 42
        CAP_Prescale_By_44 = (22 << 9),  //!< Divide by 44
        CAP_Prescale_By_46 = (23 << 9),  //!< Divide by 46
        CAP_Prescale_By_48 = (24 << 9),  //!< Divide by 48
        CAP_Prescale_By_50 = (25 << 9),  //!< Divide by 50
        CAP_Prescale_By_52 = (26 << 9),  //!< Divide by 52
        CAP_Prescale_By_54 = (27 << 9),  //!< Divide by 54
        CAP_Prescale_By_56 = (28 << 9),  //!< Divide by 56
        CAP_Prescale_By_58 = (29 << 9),  //!< Divide by 58
        CAP_Prescale_By_60 = (30 << 9),  //!< Divide by 60
        CAP_Prescale_By_62 = (31 << 9)   //!< Divide by 62
    } CAP_Prescale_e;
    
    //! \brief Enumeration to define the pulse width modulation (PWM) run modes
    //!
    typedef enum
    {
        CAP_RunMode_HardStop = (0 << 14),
        CAP_RunMode_SoftStopAfterCycle = (1 << 14),
        CAP_RunMode_FreeRun = (2 << 14)
    } CAP_RunMode_e;
    
    //! \brief Enumeration to define the capture (CAP) Stop/Wrap modes
    //!
    typedef enum
    {
        CAP_Stop_Wrap_CEVT1 = (0 << 1),     //!< Stop/Wrap after Capture Event 1
        CAP_Stop_Wrap_CEVT2 = (1 << 1),     //!< Stop/Wrap after Capture Event 2
        CAP_Stop_Wrap_CEVT3 = (2 << 1),     //!< Stop/Wrap after Capture Event 3
        CAP_Stop_Wrap_CEVT4 = (3 << 1)      //!< Stop/Wrap after Capture Event 4
    } CAP_Stop_Wrap_e;
    
    //! \brief Enumeration to define the capture (CAP) events
    //!
    typedef enum
    {
        CAP_Event_1 = 0,     //!< Capture Event 1
        CAP_Event_2,         //!< Capture Event 2
        CAP_Event_3,         //!< Capture Event 3
        CAP_Event_4          //!< Capture Event 4
    } CAP_Event_e;
    
    //! \brief Enumeration to define the capture (CAP) event polarities
    //!
    typedef enum
    {
        CAP_Polarity_Rising = 0,     //!< Rising Edge Triggered
        CAP_Polarity_Falling         //!< Falling Edge Triggered
    } CAP_Polarity_e;
    
    //! \brief Enumeration to define the capture (CAP) event resets
    //!
    typedef enum
    {
        CAP_Reset_Disable = 0,     //!< Disable counter reset on capture event
        CAP_Reset_Enable           //!< Enable counter reset on capture event
    } CAP_Reset_e;
    
    //! \brief Enumeration to define the Sync Out options
    //!
    typedef enum
    {
        CAP_SyncOut_SyncIn = (0 << 6),     //!< Sync In used for Sync Out
        CAP_SyncOut_CTRPRD = (1 << 6),     //!< CTR = PRD used for Sync Out
        CAP_SyncOut_Disable = (2 << 6)    //!< Disables Sync Out
    } CAP_SyncOut_e;
    
    
    //! \brief Defines the capture (CAP) object
    //!
    typedef struct _CAP_Obj_
    {
        volatile uint32_t TSCTR;        //!< Time-stamp Counter
        volatile uint32_t CTRPHS;       //!< Counter Phase Offset Value Register
        volatile uint32_t CAP1;         //!< Capture 1 Register
        volatile uint32_t CAP2;         //!< Capture 2 Register
        volatile uint32_t CAP3;         //!< Capture 3 Register
        volatile uint32_t CAP4;         //!< Capture 4 Register
        volatile uint16_t Rsvd_1[8];    //!< Reserved
        volatile uint16_t ECCTL1;       //!< Capture Control Register 1
        volatile uint16_t ECCTL2;       //!< Capture Control Register 2
        volatile uint16_t ECEINT;       //!< Capture Interrupt Enable Register
        volatile uint16_t ECEFLG;       //!< Capture Interrupt Flag Register
        volatile uint16_t ECECLR;       //!< Capture Interrupt Clear Register
        volatile uint16_t ECEFRC;       //!< Capture Interrupt Force Register
    
    } CAP_Obj;
    
    //! \brief Defines the capture (CAP) handle
    //!
    typedef struct _CAP_Obj_ *CAP_Handle;
    
    // **************************************************************************
    // the globals
    
    // **************************************************************************
    // the function prototypes
    
    //! \brief     Sets capture peripheral up for capture mode
    //! \param[in] capHandle  The capture (CAP) object handle
    extern void CAP_setModeCap(CAP_Handle capHandle);
    
    //! \brief     Sets capture peripheral up for APWM mode
    //! \param[in] capHandle  The capture (CAP) object handle
    extern void CAP_setModeApwm(CAP_Handle capHandle);
    
    //! \brief     Clears capture (CAP) interrupt flag
    //! \param[in] capHandle  The capture (CAP) object handle
    //! \param[in] intType  The capture interrupt to be cleared
    static inline void CAP_clearInt(CAP_Handle capHandle,
                                    const CAP_Int_Type_e intType)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        cap->ECECLR |= intType;
    
        return;
    }
    
    //! \brief     Disables loading of CAP1-4 on capture event
    //! \param[in] capHandle  The capture (CAP) object handle
    extern void CAP_disableCaptureLoad(CAP_Handle capHandle);
    
    //! \brief     Disables capture (CAP) interrupt source
    //! \param[in] capHandle  The capture (CAP) object handle
    //! \param[in] intType  The capture interrupt type to be disabled
    extern void CAP_disableInt(CAP_Handle capHandle, const CAP_Int_Type_e intType);
    
    //! \brief     Disables counter synchronization
    //! \param[in] capHandle  The capture (CAP) object handle
    extern void CAP_disableSyncIn(CAP_Handle capHandle);
    
    //! \brief     Disables Time Stamp counter from running
    //! \param[in] capHandle  The capture (CAP) object handle
    extern void CAP_disableTimestampCounter(CAP_Handle capHandle);
    
    //! \brief     Enables loading of CAP1-4 on capture event
    //! \param[in] capHandle  The capture (CAP) object handle
    extern void CAP_enableCaptureLoad(CAP_Handle capHandle);
    
    //! \brief     Enables capture (CAP) interrupt source
    //! \param[in] capHandle  The capture (CAP) object handle
    //! \param[in] intType  The capture interrupt type to be enabled
    extern void CAP_enableInt(CAP_Handle capHandle, const CAP_Int_Type_e intType);
    
    //! \brief     Enables counter synchronization
    //! \param[in] capHandle  The capture (CAP) object handle
    extern void CAP_enableSyncIn(CAP_Handle capHandle);
    
    //! \brief     Enables Time Stamp counter to running
    //! \param[in] capHandle  The capture (CAP) object handle
    extern void CAP_enableTimestampCounter(CAP_Handle capHandle);
    
    //! \brief     Gets the CAP1 register value
    //! \param[in] capHandle  The capture (CAP) object handle
    static inline uint32_t CAP_getCap1(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        return (cap->CAP1);
    } // end of CAP_getCap1() function
    
    //! \brief     Gets the CAP2 register value
    //! \param[in] capHandle  The capture (CAP) object handle
    static inline uint32_t CAP_getCap2(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        return (cap->CAP2);
    } // end of CAP_getCap2() function
    
    //! \brief     Gets the CAP3 register value
    //! \param[in] capHandle  The capture (CAP) object handle
    static inline uint32_t CAP_getCap3(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        return (cap->CAP3);
    } // end of CAP_getCap3() function
    
    //! \brief     Gets the CAP4 register value
    //! \param[in] capHandle  The capture (CAP) object handle
    static inline uint32_t CAP_getCap4(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        return (cap->CAP4);
    } // end of CAP_getCap4() function
    
    static inline uint16_t CAP_getECEFLAG(CAP_Handle capHandle)
    {
        uint16_t ECEFLG_INT;
        CAP_Obj *cap = (CAP_Obj *) capHandle;
        ECEFLG_INT = cap->ECEFLG;
        return ECEFLG_INT;
    } // end of CAP_getECEFLAG() function
    
    
    //! \brief     (Re-)Arm the capture module
    //! \param[in] capHandle  The capture (CAP) object handle
    static inline void CAP_rearm(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        cap->ECCTL2 |= CAP_ECCTL2_REARM_BITS;
    
        return;
    } // end of CAP_rearm() function
    
    //! \brief     Sets the capture event polarity
    //! \param[in] capHandle  The capture (CAP) object handle
    //! \param[in] event  The event to configure
    //! \param[in] polarity  The polarity to configure the event for
    extern void CAP_setCapEvtPolarity(CAP_Handle capHandle, const CAP_Event_e event,
                                      const CAP_Polarity_e polarity);
    
    //! \brief     Sets the capture event counter reset configuration
    //! \param[in] capHandle  The capture (CAP) object handle
    //! \param[in] event  The event to configure
    //! \param[in] reset  Whether the event should reset the counter or not
    extern void CAP_setCapEvtReset(CAP_Handle capHandle, const CAP_Event_e event,
                                   const CAP_Reset_e reset);
    
    //! \brief     Sets up for continuous Capture
    //! \param[in] capHandle  The capture (CAP) object handle
    extern void CAP_setCapContinuous(CAP_Handle capHandle);
    
    //! \brief     Sets up for one-shot Capture
    //! \param[in] capHandle  The capture (CAP) object handle
    extern void CAP_setCapOneShot(CAP_Handle capHandle);
    
    //! \brief     Sets the APWM period
    //! \param[in] capHandle  The capture (CAP) object handle
    //! \param[in] period  The APWM period
    static inline void CAP_setApwmPeriod(CAP_Handle capHandle,
                                         const uint32_t period)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        cap->CAP1 = period;
    
        return;
    } // end of CAP_setApwmPeriod() function
    
    //! \brief     Sets the APWM compare value
    //! \param[in] capHandle  The capture (CAP) object handle
    //! \param[in] compare  The APWM compare value
    static inline void CAP_setApwmCompare(CAP_Handle capHandle,
                                          const uint32_t compare)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        cap->CAP2 = compare;
    
        return;
    } // end of CAP_setApwmCompare() function
    
    //! \brief     Sets the APWM shadow period
    //! \param[in] capHandle  The capture (CAP) object handle
    //! \param[in] shadowPeriod  The APWM shadow period
    static inline void CAP_setApwmShadowPeriod(CAP_Handle capHandle,
                                               const uint32_t shadowPeriod)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        cap->CAP3 = shadowPeriod;
    
        return;
    } // end of CAP_setApwmShadowPeriod() function
    
    //! \brief     Set the stop/wrap mode
    //! \param[in] capHandle  The capture (CAP) object handle
    //! \param[in] stopWrap  The stop/wrap mode to set
    extern void CAP_setStopWrap(CAP_Handle capHandle,
                                const CAP_Stop_Wrap_e stopWrap);
    
    //! \brief     Set the sync out mode
    //! \param[in] capHandle  The capture (CAP) object handle
    //! \param[in] syncOut  The sync out mode to set
    extern void CAP_setSyncOut(CAP_Handle capHandle, const CAP_SyncOut_e syncOut);
    
    //! \brief     Initializes the capture (CAP) object handle
    //! \param[in] pMemory     A pointer to the base address of the CAP registers
    //! \param[in] numBytes    The number of bytes allocated for the CAP object, bytes
    //! \return    The capture (CAP) object handle
    extern CAP_Handle CAP_init(void *pMemory, const size_t numBytes);
    
    #ifdef __cplusplus
    }
    #endif // extern "C"
    
    //@} // ingroup
    #endif // end of _CAP_H_ definition
    
    

    cap.c:

    // **************************************************************************
    // the includes
    #include "sw/drivers/cap/src/32b/f28x/f2802x/cap.h"
    
    // **************************************************************************
    // the defines
    
    // **************************************************************************
    // the globals
    
    // **************************************************************************
    // the functions
    
    CAP_Handle CAP_init(void *pMemory, const size_t numBytes)
    {
        CAP_Handle capHandle;
    
        if (numBytes < sizeof(CAP_Obj))
            return ((CAP_Handle) NULL);
    
        // assign the handle
        capHandle = (CAP_Handle) pMemory;
    
        return (capHandle);
    } // end of CAP_init() function
    
    void CAP_disableCaptureLoad(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECCTL1 &= ~CAP_ECCTL1_CAPLDEN_BITS;
    
        return;
    } // end of CAP_disableCaptureLoad() function
    
    void CAP_disableSyncIn(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // set the bit
        cap->ECCTL2 &= ~CAP_ECCTL2_SYNCIEN_BITS;
    
        return;
    } // end of CAP_disableSyncIn() function
    
    void CAP_disableInt(CAP_Handle capHandle, const CAP_Int_Type_e intType)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECEINT &= ~intType;
    
        return;
    } // end of CAP_disableInt() function
    
    void CAP_disableTimestampCounter(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECCTL2 &= ~CAP_ECCTL2_TSCTRSTOP_BITS;
    
        return;
    } // end of CAP_disableTimestampCounter() function
    
    void CAP_enableCaptureLoad(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECCTL1 |= CAP_ECCTL1_CAPLDEN_BITS;
    
        return;
    } // end of CAP_enableCaptureLoad() function
    
    void CAP_enableInt(CAP_Handle capHandle, const CAP_Int_Type_e intType)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECEINT |= intType;
    
        return;
    } // end of CAP_enableInt() function
    
    void CAP_enableSyncIn(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // set the bit
        cap->ECCTL2 |= CAP_ECCTL2_SYNCIEN_BITS;
    
        return;
    } // end of CAP_enableSyncIn() function
    
    void CAP_enableTimestampCounter(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECCTL2 |= CAP_ECCTL2_TSCTRSTOP_BITS;
    
        return;
    } // end of CAP_enableTimestampCounter() function
    
    void CAP_setCapEvtPolarity(CAP_Handle capHandle, const CAP_Event_e event,
                               const CAP_Polarity_e polarity)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECCTL1 &= ~(1 << (2 * event));
    
        // Set the new value
        cap->ECCTL1 |= (polarity << (2 * event));
    
        return;
    } // end of CAP_setCapEvtPolarity() function
    
    void CAP_setCapEvtReset(CAP_Handle capHandle, const CAP_Event_e event,
                            const CAP_Reset_e reset)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECCTL1 &= ~(1 << (1 + (2 * event)));
    
        // Set the new value
        cap->ECCTL1 |= (reset << (1 + (2 * event)));
    
        return;
    } // end of CAP_setCapEvtReset() function
    
    void CAP_setCapContinuous(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECCTL2 &= (~CAP_ECCTL2_CONTONESHOT_BITS);
    
        return;
    } // end of CAP_setCapContinuous() function
    
    void CAP_setCapOneShot(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECCTL2 |= CAP_ECCTL2_CONTONESHOT_BITS;
    
        return;
    } // end of CAP_setCapOneShot() function
    
    void CAP_setModeCap(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECCTL2 &= (~CAP_ECCTL2_CAPAPWM_BITS);
    
        return;
    } // end of CAP_setModeCap() function
    
    void CAP_setModeApwm(CAP_Handle capHandle)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECCTL2 |= CAP_ECCTL2_CAPAPWM_BITS;
    
        return;
    } // end of CAP_setModeApwm() function
    
    void CAP_setStopWrap(CAP_Handle capHandle, const CAP_Stop_Wrap_e stopWrap)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECCTL2 &= (~CAP_ECCTL2_STOP_WRAP_BITS);
    
        // Set the new value
        cap->ECCTL2 |= stopWrap;
    
        return;
    } // end of CAP_setStopWrap() function
    
    void CAP_setSyncOut(CAP_Handle capHandle, const CAP_SyncOut_e syncOut)
    {
        CAP_Obj *cap = (CAP_Obj *) capHandle;
    
        // clear the bits
        cap->ECCTL2 &= (~CAP_ECCTL2_SYNCOSEL_BITS);
    
        // Set the new value
        cap->ECCTL2 |= syncOut;
    
        return;
    } // end of CAP_setSyncOut() function
    
    
    

    main.c:

    void main()
    {
     myCap = CAP_init((void *) CAP1_BASE_ADDR, sizeof(CAP_Obj));
    .
    .
    .
    .
    }
    void InitECapture()
    {
        CLK_enableEcap1Clock(myClk);
        CAP_setModeCap(myCap);
        CAP_disableInt(myCap, CAP_Int_Type_All);   // Disable all capture interrupts
        CAP_clearInt(myCap, CAP_Int_Type_All);      // Clear all CAP interrupt flags
        CAP_disableCaptureLoad(myCap);           // Disable CAP1-CAP4 register loads
        CAP_disableTimestampCounter(myCap);      // Make sure the counter is stopped
    
        // Configure peripheral registers
        CAP_setCapContinuous(myCap);
        CAP_setStopWrap(myCap, CAP_Stop_Wrap_CEVT4);             // Stop at 4 events
        CAP_setCapEvtPolarity(myCap, CAP_Event_1, CAP_Polarity_Rising); // Falling edge
        CAP_setCapEvtPolarity(myCap, CAP_Event_2, CAP_Polarity_Rising); // Rising edge
        CAP_setCapEvtPolarity(myCap, CAP_Event_3, CAP_Polarity_Rising); // Falling edge
        CAP_setCapEvtPolarity(myCap, CAP_Event_4, CAP_Polarity_Rising); // Rising edge
    
        CAP_setCapEvtReset(myCap, CAP_Event_1, CAP_Reset_Enable); // Difference operation
        CAP_setCapEvtReset(myCap, CAP_Event_2, CAP_Reset_Enable); // Difference operation
        CAP_setCapEvtReset(myCap, CAP_Event_3, CAP_Reset_Enable); // Difference operation
        CAP_setCapEvtReset(myCap, CAP_Event_4, CAP_Reset_Enable); // Difference operation
    
        CAP_disableSyncIn(myCap);
        CAP_setSyncOut(myCap, CAP_SyncOut_SyncIn);  // Pass through
    
        CAP_enableCaptureLoad(myCap);
    
        CAP_enableTimestampCounter(myCap);          // Start Counter
    
        CAP_enableCaptureLoad(myCap);             // Enable CAP1-CAP4 register loads
        CAP_enableInt(myCap, CAP_Int_Type_CEVT4);   // 4 events = interrupt
        Tst1 = CAP_getCap1(myCap); // Fetch Time-Stamp captured at t1
        Tst2 = CAP_getCap2(myCap); // Fetch Time-Stamp captured at t2
        Tst3 = CAP_getCap3(myCap); // Fetch Time-Stamp captured at t3
        Tst4 = CAP_getCap4(myCap); // Fetch Time-Stamp captured at t4
    }
    

  • Hello Team,

    Is there any solution update of my problem?

    Regards,

    Jesal

  • Sorry Jesal, code reviews can be long and difficult and it is not sustainable to debug all of our customers code.
    Being that C is an industry standard and that we have found the exact portion of your code that is causing the issue you should be able to complete the debug on your own.

    If you fix this issue and your code still does not function feel free to reply here an I help with the debug.

    Regards,
    Cody