cancel
Showing results for 
Search instead for 
Did you mean: 

Timer as Counter

muralij21
Associate II
Posted on December 03, 2010 at 11:49

Timer as Counter

14 REPLIES 14
dsystem
Associate II
Posted on May 17, 2011 at 14:17

Dear Karakaya

Can you give me code for counting from CH1?

Regards

mehmet.karakaya
Associate III
Posted on May 17, 2011 at 14:17

this is my code for CH1 counting

void TIM4init(void) {

 

  /* Time base configuration */

 

  TIM_TimeBaseStructure.TIM_Period = 0xffff;

 

  TIM_TimeBaseStructure.TIM_Prescaler = 0;

 

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

 

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

  TIM_ITConfig(TIM4,TIM_IT_Update , ENABLE);

 

 

  TIM4->CCMR1=0x0031;

 

  TIM4->SMCR=0x0057;

 

  TIM_Cmd(TIM4, ENABLE);

 

}

madhu13
Associate III
Posted on May 17, 2011 at 14:17

''dont waste your time counting pulses at ETR pin

 

 

no matter what I tried I couldnot count ETR pulses - ( there is probably a bug in hardware )

 

try to count pulses at CH1 of the timer - it works''

there is no bug in hardware, TIM_CH1 and TIM_ETR share the same pin, by default TIM_CH1(i.e. PA0) is mapped to the pin, if you want to use TIM_ETR(i.e.PA15) pin remap the pin by programming AF remap and debug I/O configuration register (AFIO_MAPR) TIM2_REMAP(bits 9 & 8) then your code will work

mehmet.karakaya
Associate III
Posted on May 17, 2011 at 14:17

hello ,

I tried to count ETR pulses of TIM3

which is conected to PD2 - it didnot count - I insist that there is hardware bug

in the manual it ''doesnot'' say that TIM3_ETR and TIM3_CH1 share the same pin

can you please write the code here which couns TIM3_ETR pulses ?

madhu13
Associate III
Posted on May 17, 2011 at 14:17

karakaya.mehmet, u can use TIM2_ETR pin to count pulses by using the remap, and u can not count pulse using TIM3_ETR