cancel
Showing results for 
Search instead for 
Did you mean: 

Input capture Porblem

mahmoud boroumand
Associate III
Posted on July 31, 2017 at 13:55

Hey 

I use stm32f030p4 and i want counting a external frequency (Learning remote ).

I configure timer  and interrupts like this

TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;

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(TIM3, &TIM_ICInitStructure);

/* Enable the CC2 Interrupt Request */

TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);

/* Enable the TIM1 global Interrupt */

NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

uint32_t now =0;

void TIM3_IRQHandler(void)

{

if(TIM_GetITStatus(TIM3, TIM_IT_CC1) == SET)

{

TIM_ClearITPendingBit(TIM3,TIM_IT_CC1);

now=TIM_GetCapture1(TIM3);

}

}

Interrupt work good but 

TIM_GetCapture1(TIM3) is always 0 .

how can i solve this problem?

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on July 31, 2017 at 14:29

i dont use tim_cmd(tim3,enable)

That's why the timer is not running, i.e. TIM3_CNT is always 0. So then of course if you capture it (i.e copy CNT into CC1) then you always capture 0.

JW

View solution in original post

4 REPLIES 4
Posted on July 31, 2017 at 14:06

Is TIM3 actually running (enabled in TIM3_CR1.CEN and TIM3_ARR nonzero)?

JW

Posted on July 31, 2017 at 14:19

Hey i use the STM32F0xx_StdPeriph_Examples and interrupt work well in rising edge. and i dont use tim_cmd(tim3,enable)

Posted on July 31, 2017 at 14:29

i dont use tim_cmd(tim3,enable)

That's why the timer is not running, i.e. TIM3_CNT is always 0. So then of course if you capture it (i.e copy CNT into CC1) then you always capture 0.

JW

Posted on August 01, 2017 at 09:00

Thanks