Efficient control for BLDC 3-phase motor with BEMF using Arduino (Atmega328pb)

Thread Starter

Elazar

Joined Oct 29, 2019
49
Working on developing efficient code for driving a BLDC 3-phase motor with BEMF feedback using Atmega328pb,

The code is based (as a starting point) on this tutorial: Tutorial Link

The basic understanding is to increase the speed we need to increase the duty of the PWM's

However, the code I currently have works fine BUT is not efficient, (the motor uses much more current than other off the shelf controllers for the same speed)

Note: For this specific project, the main goal is to get a high speed (as the motor is used for an air pump or blower)

The code is simple,
  1. It uses a 6-step commutation to rotate the motor,
  2. It triggers a comparator interrupt to go from one step to the next step, (for every step the interrupt is different, see the code in the above link)

See the link Controlling Sensorless, BLDC Motors via Back EMF that explains how it works, and for this project, we use this configuration below:
cam.png

Important text from the Digikey tutorial from the link above:
Note that there is a phase difference between an individual Hall sensor changing output in a conventional BLDC motor, and the back EMF zero crossing point for an individual coil in a sensorless unit of 30 degrees. Consequently, in a sensorless motor control circuit, after the zero-crossing point is detected, a 30-degree phase lag is built into the firmware before the next action in the energizing sequence is activated

