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.

RTOS/CC2640R2F: RTC Capture Pin Selection

Part Number: CC2640R2F

Tool/software: TI-RTOS

Hi everyone,

I will use Real Time Clock to capture pulse duration instead of GPTimer.

// Set channel 1 in capture mode
AONRTCModeCh1Set(AON_RTC_MODE_CH1_CAPTURE);

// Enable channel
AONRTCChannelEnable(AON_RTC_CH1);
AONEventRtcSet(AON_EVENT_DIO27);
AONRTCEnable();

I would like to set DIO17 pin in launchpad to capture. How can i set that which pin the rtc will capture ?
How can i trigger DMA to save the capture time to the memory when new capture result is ready ?


I edited the post and add the following text.


I worked on this topic a little bit. Here is what i did

void gpioButtonFxn0(uint_least8_t index)
{
    AONRTCChannelEnable(AON_RTC_CH1);
    AONRTCEnable();
}

void *mainThread(void *arg0)
{
    /* Call driver init functions */
    GPIO_init();

    /* install Button callback */
    GPIO_setCallback(Board_GPIO_BUTTON1, gpioButtonFxn0);

    /* Enable interrupts */
    GPIO_enableInt(Board_GPIO_BUTTON1);

    // Disable all channel
    AONRTCChannelDisable(AON_RTC_CH0);
    AONRTCChannelDisable(AON_RTC_CH1);
    AONRTCChannelDisable(AON_RTC_CH2);

    AONRTCModeCh1Set(AON_RTC_MODE_CH1_CAPTURE);
    //AONEventRtcSet(AON_EVENT_DIO17); //Note mapping is package dependent
    AONEventRtcSet(AON_EVENT_IO); //Note mapping is package dependent

    while(AONRTCEventGet(AON_RTC_CH1) == false);

    data = AONRTCCaptureValueCh1Get();
}

When i press the button1 on the launchpad, the AON_RTC will be enabled and the its counter starts counting. 
If any rising edge is detected on any pin, AON_RTC will be triggered to latch the counter value.
After this trigger, I should see the event flag in AON_RTC:EVFLAGS that tells new capture time is ready to read.
However, it did not. I cannot capture edge time. 

Third edit

#define IO_CAPTURE                  IOID_17 //BTN_SELECT
#define AON_EVENT_DIO17             1 // 7x7

void *mainThread(void *arg0)
{

    uint32_t data = 0;

    PRCMPowerDomainOn(PRCM_DOMAIN_PERIPH);
    while(PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON);

    PRCMPeripheralRunEnable(PRCM_PERIPH_GPIO);
    PRCMLoadSet();
    while(!PRCMLoadGet());

    /* Call driver init functions */
    //GPIO_init();

    /* install Button callback */
    //GPIO_setCallback(Board_GPIO_BUTTON1, gpioButtonFxn0);

    /* Enable interrupts */
    //GPIO_enableInt(Board_GPIO_BUTTON1);



    IOCPortConfigureSet(IO_CAPTURE, IOC_PORT_GPIO, SLOW_CLOCK_GPIO_CFG);
    IOCIntEnable(IO_CAPTURE);

    // Disable all channel
    AONRTCChannelDisable(AON_RTC_CH0);
    AONRTCChannelDisable(AON_RTC_CH1);
    AONRTCChannelDisable(AON_RTC_CH2);

    //AONEventMcuWakeUpSet(AON_EVENT_MCU_WU3, AON_EVENT_RTC_CH1);
    //AONRTCCombinedEventConfig(AON_RTC_CH1);

    AONRTCModeCh1Set(AON_RTC_MODE_CH1_CAPTURE);

    //AONEventRtcSet(AON_EVENT_IO); //Note mapping is package dependent

    AONRTCChannelEnable(AON_RTC_CH1);
    AONRTCEnable();

    AONEventRtcSet(AON_EVENT_DIO17); //Note mapping is package dependent

    while(AONRTCEventGet(AON_RTC_CH1) == false);

    data = AONRTCCaptureValueCh1Get();


}

Which value i should give to AONEventRtcSet function to set DIO 17 pin as event pin for RTC ?
According to the hw_device.h, i should give 1. However. when i applied pulse to DIO17 pin, RTC could not catch the trigger.

Please, help me to solve my problem. What is thing that i am missing ?




