Make your own ESC || BLDC Motor Driver (Part 1)

As you can see I am currently working on my DIY quadcopter project which I will probably finish in the year 2022. The heart of the system are those 4 brushless DC motors which through the help of the fitting propellers create the uplift necessary to let the quadcopter levitate.

I already talked about brushless DC motors, also known as BLDC motors, during a basics video of mine but I missed the chance to talk in detail about so called ESCs or electric speed controllers which directly connect in-between the three phases of the BLDC motors and the power source of the system. Simply put their job is to spin the rotor of the motor with an adjustable speed according to an input signal.

But while that is a rather dumbed down explanation of what they do their hardware construction and control software is everything but simple. So, I went ahead and created a first schematic for the project in which I not only connected the output and input pins of the IC but also added the complementary components for the bootstrapping, a potentiometer to adjust the rotation speed and 5 1ohm power resistors which will have an important function for the circuit later on.

Now because creating this circuit on a breadboard could turn out to be quite a hassle due to the high current flow I rather created the circuit on a piece of perfboard right from the start. And of course you can find more information about this project like all the schematics, the Arduino code and pictures of my layout design as always in the video description.

After 2 hours of soldering the first test circuit was complete and it was finally time to program the Arduino. As you can see I started off by creating 6 functions for the 6 steps in which I utilized the PORTB and PORTD register to pull the output of the Arduino connected to the L6234 IC High or Low.

It may look complicated but once you know that PORTD basically represents digital pin 0 to 7, PORTB represents pin 8 to 13 and a1 means pull the output high and 0 means pull the output low it is easy to understand. And the input logic of the IC is also well described in the datasheet, if the enable pin is pulled high, a low input activates the low side MOSFET while a high input activates the high side MOSFET.

And if the enable pin is low both MOSFETs are turned off. So, after completing the step functions I configured the timer 1 of the Arduino so that it creates a timer compare interrupt in a time interval between 80 and 1.6ms according to the position of the potentiometer. The point of this interrupt is to increase a counter variable called step which I used in the main loop to switch between the different step functions.

And of course, if the step counter reaches the value 6 it starts over at 0 and additionally I also added a do once flag so that the output registers do not get rewritten continuously. After uploading the code, hooking up the three phases of the motor and supplying a voltage of 12V to the circuit we can see that the motor tries to move but it seems like its stuck.

A first clue to why this is happening can be seen when we have a look at my power supply which reaches its current limit of 3A every half second. And if monitor the supply voltage with an oscilloscope we can see how the voltage collapses down to 4V which forces the Arduino to restart. Thankfully though, the problem we are facing here is easy to understand.

At first, The Arduino activates step 1 which lets current flow from Phase A to Phase C. As you might know coils have a very low resistance but on the other hand a relatively big inductance that means that the current through the coils will rise very fast and easily reaches our 3A current limit even within the shortest step duration that we set earlier.

So, what we have to do is to somehow cut off the current rise at a threshold value so that the current can decrease and then once again rise after a set wait time. And to find out how to implement this current chopping feature and how to improve our DIY ESC even more make sure to watch part 2 of this project series.

