Sampling Frequency for ADC in BLDC

Discussions regarding the Field Oriented Control (FOC) implementation on the VESC.
Posts: 2
Joined: 29 Sep 2017, 22:54
Location: Arizona

Sampling Frequency for ADC in BLDC

Postby vandammn » 29 Sep 2017, 23:00

Hi guys,

I am interested in knowing how fast we run mcpwm_adc_int_handler() for bldc mode commutation.


Posts: 1
Joined: 03 Jun 2017, 16:11
Location: France

Re: Sampling Frequency for ADC in BLDC

Postby Guillaume227 » 14 Dec 2017, 14:35

[Note: that question is miscategorized as it's about BLDC and it's posted in FOC subforum]

Here is my understanding from looking at the VESC code and at the f407 reference manual

There are two types of ADC conversion : injected and regular.
mcpwm_adc_int_handler is called at the end of the DMA transfer of the regular channel ADC conversion.

From mcpwm_init in mcpwm.c, we see the regular ADC conversion is triggered by Timer 8:

Code: Select all

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T8_CC1;

Timer 8 itself is a slave of Timer 1:

Code: Select all

   TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update);
   TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable);
   TIM_SelectInputTrigger(TIM8, TIM_TS_ITR0);
   TIM_SelectSlaveMode(TIM8, TIM_SlaveMode_Reset);

If we look higher up at Timer 1 setup:

Code: Select all

// Time Base configuration
   TIM_TimeBaseStructure.TIM_Prescaler = 0;
   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
   TIM_TimeBaseStructure.TIM_Period = SYSTEM_CORE_CLOCK / (int)switching_frequency_now;

It's got no prescaler and runs at a period of SYSTEM_CORE_CLOCK / switching_frequency_now Tim1 cycles.
So the frequency in Hz we recover is switching_frequency_now: the ADC runs at the same frequency as the PWM.
Switching frequency is in the range 3 kHz - 40 kHz.
That range can be set in the VESC tool.
During operation, the switching frequency is adjusted based on duty cycle as can be seen in set_duty_cycle_hw(float dutyCycle):

Code: Select all

switching_frequency_now = (float)conf->m_bldc_f_sw_min * (1.0 - fabsf(dutyCycle)) +
                conf->m_bldc_f_sw_max * fabsf(dutyCycle);

So it moves linearly between the two ends of that range when duty cycle varies from 0 to 100 pct.

Return to “FOC”

Who is online

Users browsing this forum: No registered users and 2 guests