cancel
Showing results for 
Search instead for 
Did you mean: 

Configure hall sensor on STM32_ini.c from Keil

ivitro
Associate II
Posted on September 06, 2011 at 21:29

Hi guys,

I need some help to configure TIM4 for hall sensor.

the STM32_ini.c is attach.
4 REPLIES 4
ivitro
Associate II
Posted on September 08, 2011 at 01:44

Any help?

so, my motor speed is 5000rpm what is the best config of PSC for timer not overflow?

// define timer clock

// between two changes on the hall sensor lines on the lowest rotation

// speed (eg. 1/100 from max. speed) the timer must not overflow

// define timer counter clock appropriate

// timer base configuration

// 126 => 3,5s till overflow ; 285,714kHz TimerClock [36MHz/Prescaler]

 TIM_TimeBaseStructure.

TIM_Prescaler

=

126

; TIM_TimeBaseStructure.

TIM_CounterMode

= TIM_CounterMode_Up; TIM_TimeBaseStructure.

TIM_Period

=

65535

; TIM_TimeBaseStructure.

TIM_ClockDivision

=

0

; TIM_TimeBaseStructure.

TIM_RepetitionCounter

=

0

; TIM_TimeBaseInit

(

TIM4, &TIM_TimeBaseStructure

)

; i not understand why 126

Dino COSTANZO
Associate II
Posted on September 08, 2011 at 18:12

Hello,

sorry, I do not know how it's configured in the Keil source example. Anyhow, there's a similar module in the STM32 PMSM FOC SDK v3.0 to handle Hall sensor signals, here below an excerpt of the timer peripheral configuration:

... 

  /* Set full 16-bit working range */

  TIM_HALLTimeBaseInitStructure.TIM_Period = U16_MAX;

  TIM_HALLTimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;

  TIM_TimeBaseInit(TIMx,&TIM_HALLTimeBaseInitStructure);

 

  TIM_ICStructInit(&TIM_HALLICInitStructure);

  TIM_HALLICInitStructure.TIM_Channel = TIM_Channel_1;

  TIM_HALLICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;

  TIM_HALLICInitStructure.TIM_ICFilter = pDParams_str->hInpCaptFilter;

 

  TIM_ICInit(TIMx,&TIM_HALLICInitStructure);

 

  /* Force input capture from TRC */

  /* Disable the Channel 1: Reset the CC1E Bit */

  TIMx->CCER &= CCER_CC1E_Reset;

  TIMx->CCMR1 |= 0x03u; /* CCS1 = 0b11; */

  TIMx->CCER |= CCER_CC1E_Set;

 

  /* Force the TIMx prescaler with immediate access (no need of an update event)

  */

  TIM_PrescalerConfig(TIMx, (u16) pDVars_str->hHALLMaxRatio,

                      TIM_PSCReloadMode_Immediate);

  TIM_InternalClockConfig(TIMx);

 

  /* Enables the XOR of channel 1, channel2 and channel3 */

  TIM_SelectHallSensor(TIMx, ENABLE);

 

  TIM_SelectInputTrigger(TIMx, TIM_TS_TI1F_ED);

  TIM_SelectSlaveMode(TIMx,TIM_SlaveMode_Reset);

 

  /* Source of Update event is only counter overflow/underflow */

  TIM_UpdateRequestConfig(TIMx, TIM_UpdateSource_Regular);

...

With this setup, the counter is reset every time there's a rising or falling edge on each of the internally XORed H1,H2,H3 (TI1F_ED, which is the OR of TI1F_Rising and TI1F_Falling, is used as trigger input by the slave mode controller) and its last value is stored in the CCR1 (TRC is used to force a capture). Figure 77 - in the STM32 reference Manual (RM0008) - is explanatory.

About the prescaler, in the SDK's Hall sensor module, it's constantly adjusted in order to always have the best resolution. I invite you to have a look at the User Manual UM1052, figures 44, 45 and 46.

Best regards,

Dino

Any help?

so, my motor speed is 5000rpm what is the best config of PSC for timer not overflow?

// define timer clock

// between two changes on the hall sensor lines on the lowest rotation

// speed (eg. 1/100 from max. speed) the timer must not overflow

// define timer counter clock appropriate

// timer base configuration

// 126 => 3,5s till overflow ; 285,714kHz TimerClock [36MHz/Prescaler]

 TIM_TimeBaseStructure.

TIM_Prescaler

=

126

; TIM_TimeBaseStructure.

TIM_CounterMode

= TIM_CounterMode_Up; TIM_TimeBaseStructure.

TIM_Period

=

65535

; TIM_TimeBaseStructure.

TIM_ClockDivision

=

0

; TIM_TimeBaseStructure.

TIM_RepetitionCounter

=

0

; TIM_TimeBaseInit

(

TIM4, &TIM_TimeBaseStructure

)

; i not understand why 126

ivitro
Associate II
Posted on September 09, 2011 at 01:24

I download the FOC lib and install but not found the file with that code.

I appreciate

dino

King Regards

Vitor Soares

Dino COSTANZO
Associate II
Posted on September 12, 2011 at 09:26

Hello,

the source name is ''HALL_SpeednPosFdbkClass.c'' and it belongs to the MC library, a compiled layer in the SDK web distribution you have downloaded. Source code of this layer - with the exception of specific algorithms such as the sensorless state observer - is included in the SDK confidential distribution, free of charge and on demand by contacting your nearest ST sales office or support team.

Best regards,

Dino