Mark Loit

Bug in FTM_SetupDualEdgeCapture()

Discussion created by Mark Loit on Apr 24, 2019
Latest reply on Apr 24, 2019 by Jing Pan

There is a bug in set-up of the input filtering. The function accepts a channel pair number, but this pair number is used as a direct channel number when setting up the filter.

 

Code currently in SDK 2.5.0 (and earlier)

    /* Input filter available only for channels 0, 1, 2, 3 */
    if (chnlPairNumber < kFTM_Chnl_4)
    {
        reg = base->FILTER;
        reg &= ~(FTM_FILTER_CH0FVAL_MASK << (FTM_FILTER_CH1FVAL_SHIFT * chnlPairNumber));
        reg |= (filterValue << (FTM_FILTER_CH1FVAL_SHIFT * chnlPairNumber));
        base->FILTER = reg;
    }

This is incorrect as the check in the code expects a channel number, not a pair number. The bits in the FILTER register are also for channels not pairs.

 

My proposed correction is as follows.

    /* Input filter available only for channels 0, 1, 2, 3. Thus pairs 0 & 1 only (channels 0 & 2) */
    if ((chnlPairNumber*2) < kFTM_Chnl_4)
    {
        reg = base->FILTER;
        reg &= ~(FTM_FILTER_CH0FVAL_MASK << (FTM_FILTER_CH1FVAL_SHIFT * (chnlPairNumber*2)));
        reg |= (filterValue << (FTM_FILTER_CH1FVAL_SHIFT * (chnlPairNumber*2)));
        base->FILTER = reg;
    }

This change is in-line with the rest of the code that converts the pair into a channel number when setting the register values.

Outcomes