cancel
Showing results for 
Search instead for 
Did you mean: 

measure time duration

kong0073
Associate II
Posted on July 13, 2011 at 09:19

I have a string of pulses coming in, and i want to measure the period of a pulse. So i have initialize the input capture for the timer, in my case TIM2 CH4.

 RCCIC_Configuration();

      /* NVIC configuration */

    NVICIC_Configuration();

      /* Configure the GPIO ports */

    GPIOIC_Configuration();

    TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;

    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 = 0x0;

    TIM_ICInit(TIM2, &TIM_ICInitStructure);

    /* TIM enable counter */

    TIM_Cmd(TIM2, ENABLE);

    /* Enable the CC4 Interrupt Request */

    TIM_ITConfig(TIM2, TIM_IT_CC4, ENABLE);

but how do i go about starting the time duration measurement when i see a ''1'' at my input and count until another ''1'' appears?

#stm32 #pulse #time-duration
3 REPLIES 3
Posted on July 13, 2011 at 14:34

Read the timer registers, and compute a delta time at the clocking frequency?

What's the min/max time between pulses?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kong0073
Associate II
Posted on July 14, 2011 at 03:24

can u elaborate?

which timer registers are u referring to? the time between each pulse should be approximately values in ms. and what do you mean by computing a delta time?

Posted on July 14, 2011 at 18:46

Well presumably you're going to want to read the CCR registers at some point, because the main timer is going to tick away, and you're looking to ''capture'' an event which it latches.

delta - difference, time between two points, in a tick unit/quantum, that's presumably not a second, but based on a time line measured in TIMCLK periods.

For a millisecond, you're going to need to watch the clock, at 72 MHz, your going to blow through the 16-bit resolution in 1 millisecond (72000 ticks). 36 MHz might be viable, but you'll also need to watch/account for when it rolls over.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..