cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L151: Timer Capture Input (TIMx_CHy vs TIMx_ICy)

rehfinger
Associate
Posted on June 23, 2014 at 17:02

Hi,

I'm using a STM32L151 and would like to connect the pin PA2 to one of the timer capture inputs. According to the reference manual and the example InputCaptureRouting in the STM32L1xx_StdPeriph_Lib_V1.1.1, this code should do the trick:

    RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOAEN, ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_COMP | RCC_APB1Periph_PWR, ENABLE);

    GPIO_InitTypeDef GPIO_InitStructure;

    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_2;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;

    GPIO_InitStructure.GPIO_PuPd  = 0;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;

    GPIO_Init(GPIOA, &GPIO_InitStructure);

&sharpif 1

    // Route PA2 to TIM2_IC3

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_RI);

    SYSCFG_RITIMSelect(TIM_Select_TIM2);

    SYSCFG_RITIMInputCaptureConfig(RI_InputCapture_IC3, RI_InputCaptureRouting_0/*0: PA2*/);

&sharpelse

    // Use PA2 as TIM2_CH3

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM2);

&sharpendif

    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

    TIM_TimeBaseStructure.TIM_Period = 65535;

    TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock/*Hz*/ / 100000/*10us/s*/) - 1;

    TIM_TimeBaseStructure.TIM_ClockDivision = 0;

    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

    // Use TIM2_IC3 as Input Capture

    TIM_ICInitTypeDef  TIM_ICInitStructure;

    TIM_ICInitStructure.TIM_Channel     = TIM_Channel_3;

    TIM_ICInitStructure.TIM_ICPolarity  = TIM_ICPolarity_Rising;

    TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

    TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

    TIM_ICInitStructure.TIM_ICFilter    = 3;   // Filter: 8 clocks

    TIM_ICInit(TIM2, &TIM_ICInitStructure);

    TIM_Cmd(TIM2, ENABLE);

This should connect the pin PA2 to the Timer Capture Input TIM2_IC3. I would expect that pin PA2 is in a high impedance state in this case, but on a scope it is easy to see that it is driven low by the STM32.

If I change the

&sharpif 1

in the snippet above to

&sharpif 0

, everything works as expected: PA2 is in high impedance state and a rising edge captures TIM2_CNT in register TIM2_CCR3.

Actually, I need to use PA10 as a Timer Capture Input which is only possible if it's routed via the RI module. I assumed that (if correctly configured) the

TIMx_ICy

signals are equivalent to the according

TIMx_CHy

signals. Is this correct (the documentation is not 100% clear in this point)?

#worst-forum-software-ever #stm32-timer-capture-input
4 REPLIES 4
christian2399
Associate
Posted on July 10, 2014 at 16:44

Hello Thomas,

I encountered the same issue.  My line is always set to 0 when I routed TIM4 IC channel 4 to C.11.    Also, I don't get any input capture interrupt.  I set it in both edge.

Did you find something to fix it?

Christian

 

bhamilton
Associate II
Posted on July 23, 2014 at 04:09

edit: And another extra post which I can't delete.  Turns out the edit button doesn't do what I expected it to either.

bhamilton
Associate II
Posted on July 23, 2014 at 04:11

edit:  whoops, double post.

Posted on July 23, 2014 at 09:35

Thanks for sharing this info. It's a shame the UM couldn't be clear enough in these important details.

The link you gave needs login; this does not (ugly, but that how this crap of a forum works): [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32L100%20RI%20for%20TIM%20IC%20routing&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=16]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FSTM32L100%20RI%20for%20TIM%20IC%20routing&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=16

JW