AnsweredAssumed Answered

External clock for Timer

Question asked by kihlmark.richard on Aug 19, 2014
Latest reply on Aug 19, 2014 by kihlmark.richard
Hi,

We're using STM32F307.
Trying to get Timer3/Ch 4 to count edges from a 24VDC fan tachometer to get Rpm.
Done research through Reference manual and forum posts.
Obviously I'm missing something.
We also tried Input Capture and can see that clock is counting real fast between edges, but this is not what we want.
At full speed fan pulses are 100Hz.
Think we need to use TIM_ETRClockMode2 since we need to use Ch 4 of the timer.
Here is the code, of course we've tried a lot of other Firmware with no luck:

/* TIM3/4 count Tachometer edges using ADC1 Ch 4 terminal as input */
void ConfigTach(void) Beg
 
  /* TIM3 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
 
  /* GPIOB clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
   
  /* GPIOB Configuration: TIM3/4 (PB1) */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
 
  /* Connect TIM3/4 pin (PB1) to AF (Alternate Function) */
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource1,GPIO_AF_TIM3);
 
  /* Configure TIM3/4 to capture rising edges */
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_Period = 0xFFFF; // TIM3 is 16-bit counter
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
 
  /* Timer is triggered by external clock (Fan Tachometer) */
  TIM_ETRClockMode2Config(TIM3,TIM_ExtTRGPSC_OFF,TIM_ExtTRGPolarity_NonInverted,0x0);   
 
  /* TIM3 enable counter */
  TIM_Cmd(TIM3,ENABLE); // start Timer
End

Outcomes