BLDC#1 ESC controller and BLDC motor Design for EV Applications

In this tutorial, we are going to look at the working principle of Brushless DC(BLDC) motor shown in figure-1. This tutorial concludes with the discussion of construction idea and the Electronic speed controller (ESC) design to run the motor. Everything from schematics and components to the final motor desing and working ESC will be updated here, so stay tuned.

    INTRODUCTION

    The recent trends in automotive industries about saving energy and reducing the pollution gives a new life to the design of Electric motors. Basic principle of a motor is to convert the electrical energy into mechanical energy by means of electromagnetic interaction between the rotor and the stator( as the names suggest, rotor is the rotating part in the motor while stator stays put). But when it comes to the use of a motor, one has to think about its size, power efficiency, speed control and price. Keeping these constraints in mind, BLDC motor as shown in figure-1

    Figure-1: BLDC motor

     surpassed most of the motors available in market. Moreover, unlike other motors BLDC motor speed can easily be controlled by cheaper electronic speed controller as shown in figure-2.

    Figure-2: ESC controller
    Brushless DC (Brushless Direct Current, BLDC) motor is a positive rapid spread of the motor type, it can be used in home appliances, automotive, aerospace, consumer goods, medical, industrial automation equipment and instrumentation industries. As the name points out, BLDC motors do not have brushes for commutation, but the use of electronic commutation. And brushed DC motors and induction motors compared to a BLDC motor, has many advantages. 
    These include:
    • Better speed - torque characteristics
    • Fast dynamic response
    • high efficiency
    • long lasting
    • noise-free operation
    • In addition the higher speed range,
    Since the motor output torque and a higher volume ratio, so that the need to focus on applications where space and weight are factors, are very useful.
    For more info on BLDC motor follow the link....

    TYPES OF BLDC MOTORS

    Here, we will cover the BLDC motor types commonly available in the market.

    APPLICATION OF BLDC MOTORS

    This sections is a motivation to the readers that why we going to dig into the basics of BLDC motors.

    COMPARISON

    WORKING PRINCIPAL

    DIFFERENT POSSIBLE ESC DESIGN SCENARIOS

    There are many ways to approach towards designing of ESC controller and some of those are as follows:

    1. ESC controller (link) with BLDC motor (link): This design has open source documentation available online, helps in designing own sensorless ESC controller and one can also get his hands dirty on the firmware development part. Remember this design is for 12V and can be extended to 48V by changing the back emf sensing circuit and buck converter circuit. Follow the links given below to get started.
      1. Electronoobs ESC playlist, for more information visit his website too.
    2. Sensored CD-ROM BLDC motor with DIY sensored ESC controller on electronoobs: this combination is going to help in understanding how the hall sensor encoder works and how to implement it in firmware. Moreover, it helps in designing the complete ESC for sensored BLDC motors.
      1. sensored BLDC control with arduino (link), this design can be extended to 48v.
      2. Electronoobs this design will not work beyond 15v.
    3. ST's X-NUCLEO-IHM11M1(datasheet) for 1.8 to 10v application/X-NUCLEO-IHM15A1 for 7 to 45v application/X-NUCLEO-IHM16M1 for 7 to 45v application expansion board with Nucleo-L476RG/F446RE board or with arduino uno R3 clone model board.
    4. SimpleFOCshield compatible with Arduino Uno R3 is an open source hardware and for it's software development simpleFOC library is also available at this link. This FOC shield uses L6234 driver that has builtin mosfets and this driver can work in the range of 7 to 52v. This simpleFOC shield can only work from 12 to 24 inputs but this voltage level can be extended by replacing the linear regulator.
      1. see simpleFOC powershield v2.0 using BTN8982 driver.
      2. from SimpleFOC website: Example using DRV8302 driver module with Arduino Uno for FOC control (for 4.4 to 45v applications).
      3. Example design of DRV8302 driver module from TI
      4. Sensorless design example of L6234 with arduino Uno and CD-ROM BLDC motor. It also has other links for designing arduino based ESC using IR2101 and IR2104 
      5. Components can be purchased here
        1. L6234
        2. INA240 current sense amplifier: used in simpleFOCshield V2.x
    5. Using above modules, Once the firmware and hardware is freezed, then IR2113/IR2110 (available in 14 PDIP and 16 pin SOIC package)driver can be used together with the arduino uno to control the sensorless/sensored BLDC motor.  
    6. Using STSPIN32F0 (datasheet) microcontroller with built in driver circuitry. ST Microelectronics provides evaluation board for this chip.
    7. Using DRV8302 (for 8 to 60v applications) with STM32F4 microcontrollers: this design is open source and from code to the hardware development almost everything is available at this link. Firmware for this project is developed using ChibiOS. So it will take some time to get the full grasp on this project.
      1. DRV8302 has builtin buck converter.
      2. Components can be purchased here
        1. DRV8302 
    8. Using MIC4605(for upto 85v application) driver with STM32F303 microcontroller: schematics, gerber files and firmware development guidelines can be found here. This project is besed on the one mentioned in point-7 but promises to be comparatively cheaper in cost. 
      1. This project designs XL7015 and ACT4088 based buck converter 
      2. Components can be purchased here
        1. MIC4605
    9. DRV8320S (for upto 60v application) driver with STM32L and STM32G series microcontrollers: documentation for this desing is available here, for more infor one can follow this blog.
      1. DRV8320S has builtin buck converter.
    10. LM5101 (for upto 100v application) driver with STM32F103C CORTEX M3 microcontroller: documentation for this desing is available here but the firmware development does'nt seem to be available.
      1. This project uses LT3470 SMPS IC for buck conversion
    11. IR2104 (8pin IC: for upto 600v applications) with Atmega88PA microconroller: documentaion, schematics and firmware development details are available here.
      1. Rating: 12V-36V@20A
      2. Current sensing: resistor drop method, no amplification.
      3. voltage sensing: resistor divider
      4. BKIN: NA
      5. Micro-controller: ATmega88PA micro-controller
      6. sensor support: NA
      7. control Algorithm: NK
      8. back emf sensing: Resistor divider
      9. power converter: single supply, TLE4267 (36 to 5V) linear regulator.
      10. Avilability: Robu
      11. References for further reading:
    12. A design based on point-7 but it promises to work at higher watt rating of 2kw to 3kw. Documentation for this project is available here but the schematics is not properly opened by kicad.
    13. IR2101(8pin IC: for upto 600v applications) with STM32F103 Blue pill dev board. This project uses XL7015 and MP2307 modules for power conversion. All the details about this project can be found here.
      1. Rating: 12V-36V@
      2. Current sensing: inline sense resistor and amplification by TSV994 automotive grade opamp.
      3. voltage sensing: resistor divider
      4. BKIN: hardware break based on current limits using LM339 opamp.
      5. Micro-controller: STM32F103 blue pill module
      6. sensor support: hall sensor, optical encoder
      7. control Algorithm: FOC
      8. back emf sensing: Resistor divider
      9. power converter: single supply, XL7015 buck module(36 to 12V) and MP2307 buck module(12 to 5v).
      10. Avilability: electronicsComponent, roboelements, TSV994 is NA
      11. References for further reading:
    14. IR2101(8pin IC: for upto 600v applications) with STM32F103 Blue pill dev board. This project uses LM1117-5.0 for power conversion. All the details about this project can be found here.
      1. Rating: 12V-72V@30A
      2. Current sensing: ACS712
      3. voltage sensing: resistor divider
      4. BKIN: hardware break based on current limits using LM339 opamp.
      5. Micro-controller: STM32F103 blue pill module
      6. sensor support: hall sensor
      7. control Algorithm: Trapezoidal, sinusoidal
      8. back emf sensing: NA
      9. power converter: Dual supply, LM1117-5.0 linear module(12 to 5v).
      10. Avilability: electronicsComponent, roboelements
      11. References for further reading:
    15. DRV8316 with ESP32 IC . This project uses LMR36506 for buck conversion. All the details about this project can be found here.
    16. L6234 based driver circuit only
      1. Rating: 12V-33V@30A
      2. Current sensing: TLV271 with sense resistor
      3. voltage sensing: resistor divider
      4. sensor support: hall sensor/encoder etc
      5. back emf sensing: resistor divider
      6. References for further reading:

    ESC DESIGN

    Before designing the hardware once must list out all the necessary interfacing required and hence i have presented a block diagram below 




    Interfacing Throttle with the ARM STM32F103(Blue pill)


    When you are making the ESC using 5V logic level microcontroller(like: ATmega328) then R works as the speed limit resistor, while, it works as logic level converter in series with the 10k resistor by making voltage divider circuit to maintain the compatibility with logic level of 3.3V.
    • NOTE: Some of possible throttle problem that may come during the ride 
    • if somehow throttle connector is disconnected, then the motor will not run, because path (from supply to green and GND) will not be complete and hence the green signal will be pulled to GND by the resistors. 
    • But if somehow GND wire is disconnected only then it is going to be a problem, and can be mitigated by monitoring the delta between the two throttle consecutive values read by the processor.
    • In case only green wire is removed, no problem
    • when wires are swapped, its a big problem depending upon the swapping order.

    Hall Sensor interfacing circuits

    As hall sensor feedback signals from motor is disturbed by the coils present in the motor winding, One has to clean that signal before feeding it to the micro-controller for proper motoring operation because these signals helps micro-controller in determining the next commutation state for the motor winding by decoding these hall sensor feedback signals. micro-controller first decodes the hall sensor signals and gets idea about the rotor exact position and then decides what phases are to be energized.

    There are many ways to filter the hall sensor feedback signal from the motor.

    Using 74HC14 Schmitt trigger and RC filter:

    RC filter itself has some noise after filtering the signal and that's why schmitt trigger circuit is used to avoid that noise.This method promises to be more precise in position sensing, although it is not the ideal solution.
    Thanks to avislab for this wonderful circuit. https://blog.avislab.com/category/brushlessmotors/#gallery-4

    Using RC filter for 5V logic level:

    Using RC filter for 3.3V logic level:

    MOSFET SELECTION

    While doing MOSFET selection, there are many parameters needed to be looked at, and those are as follows
    1. RdsON
    2. Vgs
    3. voltage rating
    4. current rating
    5. power rating
    6. current vs temperature behavior

    Example MOSFETs:

    1. NCE8290AC (82V, 90A, 7.5mohm, 20V, 170W)

    MOSFET DRIVER SELECTION

    While doing MOSFET driver selection, there are many parameters needed to be looked at, and those are as follows
    1. Max current driver can deliver at gate
    2. Deadtime and shoot-throught protection circuit in functional block diagram
    3. logic family it support
    4. voltage range it produces on gate terminal
    5. Does it has enable pin?
    6. package and number of pins

    DRIVER CIRCUIT DESIGN TESTING

    Some of the example boards are given below to drive 48V BLDC motor. As these boards are not final, many things are going to be changed in near futur and will be updated here accordingly.


    POWER CARD

    Test-1: power card test

    Use 48v Batt pack, Multimeter, 20pin connector wire, 2.54mm jumper.

    1. Check if the power card 20-pin port(main port) is connected to the test port
    2. Connect battery to power card.
    3. Turn ON key.
    4. Measure voltage at CL, BL, AL, AH, BH, CH, +5v and +48v with respect to GND (record it).
    5. if AL=BL=CL=+5v and AH=BH=CH=0v
    6. then its okay to move to the next test.
    7. Turn key OFF
    8. connect +48V and +5V of power card from main port to the Arduino/ARM control card baord.

    ARDUINO CONTROL CARD

    Test-2: 48V and 5V voltage test

    Use Multimeter

    1. Turn key ON
    2. Measure voltage at P12-48v/A2 pin (record it)
    3. Measure voltage at I2C OLED port pin +5v (record it)
    4. Turn key OFF

    Test-3: Break test

    Use Break, Multimeter

    1. Connect break at Arduino control card break port.
    2. Turn key ON
    3. press/release break and measure voltage at A1 pin(record it).
    4. Turn key OFF

    Test-4: Throttle test

    Use throttle, Multimeter

    1. Connect throttle at Arduino control card throttle port.
    2. Turn key ON
    3. Rotate throttle and measure min/max voltage at pin A0(record it).
    4. Turn key OFF 

    Test-5: Hall sensor test

    Use  Multimeter, arduino uno board, hall connect jumper wire compatible with motor and Hall sensor connector

    1. Connect arduino dev board with hall sensor wires using hall connect wires.
    2. connect arduino dev board to PC
    3. Burn motor simulation code into the arduino development board.
    4. Turn ON key
    5. Plug logic analyzer at 
      1. HY-CH0
      2. HG-CH1
      3. HB-CH2
    6. Run logic analyzer software and record waveform.
    7. If waveforms are okay then move to next point
    8. Plug logic analyzer at 
      1. A-CH0
      2. B-CH1
      3. C-CH2
    9. Run logic analyzer software and record waveform.
    10. If waveforms are okay then move to next point
    11. Plug logic analyzer at 
      1. AH-CH0
      2. AL-CH1
      3. BH-CH2
      4. BL-CH3
      5. CH-CH4
      6. CL-CH5
    12. Run logic analyzer software and record waveform.
    13. Turn key OFF.

    ARM CORTEX-M0 (STM32F0) CONTROL CARD

    F/R port 

    Use soldering station

    1. Short R and G of F/R port for forward rotation of motor

    Test-7: 48V and 5V and 3.3V voltage test

    Use Multimeter

    1. Turn key ON
    2. Measure voltage at P12-48v/A1 pin (record it)
    3. Measure voltage at pin +5v and 3.3v (record it)
    4. Turn key OFF

    Test-8: Break test

    Use Break, Multimeter

    1. Connect break at ARM control card break port.
    2. Turn key ON
    3. press/release break and measure voltage at A6 (hardware break) pin(record it).
    4. Turn key OFF

    Test-9: Throttle test

    Use throttle, Multimeter

    1. Connect throttle at ARM control card throttle port.
    2. Turn key ON
    3. Rotate throttle and measure min/max voltage at pin A0(record it).
    4. Turn key OFF 

    Test-10: Hall sensor test

    Use  Multimeter, arduino uno board, hall connect jumper wire compatible with Arduino Uno and hall sensor female connector, logic analyzer, PC(logic analyzer software, Arduino IDE, ST LINK STM utility).

    1. Connect Arduino Uno board with hall sensor wires using Male 6-pin hall connect wires.
      1. D7-Yellow
      2. D6-Green
      3. D5-Blue
      4. GND-Black
      5. left red wire floating.
    2. connect Arduino Uno board to PC
    3. Burn motor simulation code into the Arduino Uno board.
      Hall Sensor simulated signal using Arduino Uno

    4. Connect 6pin Male connector from Arduino to Female 6pin from ARM control card.
    5. Plug logic analyzer at 
      1. YHS-CH0
      2. GHS-CH1
      3. BHS-CH2
      4. GND-GND
    6. Connect logic analyzer to PC.
    7. Turn ON key
    8. Run logic analyzer software and record waveform.
    9. If waveforms are okay and matches to given below waveform then move to next step.

    10. Turn OFF key
    11. Plug logic analyzer at 
      1. AH-CH0
      2. AL-CH1
      3. BH-CH2
      4. BL-CH3
      5. CH-CH4
      6. CL-CH5
    12. Turn ON key
    13. Run logic analyzer software and record waveform.
    14. Turn key OFF.
    15. All tested okay? waveform matches to the given below waveform then move to the next step.

    16. Let the logic analyzer connector as it is.
    17. Turn OFF key, Remove Batter supply, remove 48, 5v, GND jumper form ARM to power card.
    18. Remove 20pin connector from power card test port and connect it to the ARM control card.

    Motor Equations

    Processor selection

    While selecting a processor for motoring applications, there is a parameter that plays vital role and i.e. the commutation frequency (how many times motor's hall sensors change their state in one second when the motor is running). Within every commutation period processor has to be fast enough to process signals for six switches and three hall sensors.

    fe = Nm*S/120

    Where, Nm=no of permanent magnets, S=mechanical RPM of the running motor, fe=commutation frequency

     Magnetic field theory

    1. A current carrying wire produces a magnetic field in the area around it.
    1. A time changing magnetic field induces a voltage in a coil of wire if it passes through that coil.->(used in transformer)
    1. A current carrying wire in the presence of magnetic field has a force induced on it.->(used in motor: BIL)
    1. A moving wire in presence of magnetic field has a voltage induced on it.->(used in generator: BLV)

    Back EMF

    let say a motor has outer radius Rro, stack length Lst, no of turns N, no of coils in series Nm and air gap flux density Bg is rotating at a speed of wm. According to last faraday law as mentioned above, Back EMF is generated and given by the following formula,

    Eb = BLV = (Bg)*(2*Nm*N*Lst)*(Rro*wm) = ke*wm............................(1)

    Where ke=back emf constant

    Energy conservation

    let say current drawn by the motor at speed of wm is i and the produced torque is T then output mechanical power = Eb*i = T*wm .......................................(2)

    Torque: 

    Torque is given by using the equation 1 and 2.

    T = BIL*R = (Bg)*(i)*(2*Nm*N*Lst)*Rro = Kt*i

    Current

    Let’s assume that the supply voltage is Vdc, current flowing to the motor is i, back emf generated is Eb per phase, voltage drop across one MOS switch is Vd, resistance of coil is R per phase. Then i can be calculated as

    i = (Vdc-2Eb-2Vd)/2R

    Starting current

    At the time of starting there is no physical rotation in the motor and hence the back emf will be zero.

    Ist = (Vdc-2Vd)/2R

    Maximum speed

    As the motor speed increases the back emf also increases, and hence, back emf can get up to maximum of Vdc-2Vd, it cannot go beyond this voltage else motor will work as a generator. The speed, at which the back emf is equal to Vdc-2Vd, is called as the maximum speed and can be calculated using equation 1

    wmMAX = (Vdc-2Vd)/Ke

    Current at maximum speed will ideally be zero.

    Motor Winding Procedure

    Angular slot pitch

    let say we have a motor with Ns number of slots on the stator and Nm number of permanent magnets in the rotor, and we need to do its winding. While winding the motor we need to make sure that the three phases of the motor should be at 120 degree phase shift. While winding we measure everything in terms of number of slots. Hence, to achieve the 120 degree shift in three phase we need to shift one phase's winding from the other by some slots, and the number of slots needed to be shifted in order to to get the 120 degree phase shift between the phase is known as angular slot pitch. Angular slot pitch ko is calculated as 

    rem((3Nm/2Ns)*ko, 3) = 1                  where least possible value of ko will be the solution.

    example-1: Nm=4, Ns=12 find the angular slot pitch k0

    rem((3*4/2*12)*ko, 3) = 1 => rem(ko/2, 3) = 1 => ko(min) = 2

    Meaning: 

    1. if phase-A winding starts with the slot-1 then,
    2. phase-B winding will start at slot-3 and,
    3. phase-C winding will start at slot-5.

    example-2: Nm=4, Ns=15 find ko

    rem(12ko/30, 3) = 1 =>rem(2ko/5, 3) = 1 => ko(min) = 10

    Meaning:

    1. if phase-A winding starts at slot-1 then,
    2. phase-B winding will start at slot-11 and,
    3. phase-C winding will start at slot-21, but slot 21 is not present hence rem(21,Ns)=6. Now phase-C will start at slot-6.

    example-3: Ns=18, Nm=20 find ko

    rem(60ko/36, 3) = 1 => rem(5ko/3, 3) = 1 => ko(min) = 6

    Meaning:

    1. if phase-A starts at slot-1 then,
    2. phase-B will start at slot-7 and
    3. phase-C will start at slot-13

    Nominal coil span

    Now, we need to find out that if the wire goes into a slot then after how many slots it will come out. i mean when the coils are formed then how many slots will come under one coil, that we need to find out another parameter nominal coil span s* and that can be calculated as 

    s* = max(fix(Ns/Nm), 1)

    example-1: Nm=4, Ns=15 find s*

    s* = max(fix(15/4), 1) = max(fix(3.75), 1) = max(3,1) = 3

    Meaning: while doing winding if wire goes in slot-1 then it will be coming out from slot-4 to make a coil.

    example-2: Nm=20, Ns=18 find s*

    s* = max(fix(18/20),1) = max(0,1) = 1

    Meaning: while winding if wire goes in slot-1 then it will be coming out from slot-4 to make a coil.

    Relative angle

    while winding a motor it is a big challenge to decide whether a coil will be formed  by moving anticlockwise or clockwise from once slot to the other. In order to avoid this problem relative angle comes into picture and can be calculated as

    thetac(k) = (k-1) * Nm/Ns * 180 degree electrical             where k = slot number

    using thetac(k) and s* formula below table is created for Ns=15 and Nm=4 motor.

    remeber that s* was 3 for this chosen motor.

    Relative angles

    Angle corresponding to the coil number or slot number is going beyond +180 and -180 and hence principle angle is calculated using the following formula

    theta = rem(theta+180, 360)-180                remember all the angles are in degrees.
    Principle angle


    Now for the coils having angle magnitude greater than 90 degrees, interchange their in out direction and reverse their angle by 180 degrees by subtracting 180 degrees to the angle. See table below
    Final table

    There are total of 15 slots and 3 phases. Hence per phase there will be 5 slots or 5 coils. In order to choose the 5 coil for a phase we need to pick up the least five angle's magnitude that adds up to zero. if we look at the angles corresponding to the coil number 1, 5, 8, 9, 12, they have the lower 5 possible magnitude and their sum (0+24+12-12-24) is also zero. Hence 5 coils for phase-A are 1, 5, 8, 9, 12 with their corresponding in-out from the table are shown in the table below. 
    Phase-A coils and their in-out

    As we know that the ko=10 for this motor. Hence phase-B and Phase-C winding will be at 10 slots of shift from each other. Final table for Nm=4 and Ns=15 is shown below.


    250W BLDC Hub motor

    In order to calculate these pattern, hall sensor postions, and wire gauge for different speed and torque variations use the below MATLAB code from github account name: masifamu

    Running the code for Ns=18, Nm=20

    1. Enter the no of stator slots: 18
    2. Enter the no of permanent magnets: 20
    3. Motor winding pattern [slot(in->out)]
    4. PHASE-A slots----> 1(1->2)  2(3->2)  9(10->9)  10(10->11)  11(12->11)  18(1->18)  
    5. PHASE-B slots----> 7(7->8)  8(9->8)  15(16->15)  16(16->17)  17(18->17)  6(7->6)  
    6. PHASE-C slots----> 13(13->14)  14(15->14)  3(4->3)  4(4->5)  5(6->5)  12(13->12)  
    7. no of slots between hall sensors is 3

    Running agian for Ns=48, Nm=52

    1. Enter the no of stator slots: 48
    2. Enter the no of permanent magnets: 52
    3. Mulitple slot combinations for a phase exists
    4. Motor winding pattern [slot(in->out)]
    5. PHASE-A slots----> 1(1->2)  2(3->2)  11(12->11)  12(12->13)  13(14->13)  14(14->15)  23(23->24)  24(25->24)  25(25->26)  26(27->26)  35(36->35)  36(36->37)  37(38->37)  38(38->39)  47(47->48)  48(1->48)  
    6. PHASE-B slots----> 9(9->10)  10(11->10)  19(20->19)  20(20->21)  21(22->21)  22(22->23)  31(31->32)  32(33->32)  33(33->34)  34(35->34)  43(44->43)  44(44->45)  45(46->45)  46(46->47)  7(7->8)  8(9->8)  
    7. PHASE-C slots----> 17(17->18)  18(19->18)  27(28->27)  28(28->29)  29(30->29)  30(30->31)  39(39->40)  40(41->40)  41(41->42)  42(43->42)  3(4->3)  4(4->5)  5(6->5)  6(6->7)  15(15->16)  16(17->16)  
    8. no of slots between hall sensors is 3

    Running agian for Ns=36, Nm=40

    1. Enter the no of stator slots: 36
    2. Enter the no of permanent magnets: 40
    3. Motor winding pattern [slot(in->out)]
    4. PHASE-A slots----> 1(1->2)  2(3->2)  9(10->9)  10(10->11)  11(12->11)  18(19->18)  19(19->20)  20(21->20)  27(28->27)  28(28->29)  29(30->29)  36(1->36)  
    5. PHASE-B slots----> 7(7->8)  8(9->8)  15(16->15)  16(16->17)  17(18->17)  24(25->24)  25(25->26)  26(27->26)  33(34->33)  34(34->35)  35(36->35)  6(7->6)  
    6. PHASE-C slots----> 13(13->14)  14(15->14)  21(22->21)  22(22->23)  23(24->23)  30(31->30)  31(31->32)  32(33->32)  3(4->3)  4(4->5)  5(6->5)  12(13->12)  
    7. no of slots between hall sensors is 3

    Running agian for Ns=27, Nm=30

    1. Enter the no of stator slots: 27
    2. Enter the no of permanent magnets: 30
    3. Motor winding pattern [slot(in->out)]
    4. PHASE-A slots----> 1(1->2)  2(3->2)  9(10->9)  10(10->11)  11(12->11)  18(19->18)  19(19->20)  20(21->20)  27(1->27)  
    5. PHASE-B slots----> 7(7->8)  8(9->8)  15(16->15)  16(16->17)  17(18->17)  24(25->24)  25(25->26)  26(27->26)  6(7->6)  
    6. PHASE-C slots----> 13(13->14)  14(15->14)  21(22->21)  22(22->23)  23(24->23)  3(4->3)  4(4->5)  5(6->5)  12(13->12)  
    7. no of slots between hall sensors is 3
    If you want to go deeper into these winding concepts and want to simulate its magnetic properties with FEMM and Lua scripting language, i would recommend you should visit the link

    Permanent magnet placement on Rotor

    Once winding is done on the stator, now it's time to look at how to place the permanent magnet. Placing permanent magnet is bit challenging and it's dependent on rotor radius and magnet size. Instead of going through this challenging task manually, here is a link form GB (Go Brushless) that do this for you within no time. You need to input some parameter and it will tell you the gap between the two magnets on the rotor numerically and graphically.

    Component Selection

    I will be using ARM cortex M0 processor from STMicroelectronics named as STM32F030K6T6.

    Processor selection

    When it comes to the processor selection for a BLDC motor, one must know what are parameters that decides the processor. When a BLDC motor runs, its switches are commutated by using a subroutine that is called at every hall sensor trigger(Hall sensors are used for the rotor position sensing). It  is important to note that before calling the subroutine for the next rotor position the subroutine execution must be completed for the present rotor position. Hence, a fast a processor can process this subroutine, selects the processor. I have discussed a formula that gives the information about, within what time the processor must process the subroutine.

    let say the rotor is running at the RPM of S, and the number of magnets in the rotor is Nm. Then the  frequency at which the subroutine will be called is given by the formula

    Fe=(Nm/120)*S

    and 1/Fe gives the time to process the subroutine.

    For example, S=400, Nm=20

    Fe=(20/120)*400=66.667 Hz

    1/Fe=0.0145 seconds= 14.5 ms

    Let say you have motor with Gear ratio 1:4.47

    then 14.5ms/4.47 = 3.35ms

    Hence, while coding, you should update the PWM width every 1ms so that the PWM width should be updated at each commutation.

    A bit of theory on motor control

    I will use STM32CubeMx for initial code generation and rest of the code will be written using KeilV5.

    In order to control the six switches of Inverter stage preset in the ESC controller, the processor should be capable of generating six PWM signals simultaneously. PWM signals are used to vary the applied voltage to the motor by varying the pulse width of the PWM signal, however, by changing the PWM period, frequency variation can also be achieved. As these two parameters plays a vital role in controlling the speed of a motor hence called as V/F control.

    Now we will be talking about how the PWM is implemented in ARM processors and how to achieve the variable voltage using the PWM technique.

    Motor Hall Sensor Feedback Signal Simulation

    The purpose of making this simulation is to investigate different signals to the motor, without even connecting the actual motor. Here, connect the LED circuit to the three phases of the motor.

    Now, we will be able to generate the same hall sensor signals using the below code, although the motor will not rotate as the phase wires are connected to the LEDs circuit.

    BLDC Motor Hall Sensor simulator code

    #define hallSensorCuts  266  //default is 266
    uint8_t delay_time=255;
    uint8_t RPM=10;//100 rpm gives 2.25ms of time between two hall sensor trigger.
    void setup() {
      delay_time = (uint8_t)((1000*60)/((uint16_t)RPM*hallSensorCuts));
      //Serial.begin(9600);
      //Serial.println(delay_time);
      DDRD |= 0b11100000; //setting pin 7(Y), 6(G), 5(B) as output without effecting the others
      PORTD &= 0b00111111;//starting from 001 pattern
      PORTD |= 0b00100000; 
    }
    void loop() {
      PORTD |=0b01000000;//now set green
      delay(delay_time);
      PORTD &=0b11011111;//reset blue
      delay(delay_time);
      PORTD |=0b10000000;//set yellow
      delay(delay_time);
      PORTD &=0b10111111;//reset green
      delay(delay_time);
      PORTD |=0b00100000;//set blue
      delay(delay_time);
      PORTD &=0b01111111;//reset yellow
      delay(delay_time);
    }

    BLDC Motor Hall Sensor Placement

    Now, its time to talk about the hall sensor placement for 120 degree phase shift ESC controllers. A method is discussed here that assumes: hall sensor is to be placed on the stator of the motor.

    x = mechanical degree per slot
    m = mechanical degree per 120 degree electrical
    pp = permanent magnet pole pair
    s = number of slot

    x = 360/s
    m = 360/pp mechanical degree per 360 degree electrical = 120/pp mechanical degree per 120 degree electrical.

    number of slots between two hall sensor = (m*i/x) 
    i: any positive integer that converts the above expression into whole number.

    Example:

    18S20P motor

    pp=10,s=18
    x=360/s=360/18=20
    m=120/pp=120/10=12

    number of slots between two hall sensor = (m*i/x) = 12*i/20 = 3*i/5
    i = 5 reduces the above expression to 3, and hence 3 will be the number of slots between two hall sensors.

    48S52P motor

    pp=26,s=48
    x=360/48 = 15/2
    m=120/26 = 60/13

    number of slots between two hall sensor = (m*i/x) = 60/13 * i *2/15 = 8*i/13
    i=13 reduces the above expression to 8, and hence 8 will be the number of slots between two hall sensors.

    36S32P motor

    pp = 16, s = 36
    x = 360/36 = 10
    m = 120/16 = 15/2

    number of slots between two hall sensor = (m*i/x) = 15/2*i/10 = 15*i/20 = 3*i/4
    i = 4 reduces the above expression to 3, and hence 3 will be the number of slots between two hall sensors.

    Hall sensor test code

    uint8_t a=0;
    uint16_t count=0;
    void pciSetup(byte pin)
    {
        *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
        PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
        PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
    }
    
    ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here
     {    
        a=PINB & 0b00000111;
        count++;
        // put your main code here, to run repeatedly:
      Serial.print(a);Serial.print(" :");
      Serial.println(count);
     }
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      pinMode(8, INPUT_PULLUP);
      pinMode(9, INPUT_PULLUP);
      pinMode(10, INPUT_PULLUP);
      pciSetup(8);//B
      pciSetup(9);//G
      pciSetup(10);//Y
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      //Serial.print(a);Serial.print(" :");
      //Serial.println(count);
    }
    Connect Arduino board to PC and burn this code into Arduino development board. Now connect hall sensor Y from motor to D10 of Arduino board, G to D9 and B to D8. Remember there must be a low pass filter circuit between the hall sensor and Arduino board.

      • Test-1: Open serial monitor in Arduino IDE, rotate motor manually and check the pattern on the serial monitor. Hall sensor pattern being printed on serial monitor must be 1,3,2,5,4,6. If this is not the pattern on the serial monitor then there is some problem in hall sensor position.
      • Test-2: reset the Arduino board and clear the serial monitor window as well and now rotate the motor 360 degree manually and see how many count is there on serial monitor. The total number of count must of equal to 3*pole for non geared motor and 3*pole*gearRatio for geared motor.

    Comments