AnsweredAssumed Answered

Hall-effect sensor

Question asked by b.matt on May 27, 2013
Latest reply on Dec 12, 2015 by baird.hal.001
Hello,

I'm trying to read rpm from a fan.
At first I tried with EXTI and while it worked at fast speed, it started to get crazy when halted or at low speed, especially when the voltage was at undefined state ~1.5V. Is there a way interrupts trigger when actually going from <1V to >2V ?

Now I'm trying with a timer in input capture mode ... looked at the reference manual (Interfacing with Hall sensors) and some googling to get this far ...

void HALL_Config(void){
  GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
   
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
   
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
   
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  TIM_ICInitTypeDef  TIM_ICInitStructure;
   
  TIM_TimeBaseStructure.TIM_Prescaler = 840;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_Period = 65535;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
   
  //Enable hall sensor
  TIM_SelectHallSensor(TIM2, ENABLE);
   
  // HallSensor event is delivered with singnal TI1F_ED
  // (this is XOR of the three hall sensor lines)
  // Signal TI1F_ED: falling and rising edge of the inputs is used
  TIM_SelectInputTrigger(TIM2, TIM_TS_TI1F_ED);
   
  // On every TI1F_ED event the counter is resetted and update is tiggered
  TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);
   
   
  // Channel 1 in input capture mode
  // on every TCR edge (build from TI1F_ED which is a HallSensor edge) 
  // the timervalue is copied into ccr register and a CCR1 Interrupt
  // TIM_IT_CC1 is fired
  TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_TRC;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;
  TIM_ICInit(TIM2, &TIM_ICInitStructure);
  
   
  TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
  //TIM_ITConfig(TIM2, TIM_IT_Trigger, ENABLE);
   
  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
   
  TIM_Cmd(TIM2, ENABLE);
}

... but the interrupt handler never triggers

any help appreciated
~Matt

Outcomes