Skip to main content
atox86
Associate II
June 28, 2010
Question

input capture problem with stm32

  • June 28, 2010
  • 11 replies
  • 2110 views
Posted on June 28, 2010 at 13:09

input capture problem with stm32

    This topic has been closed for replies.

    11 replies

    atox86
    atox86Author
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:56

    Meanwhile, thanks for your interest.

    I just tried but nothing has changed.

    Always gives me zero frenquenza.

    The signal I am simulating a frequency of 200Hz.

    Ok take out the printf.

    Overall missing a configuarazione to do?? All the code I wrote in first post

    raptorhal2
    Lead
    May 17, 2011
    Posted on May 17, 2011 at 13:56

    Try replacing:

       while((TIM3->SR & TIM_FLAG_CC2) != TIM_FLAG_CC2);

    with:

       while((TIM3->SR & TIM_FLAG_CC2) != RESET);

    in two places.

    Also - what range of frequencies are you trying to measure? Waiting for a printf after the first capture compare will limit your upper frequency.

    Cheers, Hal

    raptorhal2
    Lead
    May 17, 2011
    Posted on May 17, 2011 at 13:56

    I will try....again.

    The program may have locked out the interrupt. You enabled an interrupt, but as far as I can tell here, you did not clear the interrupt in an IRQ handler. See the vectors.c file int the STM library TIM examples for IRQ handler programming.

    The IRQ handler is a good place to read the capture register, since the interrupt has just occurred. Your main.c can then printf without disturbing the capture timing.

    Cheers, Hal

    atox86
    atox86Author
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:56

    anyone can help me????

    raptorhal2
    Lead
    May 17, 2011
    Posted on May 17, 2011 at 13:56

    STM has provided an example that does what you are trying to do. Go to the STM32 Downloads section and make the following selections:

    Downloads

         Documents and Files

              Firmware

                   STM32F10x_StdPeriph_Lib

    Download the library to your computer, and then make the following selections in the library directories:

    Project

         STMF10xStdPeriph_Examples

              TIM

                   Input Capture

                        main.c          and          stm32f10x_it.c

    main.c sets up the clocks, NVIC, timer interrupts, etc., then goes into an idle mode. stm32f10x_it.c contains the IRQ handler which services the interrupt, then computes the frequency.

    If you wish to print out the frequency at some interval, you should add that to main.c as I stated in an earlier post.

    This should get you going.

    A votre sante !    Hal

    atox86
    atox86Author
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:56

    Hello Cheers Hal, thank you very much for your help.

    I did not understand what to do with IRQ handler sorry but this is the first time I make this type of programming and not the ST is helping me.

    You think that there can be blocked interrupt? Stm32f10x_stdperiph_lib From the examples I see this call enables interrupts by ''TIM_ITConfig (TIM3, TIM_IT_CC2, ENABLE);'' and then configure the nvic through this function call

    NVIC_Configuration void (void)

    (

      

    NVIC_InitTypeDef NVIC_InitStructure;

      

    / * Enable the Global Interrupt TIM3 * /

      

    NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;

      

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

      

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

      

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

      

    NVIC_Init (& NVIC_InitStructure);

    )

    I do not know what to do, I'm going crazy the brain.

    Do not have a working code sample so I can understand how and what to do?? I searched throughout the forum but have not found anything that can help me.

    Thanks again for your help

    P.s.= i've found vectors.c but didn't help me :S

    atox86
    atox86Author
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:56

    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=0680X000006I6ZC&d=%2Fa%2F0X0000000bqp%2FMt4SwoZzhR9xVpePQ0v2diC.Pu5Y2x8WgoGZNOtLzck&asPdf=false
    raptorhal2
    Lead
    May 17, 2011
    Posted on May 17, 2011 at 13:56

    Your interrupt handler name is different from the standard peripheral library example. Perhaps your development environment TIM interrupt vector is pointing to a different interrupt handler.

    Cheers, Hal

    raptorhal2
    Lead
    May 17, 2011
    Posted on May 17, 2011 at 13:56

    I am guessing because I can't see how you have put together your program in your development environment.

    Look at an example such as ''Hello'' provided with your environment. It probably has another file such as vectors.c with all the interrupt handlers. The unused handlers will simply halt on interrupt. And, there should be a start up file that initializes all the interrupt vectors to call the handlers. You need both of these files (or something equivalent) in your program. Then you modify the TIM3 IRQ Handler to service the interrupt and calculate the frequency.

    If this is still a puzzle to you, find someone experienced who can look at your program for errors.

    Cheers, Hal

    atox86
    atox86Author
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:56

    Ah ok then it must have the same function name in the library?? Did I call it differently to avoid confusion.

    But I must call the main function or not?? Thanks again for your help