cancel
Showing results for 
Search instead for 
Did you mean: 

Timer for stm32 discovery board

ss882
Associate II
Posted on August 30, 2012 at 19:44

Hello everyone,

I am new to embedded programming.

I was trying to make a simple program that measures frequency and ON time of two different i/p pulses. The frequency that I want to measure is in the range of 37 to 917 Hz where as On time is in msec range.

I wrote a program using two timers, followed steps given for initialization in stdperipheral examples.

The Problem is I am not reaching ISR even when event occurs.

I dont know where I am going wrong.

Any help will be highly appreciated..!!

Thanks
7 REPLIES 7
Posted on August 30, 2012 at 20:03

The Problem is I am not reaching ISR even when event occurs. I dont know where I am going wrong.

Me neither, sounds like an issue with initialization or vector table naming.

If you expect productive answers try providing something for people to work with.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ss882
Associate II
Posted on August 30, 2012 at 20:18

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6kL&d=%2Fa%2F0X0000000buX%2FuU4qmCpSnZWmf2YOUC1..cK5E8XsFA03RNcQKYp3Nmc&asPdf=false
Posted on August 31, 2012 at 01:53

Very similar to \STM32L1xx_StdPeriph_Lib_V1.1.1\Project\STM32L1xx_StdPeriph_Examples\TIM\InputCapture\main.c

The timers look to function a little different to the F1,F2 parts.

Did you change the stm32lxx_it.c file?

What tool chain are you using?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ss882
Associate II
Posted on August 31, 2012 at 11:22

Many thanks Clive1..!!

I am using IAR workbench.

 Do i need to use Remapping as you said in some earlier posts regarding timer input capture mode.

GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE); Heres te code for stm32l1xx_it

void TIM4_IRQHandler(void)

{

  if (TIM_GetITStatus(TIM4, TIM_IT_CC2) != RESET)

  {

    /* Clear TIM4 Capture compare interrupt pending bit */

    TIM_ClearITPendingBit(TIM4, TIM_IT_CC2);

    if(CaptureNumber == 0)

    {

      /* Get the Input Capture value */

      IC4ReadValue1 = TIM_GetCapture2(TIM4);

      CaptureNumber = 1;

    }

    else if(CaptureNumber == 1)

    {

      /* Get the Input Capture value */

      IC4ReadValue2 = TIM_GetCapture2(TIM4);

      

      /* Capture computation */

      if (IC4ReadValue2 > IC4ReadValue1)

      {

        Capture = (IC4ReadValue2 - IC4ReadValue1) - 1;

      }

      else if (IC4ReadValue2 < IC4ReadValue1)

      {

        Capture = ((0xFFFF - IC4ReadValue1) + IC4ReadValue2) - 1;

      }

      else

      {

        Capture = 0;

      }

      

      /* Frequency computation */

      TIM4Freq = (uint32_t) SystemCoreClock / Capture;

      CaptureNumber = 0;

    }

  }

}

ss882
Associate II
Posted on August 31, 2012 at 11:39

Also, how can i set prescaler value to measure 10 to 100s of msec pulse width??

ss882
Associate II
Posted on August 31, 2012 at 13:14

Thanks Clive.., I found the problem. Sounds so stupid but I had set NVIC vector table in flash and was using RAM.

Now the problem is, in freq measurement, in the range of 100s its measuring perfectly but in 10 of hundreds its giving almost random readings.

amrutsswapnil
Associate
Posted on February 22, 2014 at 09:35