The question is:
How can we know exactly when to move to the next step, (maybe we can use timers, but the timers are used for controlling the PWM's)

In the tutorial code, it implements some form of delay in the ISR code that works somehow, but is very not efficient,

See code below:
Code:
// Analog comparator ISR
ISR (ANALOG_COMP_vect) {
  // BEMF debounce
  for(i = 0; i < 10; i++) {
    if(bldc_step & 1){
      if(!(ACSR & 0x20)) i -= 1;  //for falling interrupts
    }
    else {
      if((ACSR & 0x20))  i -= 1;  //for rising interrupts
    }
  }
  bldc_move(); //start the next step
  bldc_step++;
  bldc_step %= 6;
}
Basically, the code waits for some amount of clock cycles before moving further

The ACSR register bit 0x20 (32) just shows the state of the comparator, but I don't understand what it is trying to do, and how to make it more efficient?

I am trying to do something like this:

Code:
// Analog comparator ISR - at cross '0'
ISR (ANALOG_COMP_vect) {
  //check time in Timer0 TCNT0 register
  OCR0A = TCNT0; // + ((float)TCNT0 * 0.1);
  TCCR0A = 0;// set entire TCCR2A register to 0
  TCCR0B = 0;// same for TCCR2B
  //initialize counter value to 0
  TCNT0  = 0;
  // turn on CTC mode
  TCCR0A |= (1 << WGM01);
  // Set CS01 and CS00 bits for 64 prescaler
  TCCR0B |= (1 << CS02);// | (1 << CS00);
  // enable timer compare interrupt
  TIMSK0 |= (1 << OCIE0A);
}

ISR(TIMER0_COMPA_vect) {
  // disable timer compare interrupt
  TIMSK0 &= ~(0 << OCIE0A);
  bldc_move();
  // set Timer0 to normal mode (just count)
  TCCR0A &= ~(0 << WGM01);
  // Set CS01 and CS00 bits for 64 prescaler
  TCCR0B |= (1 << CS02);// | (1 << CS00);
  //reset counter value to 0
  TCNT0 = 0; //reset Timer0
}
Thank You.
 
Last edited:

MisterBill2

Joined Jan 23, 2018
18,176
Is this an educational project? Or some application? It is also possible to drive a BLDC motor in a synchronous manner by simply applying the excitation in that rotating sequence. In that mode the pulse width can also be set to provide the desired torque for each speed. Certainly the setup will take more effort butthe benefit is simpler hardware.
 

Thread Starter

Elazar

Joined Oct 29, 2019
49
Yes, you are correct,
However, without the feedback, the motor can (will eventually loose it's possition) get stuck, and there will be a lot of wasted current, (and power)

The EMF feedback is a must for efficient power and speed management,

There needs to be some delay (of 30 degrees, or half step) from the cross 0 interrupts until we can move to the next step,

The question is how to adjust this delay and power (PWM) in real-time to get best (current) power efficiency,

The main goal is to get a high speed for the lowest power possible (of cures without getting stuck)
 

MisterBill2

Joined Jan 23, 2018
18,176
OK, I do not usually run a motor that close to it's limits. For some applications reliability and stability is more important than maximum efficiency.
 

nsaspook

Joined Aug 27, 2009
13,086
Some background on BLDC motor control.
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3231115/
A BLDC motor is driven by voltage strokes coupled with the rotor position. These strokes must be properly applied to the active phases of the three-phase winding system so that the angle between the stator flux and the rotor flux is kept close to 90° to get the maximum generated torque.
3.1. Back-EMF Zero Crossing Detection method (Terminal Voltage Sensing)
The zero-crossing approach is one of the simplest methods of back-EMF sensing technique, and is based on detecting the instant at which the back-EMF in the unexcited phase crosses zero. This zero crossing triggers a timer, which may be as simple as an RC time constant, so that the next sequential inverter commutation occurs at the end to this timing interval [23].

For typical operation of a BLDC motor, the phase current and back-EMF should be aligned to generate constant torque. The current commutation point shown in Figure 9 can be estimated by the zero crossing point (ZCP) of back-EMFs and a 30° phase shift [1,4], using a six-step commutation scheme through a three-phase inverter for driving the BLDC motor. The conducting interval for each phase is 120 electrical degrees. Therefore, only two phases conduct current at any time, leaving the third phase floating. In order to produce maximum torque, the inverter should be commutated every 60° by detecting zero crossing of back-EMF on the floating coil of the motor [24], so that current is in phase with the back-EMF.
The back-emf zero cross works and is simple but it's not the most efficient way to drive the BLDC motor because we can't keep the the angle at 90 between rotor and stator flux continuously. Sensorless Field Oriented Control (FOC) of brushless motors is the modern way to drive motors because it gives instant to instant commutation control of the motor flux.

https://www.microchip.com/stellent/groups/SiteComm_sg/documents/Training_Tutorials/en532365.pdf
These are some advantages of Sensorless FOC for PMSM motors.
High efficiency is one of the top advantages of Field Oriented Control by aligning
rotor and stator flux in order to generate the most optimal torque production of the
motor.
No positions sensors are required in this algorithm since position and speed of the
motor are estimated based on currents and voltages. The implemented estimator will
be discuss in this web seminar.
Field oriented control improves dynamic response by adjusting both amplitude and
phase of the control signals fed back to the motor. Applications such direct drive
washing machines benefit with this advantage.
In Field oriented control, stator field is continuously updated based on the position
of the rotor field. By continuously pulling the rotor to a new position, the rotor is
always magnetized with a new vector, thus reducing torque ripple. Applications
where low speeds are required take advantage of this property of FOC.
Sinusoidal commutation accomplished with FOC, also reduces audible noise
produced by other types of control such as 6 step control.
Another advantage of FOC is enabling speeds above motor’s rated speed. This is
accomplished by energizing the stator windings at an angle where the rotor’s
magnetic field is weakened, and the resulting magnetic field vector composed by
stator’s field and rotor’s field is increased. Speed range can be increased
considerably by using field weakening or phase advance control
 
Last edited:

Thread Starter

Elazar

Joined Oct 29, 2019
49
Nsaspook Thanks for the detailed information,

I found this Arduino library https://github.com/simplefoc/Arduino-FOC that works with this method,
However, it does not support current sensing as feedback,

Is there any Arduino library that can do it?
or, is there any chip that can control a 3-phase BLDC motor with the POC method using back EMF current as feedback?

I found this chip: A4960 Datasheet but it looks like it works with the Back-EMF cross 0 methods?
 

nsaspook

Joined Aug 27, 2009
13,086
Nsaspook Thanks for the detailed information,

I found this Arduino library https://github.com/simplefoc/Arduino-FOC that works with this method,
However, it does not support current sensing as feedback,

Is there any Arduino library that can do it?
or, is there any chip that can control a 3-phase BLDC motor with the POC method using back EMF current as feedback?

I found this chip: A4960 Datasheet but it looks like it works with the Back-EMF cross 0 methods?
I think you mean it needs a position encoder sensor as current sensing is always needed for FOC control. As per the TI video it's possible to use back EMF to generate a position vector for field calculations but the transformations are extra overhead per interrupt that are eliminated by using a encoder.

Maybe this is the chip you mean: https://www.allegromicro.com/en/products/motor-drivers/bldc-drivers/amt49400
 

Thread Starter

Elazar

Joined Oct 29, 2019
49
I meant code that calculates the position from the back-EMF as I don't want to (can't) use an encoder

The amt49400 chip is amazing but I need a chip that works with external MOSFETs because of the high current > 2

Or code that does the same thing as the amt49400 chip

Thank You
 

MaxHeadRoom

Joined Jul 18, 2013
28,619
I have used BLDC extensively in CNC control, the quadrature encoders I use have a BLDC commutation tracks, if ordered separately to the motor, the motor pole count must be known.
Also without feedback, BLDC control exhibits distinct cogging at low RPM's.
 

nsaspook

Joined Aug 27, 2009
13,086
Sensorless FoC works well at high speeds but for low speed, high torque applications nothing works better than a high resolution position encoder. Sensorless FoC starts the motor in an open-loop sine-wave generation VF mode until back EMF is a reliable indicator of shaft position..
 

Rimbaldo

Joined Jun 6, 2016
32
Hi!! I know this is an old thread… but did you manage to fix your code regarding to the 30 degree phase lag when using backemf? Or did you change to the allegro a89301 ic?

Regards, Rimbaldo
 
Last edited:
Top