cancel
Showing results for 
Search instead for 
Did you mean: 

TIM_ICPOLARITY_BOTHEDGE Input capture in STM32L

gerardo
Associate II
Posted on November 28, 2014 at 19:24

Hello Guys,

I´m developing an application with STM32L and I would like to use TIM2 Input capture with TIM_ICPOLARITY_BOTHEDGE.

When the interrupt occurs...

Is there a way of knowing which Polarity has been detected?

Maybe it can be able getting the digital value of this channel. If it is high Rising edge has occured. Isn´t it?

Is there  some better solution?
7 REPLIES 7
Posted on November 28, 2014 at 20:43

Is there some better solution?

Use channel 1 & 2 to catch opposite edges, with channel 2 using TI1 (Timer Input 1)
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gerardo
Associate II
Posted on November 28, 2014 at 21:01

I only have one pin to do it

Posted on November 28, 2014 at 21:16

I only have one pin to do it

And so?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gerardo
Associate II
Posted on November 28, 2014 at 21:45

I dont understand your answer sorry :(

Posted on November 28, 2014 at 22:02

Perhaps a diagram from the

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/CD00240193.pdf

might help...

0690X00000602yvQAA.jpg

One pin, Two channels, Capturing opposite edges of the same Input.

Each edge time stamps against the Time Base, Each generates a uniquely identifiable IRQ.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gerardo
Associate II
Posted on November 28, 2014 at 22:10

Once again the correct answer. Thank you so much clive

gerardo
Associate II
Posted on November 28, 2014 at 22:40

0690X00000602vnQAA.jpg

Is this configuration correct??

GPIO_InitStruct.Pin =  GPIO_PIN_2;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_PULLUP;

GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

GPIO_InitStruct.Alternate = GPIO_AF2_TIM2;

¿How can I remap my PA2 pint to Alternate function CH4?

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

void

HAL_TIMInit(void)

{   

    // Enable TIM2 Clock

    __TIM2_CLK_ENABLE();

    

    // Timer configuration

    TimHandle.Instance           = TIM2;

    TimHandle.Init.Period        = T2_FULL_SCALE;

    TimHandle.Init.Prescaler     = T2_PSC;

    TimHandle.Init.ClockDivision = 0;

    TimHandle.Init.CounterMode   = TIM_COUNTERMODE_UP;

    HAL_TIM_IC_Init(&TimHandle);

    

    // Configure the Input Capture of channel 3 (PA2)

    sICConfig.ICPolarity  = TIM_ICPOLARITY_FALLING;

    sICConfig.ICSelection = TIM_ICSELECTION_DIRECTTI;

    sICConfig.ICPrescaler = TIM_ICPSC_DIV1;

    sICConfig.ICFilter    = 0; //0x03; // Input filter for 8 clock Cycles

    HAL_TIM_IC_ConfigChannel(&TimHandle, &sICConfig, TIM_CHANNEL_3);

    

    // Set the TIM2 global Interrupt

    HAL_NVIC_SetPriority(TIM2_IRQn, 0, 1);

  

    // Enable the TIM2 global Interrupt

    HAL_NVIC_EnableIRQ(TIM2_IRQn);

    

    // Start the Input Capture in interrupt mode

    HAL_TIM_IC_Start_IT(&TimHandle, TIM_CHANNEL_3);

    HAL_TIM_IC_Start_IT(&TimHandle, TIM_CHANNEL_4);

}

¿How can I configure CH4 with rising polarity?