Have a nice day.

  • Hi again,

    Any suggestion ?
  • Hi Erdem,

    Which version of the SimpleLink CC2640R2 SDK are you using? Have you reviewed the associated documentation for the RTC? You should be able to view the documentation here: <SDK_INSTALL_DIR>/docs/driverlib_cc13xx_cc26xx/cc26x0r2/driverlib/index.html
  • Hi Rachel,

    I am using simplelink_cc2640r2_sdk_1_35_00_33 and i read all documentation about RTC.

    Probably, i missing something.
    Please, help me to solve my problem

    Best Regards
  • Hi Erdem,

    The RTC capture event can be a bit tricky to implement. The reason you are not getting the capture events as you expect is due to the interplay between the RTC and the GPIO driver. Your code itself should work just fine, I'll post what I'm using to test this below.

    The problem you are experiencing is that the interrupt event generated by the GPIO is in this case subscribed to by (at least) two consumers, the GPIO driver and the RTC module. Now some sync problems occur between the two, as the RTC is running on the low frequency clock while the CPU is running on the high frequency clock. The RTC module will sample the GPIO event on the low-frequency clock edge, while the GPIO driver will be able to consume the event immediately. When the event is consumed by the GPIO driver, it will also clear this event line before the RTC will be able to sample the event and it ends up missing the event.

    This can be "patched" to work as you would expect it to by making the PIN driver (the GPIO driver is based on this one) wait for the RTC to sync up with the main CPU. This would however affect the GPIO response time in the process (the delay time will be at least 2 low-frequency clock cycles)

    I did my example based on the "gpiointerrupt" example and ended up with the code below:.

    /*
     *  ======== gpioButtonFxn0 ========
     *  Callback function for the GPIO interrupt on Board_GPIO_BUTTON0.
     */
    void gpioButtonFxn0(uint_least8_t index)
    {
        AONRTCChannelEnable(AON_RTC_CH1);
    }
    
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
    
        /* Call driver init functions */
        GPIO_init();
    
        /* Configure the LED and button pins */
        //GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD  | GPIO_CFG_OUT_LOW);
        GPIO_setConfig(Board_GPIO_LED1, GPIO_CFG_OUT_STD  | GPIO_CFG_OUT_LOW);
        GPIO_setConfig(Board_GPIO_BUTTON0, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING);
        GPIO_setConfig(Board_GPIO_BUTTON1, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING);
        GPIO_setConfig(E2E_DIO0_TEST     , GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING);
    
        /* install Button callback */
        GPIO_setCallback(Board_GPIO_BUTTON0, gpioButtonFxn0);
    
        /* Enable interrupts */
        GPIO_enableInt(Board_GPIO_BUTTON0);
        GPIO_enableInt(Board_GPIO_BUTTON1);
        GPIO_enableInt(E2E_DIO0_TEST);
    
        AONRTCChannelDisable(AON_RTC_CH1);
        AONRTCModeCh1Set(AON_RTC_MODE_CH1_CAPTURE);
        AONEventRtcSet(AON_EVENT_IO);
    
        while(1) {
            while(AONRTCEventGet(AON_RTC_CH1) == false);
    
            uint32_t data = AONRTCCaptureValueCh1Get();
            AONRTCEventClear(AON_RTC_CH1);
        }
    
        return (NULL);
    }

    In combination with this, I added two AONUpdate syncs inside the PIN hwi function (inside the PINCC26XX driver):

    // I/O HWI service routine
    static void PIN_hwi(uintptr_t arg) {
        uint32_t eventMask;
    
        // Sync with RTC
        SysCtrlAonUpdate();
        SysCtrlAonUpdate();
    
    
        // Get event flag with lowest index (also pin ID)
        eventMask = HWREG(GPIO_BASE + GPIO_O_EVFLAGS31_0);
    
        // Clear this event flag
        HWREG(GPIO_NONBUF_BASE + GPIO_O_EVFLAGS31_0) = eventMask;
    
        // Include all GPIO's currently triggered in the SWI
        SwiP_or(&(pinSwi), eventMask);
    }
    

    Regarding the DMA part, I would would not recommend trying to use it together with the RTC. While it might be possible to implement it, it would very likely end up interfering with the system clock as this is sourced from the RTC. The DMA will generate an interrupt on the peripheral when a transfer is completed (while also blocking any "Normal" interrupts to the peripheral during the transfer). I suspect this will cause problems with the system clock.