WEBVTTKind: captionsLanguage: enAs you can see I am currently working on myDIY quadcopter project which I will probablyfinish in the year 2022The heart of the system are those 4 brushlessdc motors which through the help of the fittingpropellers create the uplift necessary tolet the quadcopter levitateI already talked about brushless DC motorsaka BLDC motors during a basics video of minebut I missed the chance to talk in detailabout so called ESCs or electric speed controllerswhich directly connect in-between the threephases of the BLDC motors and the power sourceof the systemSimply put their job is to spin the rotorof the motor with an adjustable speed accordingto an input signalBut while that is a rather dumbed down explanationof what they do their hardware constructionand control software is everything but simpleSo in this 2 part video series let’s findout how such an ESC works and let’s tryto create our own consisting of an Arduinoand a couple of complementary componentsLet’s get started!First off, I hooked up three oscilloscopeprobes to the three phases of the motor andsent an input signal to the ESC so that itrotates relatively slowBy the way the input signal consists of asimple PWM signal with a frequency of 20msand an on time of 1 to 2 ms, while 1ms representsthe low speed and 2ms the high speedI created this signal by utilizing the timer1of the Arduino µCBut back to topic, the oscilloscope alreadyshows us that this will not be a simple projectbut if we think about the overall structureof a BLDC motor we might be able to understandthe voltage curvesNow a BLDC motor consist of three coils whichas we can see are distributed evenly and alsotied together in a common neutral point, whiletheir three phases which I will call A, Band C are led out of the motor as three wiresThis part is called the stator which obviouslystays in place while the rotor with its manyneodymium magnets surrounds the stator andis like the name suggest the part of the motorthat rotatesBut to keep the explanation easier later onI decreased the number of magnets in my illustrationto only 4Now the voltages we have been looking at sofar were the voltages between phase A/B, phaseB/C and phase C/AThose are called mesh voltages and usuallya bit harder to grasp since they include twocoil simultaneouslyIt would be easier for us if we could seethe voltage across each individual coil whichmeans we have to use the neutral point asa reference voltage but as I said earlieronly the three phases are led out of the motor,not the neutral pointSo, to solve this problem we could add a 10kohmresistor to each phase and solder them togetheron the other side to create a virtual neutralpointNow by checking the voltages while the motorrotates reveals still complicated lookingvoltage curves, but let’s have a closerlook at them step by stepFirst off Phase A Is pulled up to the supplyvoltage while Phase C is pulled down to GNDAfter pulsing this behavior for a couple oftimes which I will talk about in detail laterwe can see that there is a phase change whichmeans that now Phase B is pulled to the supplyvoltage while Phase C stays lowThis phase change process then repeated 4times, each time with different a phase pulledto the supply voltage and GND before the cyclestarted over againSo, what the ESC basically does is going through6 steps in which one of the three phases isconnected to the supply voltage and one toGNDThat means that in each step current flowsthrough two coils, each time with a differentdirection which thus creates a changing magneticfield which attracts the magnets of the rotorand therefore creates a complete 360 degreesrotation of the magnets in those six stepsBut if you have more magnets like we do itwill take a multiple of the six steps butthey will still stay the same, they will onlyrepeat themselves a couple of timesAnd of course, if we want to increase therotation speed of the motor the ESC simplydecreases the time for one step and thus increasesthe frequency of the rotationSo now that we know the theory, how does theESC actually connect the phases to their correspondingvoltage potential?By removing the shrinking tube of one of themwe can see the components that handle thisjob pretty close to the output of the ESCAccording to their datasheet they are N channelMOSFETs which are connected to the three phasesas three half bridgesThis way we can activate a high side one toconnect one phase to the supply voltage andactivate a low side one to connect one phaseto GND and thus create the 6 different statesfor the six stepsBut because we want to use N channel MOSFETsfor high side switching we would need a bootstrapconfiguration to do soThat is why I went with this L6234 three phasemotor driver IC since it combines the threeMOSFET half bridges and driver circuitry ina simple to use packageAll we need to do is to connect the motorphases to the output pins of the IC and connectits six inputs pins to the ArduinoSo, I went ahead and created a first schematicfor the project in which I not only connectedthe output and input pins of the IC but alsoadded the complementary components for thebootstrapping, a potentiometer to adjust therotation speed and 5 1ohm power resistorswhich will have an important function forthe circuit later onNow because creating this circuit on a breadboardcould turn out to be quite a hassle due tothe high current flow I rather created thecircuit on a piece of perfboard right fromthe startAnd of course you can find more informationabout this project like all the schematics,the Arduino code and pictures of my layoutdesign as always in the video descriptionAfter 2 hours of soldering the first testcircuit was complete and it was finally timeto program the ArduinoAs you can see I started off by creating 6functions for the 6 steps in which I utilizedthe PORTB and PORTD register to pull the outputsof the Arduino connected the L6234 IC Highor LowIt may look complicated but once you knowthat PORTD basically represents digital pin0 to 7, PORTB represents pin 8 to 13 and a1 means pull the output high and 0 means pullthe output low it is easy to understandAnd the input logic of the IC is also welldescribed in the datasheet, if the enablepin is pulled high, a low input activatesthe low side MOSFET while a high input activatesthe high side MOSFETAnd if the enable pin is low both MOSFETsare turned offSo, after completing the step functions Iconfigured the timer 1 of the Arduino so thatit creates a timer compare interrupt in atime interval between 80 and 1.6ms accordingto the position of the potentiometerThe point of this interrupt is to increasea counter variable called step which I usedin the main loop to switch between the differentstep functionsAnd of course, if the step counter reachesthe value 6 it starts over at 0 and additionallyI also added a doonce flag so that the outputregisters do not get rewritten continuouslyAfter uploading the code, hooking up the threephases of the motor and supplying a voltageof 12V to the circuit we can see that themotor tries to move but it seems like itsstuckA first clue to why this is happening canbe seen when we have a look at my power supplywhich reaches its current limit of 3A everyhalf secondAnd if monitor the supply voltage with anoscilloscope we can see how the voltage collapsesdown to 4V which forces the Arduino to restartBut thankfully though the problem we are facinghere is easy to understandAt first The Arduino activates step 1 whichlets current flow from Phase A to Phase CAs you might know coils have a very low resistancebut on the other hand a relatively big inductanceThat means that the current through the coilswill rise very fast and easily reaches our3A current limit even within the shorteststep duration that we set earlierSo, what we have to do is to somehow cut offthe current rise at a threshold value so thatthe current can decrease and then once againrise after a set wait timeAnd to find out how to implement this currentchopping feature and how to improve our DIYESC even more make sure to watch part 2 ofthis project seriesUntil then don’t forget to like, share andsubscribeStay creative and I will see you next time