cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Input Capture in STM32F103RBT6

shrfhegazy
Associate II
Posted on August 22, 2011 at 15:25

Hi all!

I'm using STM32F103RBT6, board Olimex STM32-H103 and i'm trying to create an IR receiving firmware.

I'm using Input Capture mode TIM1-Channel1 with the specs below:

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    TIM_ICInitTypeDef  TIM_ICInitStructure;

    TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;

    TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;

    TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

    TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

    TIM_ICInitStructure.TIM_ICFilter = 0xf;

    TIM_ICInit(TIM1, &TIM_ICInitStructure);

    /* Enable the CC1 Interrupt Request */

    TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE);

    /* TIM1 enable counter */

    TIM_Cmd(TIM1, ENABLE);

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

and the NVIC specs:

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    NVIC_InitTypeDef NVIC_InitStructure;

    /* Enable the TIM1 global Interrupt */

    NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

 

The problem is: the TIM1 CC interrupt handler is being called every time i connect the PA.8 (which is internally linked to TIM1-CH1) with a floating wire.

#input-capture #stm32f103rbt6
7 REPLIES 7
raptorhal2
Lead
Posted on August 22, 2011 at 16:37

So why do you think that a floating wire that probably has an electrostatic charge or is picking up RF would not trigger an interrupt ? And what is the significance in your IR application of using a floating wire?

Cheers, Hal

shrfhegazy
Associate II
Posted on August 23, 2011 at 09:34

First thx for attention 🙂

Second I was just testing the hardware with many ways not just the floating wire.

Third, the problem solved , thx a lot:)

shrfhegazy
Associate II
Posted on August 23, 2011 at 16:57

Another Problem:(

I've found that it just sees the first falling or rising edge, while my signal is a chain of pulses that i want to know the time between an edge and the one comes next.

What can i do?? quick reply please!!
raptorhal2
Lead
Posted on August 23, 2011 at 17:50

First you need to read the All Densities Reference Manual section on timer capture mode to get a basic understanding of how capture works. Then in your interrupt service routine, you read the timer register value at each interrupt, subtract the previous register value and compute a time difference based on the timer frequency. You need some logic to cater to timer register overflows between captures.

See the timer capture examples that come with the Standard Peripheral Library for more hints.

Cheers, Hal

shrfhegazy
Associate II
Posted on August 25, 2011 at 09:38

I've already done all of that, and what i figured out that TIM_GetCapture just takes the first edge of the chain and ignores any come after that.

I need a solution!!!

raptorhal2
Lead
Posted on August 25, 2011 at 14:30

I presume you haven't posted a complete program because it is proprietary or too large. Create a test program that does only the capture function and see if that works. If it doesn't work, post it in the forum for review.

Cheers, Hal

shrfhegazy
Associate II
Posted on August 25, 2011 at 14:56

Yes, i'm running on a test program already, but the problem was in the repeat pulses that i've not taken into my account so the program was making a lot of tricks and illogical things, i'm on my way now to solve it and enhance the code, thx a lot for your attention bro 🙂