cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F205 TIM2 Capture

cm600
Associate II
Posted on September 27, 2011 at 12:04

Is it possible to use the timer clock prescaler in input capture mode? I used some different values but 

that doesn't seem to make a difference, the value in TIM2->CCR3 is the same every time. 

5 REPLIES 5
raptorhal2
Lead
Posted on September 27, 2011 at 21:35

Yes.

Look at the peripheral code examples that come with the library.

Cheers, Hal

cm600
Associate II
Posted on September 28, 2011 at 09:13

In the StdPeriphLib InputCapture example only the input capture prescaler is used not the timer clock prescaler.

raptorhal2
Lead
Posted on September 28, 2011 at 21:48

Show your code and describe the capture input signal.

Cheers, Hal

cm600
Associate II
Posted on September 29, 2011 at 11:16

CPU speed 60MHz

APB2 prescaler = 1 60MHz

APB1 prescaler = 2 30MHz -> timer 2 clock 60MHz

void TIM2_init(void)

{

RCC->APB1ENR |= (1 << TIM2EN);

TIM2->PSC = 5; 

TIM2->CCMR2 = ( (1 << CC3S_bfi) | (1 << CC4S_bfi) );  

TIM2->CCER = TIM_CCER_CC3P | TIM_CCER_CC4P; // capture on falling edge

TIM2->DIER = TIM_DIER_CC3IE | TIM_DIER_CC4IE; 

}

TIM2->CR1 |= TIM_CR1_CEN;

TIM2->CCER |= TIM_CCER_CC3E | TIM_CCER_CC4E; // enable capture

while(!(TIM2->SR & TIM_SR_CC3IF)) 

{

// wait for the first falling edge

}

TIM2->CNT = 0x00000000; // clear counter

p_res->reper_ticks_adj = TIM2->CCR3;  // clear flag

while(!(TIM2->SR & TIM_SR_CC3IF)) 

{

// wait for the second falling edge

}

p_res->reper_ticks_adj = TIM2->CCR3;

printf(''%u \n'',p_res->reper_ticks_adj); 

...........................................................................

The input signal is square wave. The time between two falling edges is 0.6s

For example:

TIM2->PSC = 1;

CCR3: 36 000 000 

TIM2->PSC = 5;

CCR3: 36 000 000 

It looks like the timer is always clocked @ 60MHz no mather what the prescaler value is.

cm600
Associate II
Posted on September 30, 2011 at 16:53

Problem solved, i wasn't setting the UG bit :)g