Brushless DC Speed Controller

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
my submarine has been sitting in the garage collecting dust for a little too long so i decided it's time to get it back up and running i've replaced the trolling motors with brushless motors that i modified to run in salt water which should provide better efficiency and avoid the need for sealed casing but i've been having a hard time getting the commercial brushless speed controllers designed for rc models to cooperate with the control board on my sub even with the control board outputting the exact same pwm signal that an rc receiver would the escs either don't want to initialize or constantly reset i could solve this with enough debugging but i'd rather have control of the firmware on my esc so that i can tailor it to the submarine's needs so this was a good opportunity to build my own doing so would also make it much easier to debug or repair them when things go wrong so i drew up the schematic which is pretty close to a lot of the simple designs you'll find online once i get it working i'll be making some changes to suit my needs but before that let's talk about how a brushless motor actually works just like with an electromagnet we start with a ferrous core three sets of windings are made around the core for phase a b and c in this case i have four windings for phase but it can be any number the rotor consists of permanent magnets with alternating polarity typically the number of magnets is less than the number of windings so here i have 8 magnets and 12 windings total there's two different ways a three-phase motor can be connected either a y configuration or a delta configuration y provides more torque but a lower rpm and delta provides more rpm but a lower torque for this project i'm going to be using motors with y wiring so that's what i'll cover in a wide configuration all three windings share a common or neutral point at which they're all connected so current will always be flowing into one winding and out of another okay let's look at a complete phase sequence current will start by flowing into winding a for the sake of this demo let's say i wound the coils so that incoming current causes a north polarity current will exit through winding b which will cause a south polarity in this example the polarity of the coils will cause a repulsion at these points that pulls the rotor counterclockwise here too we get a counter-clockwise pull as the south pole coils repel the south pole magnets and attract the north pole magnets this will cause the rotor to turn until it reaches a stable equilibrium point where it'll want to stay but we want it to keep moving so we advance to the next phase by switching windings and having current exit through winding c this has caused the stable equilibrium point to advance counter-clockwise and the rotor will turn to follow it we advance the phase again and this time the incoming winding switches again the rotor advances to follow this pattern continues until we end up back where we began in this example we've moved 90 degrees in one cycle because there are four pairs of magnets or poles if there was only one pair we'd have completed a full rotation this is why you tend to see smaller faster motors having a small number of poles and larger higher torque motors having a large number of poles the circuit to drive the motor consists of three half bridges one for each winding set as we just saw with a white configuration current always flows in through one winding and out through another meaning that at any point during the cycle the high side mosfet of one half bridge will be on the low side switch of another half bridge will be on and the third half bridge will be completely shut off the mosfets cycle through the on off combinations we just saw in the previous animation a to b a to c b to c b to a c to a c to b and then back where we started at a to b this combination can also be reversed and it will make the motor turn backward okay let's look at that on a graph incoming current is a positive one outgoing current is a negative one and zero means nothing is happening and back to where we started i think by now we've pretty well established the switching order of the mosfets now i need something to switch them the arduino is my go-to microcontroller but we don't actually need to use the whole board all we need is the microcontroller on the board the atmega328 as you can see on my schematic from earlier the admega 328 pins control the mosfet drivers which in turn provide the pulses of current needed to quickly turn on the mosfet gates to control the windings to program an atmega328 by itself first you have to burn the bootloader this can be done with a separate arduino board using the connections shown here i took this diagram from a guide on the arduino website which is linked in the description below with your arduino plugged in open the ide and go to examples arduino isp and select the arduino isp sketch then upload it to your board now the app mega chip is programmable so i install it on my board the four pin header on the upper left corner will allow me to program the chip without removing it from the board using the connections shown here alright let's upload some code to test out the board make sure when you're uploading to a standalone appmega that you select atmega328 on a breadboard as your device and under programmer select arduino as isp next i wrote a simple test program to make sure the board works i set which pins i want as outputs to drive my bets and have a simple loop that switches on a pair of fets waits for a short time switches them off waits for a little longer then advances to the next state the mosfet on off states are contained in this function and it's exactly the same pattern as in the phase diagrams i showed earlier i uploaded the code to the app mega and added the mosfet driver chips then i powered everything up for a first test all right i got it spinning so the switching sequence is definitely working but right now this isn't useful for much because the esc has no way of knowing where the motor is in its rotation so it can't deliver current at the right time this is running entirely on open loop kind of like a stepper motor but with way less torque the best way to solve this would be with hall effect sensors spaced at specific intervals around the rotor based on the permanent magnet polarity combinations at the sensors the controller would know exactly which step of the cycle to energize the coils at and this is the exact reason electric vehicles like cars or go karts can deliver all their torque at zero rpm unfortunately my motors don't have hall effect sensors but there's another way for the controller to determine when to switch because the rotor contains moving magnets a voltage or back emf will be produced across the unpowered windings here i've got my brushless motor connected to a brushed motor running off my power supply so i can see what this back emf looks like on my oscilloscope in yellow is one of the phase voltages and in purple is the neutral point voltage which stays approximately constant by using a comparator to measure this voltage relative to the neutral point of the motor we can determine when a zero crossing occurs which indicates that it's time to switch in practice this is done with a resistor divider network to limit current and keep the voltage within the range of the microcontroller three comparators are used one for each phase and their outputs are sent to the controller i used an lm324 to do this because it has four op-amp comparators in one ic i wired the neutral point to the positive inputs and the phase voltages went to the negative inputs the output's changing state would indicate a zero crossing of the phase across the neutral point so here's what that looked like on my scope i'm probing the zero crossing outputs of face a and b and they're 120 degrees out of phase as i'd expect now i'd barely finished building the lm 324 circuit when i discovered that the admaka 328 has its own built-in comparator connected to digital pin 6 which has a multiplexer that can switch between six different analog inputs as a negative input better still its output can be used as a program interrupt on either a rising or falling edge of the comparator so this is ideal for a brushless controller and much simpler than adding a whole additional ic to my board at this point i had all the board hardware in place so i loaded some code onto the appmegachip to test out the driver i didn't write this code and i'm not much of a software guy so i won't get too deep into the detail of it but i'll just briefly go over what it does a link to the source is provided in the description this part establishes the input and output pins note that this is done by directly commanding the registers on the chip instead of using the pin mode command the next part sets up the timers that will be used for pwm throttle control and the analog comparator interrupt that'll be used to force the program to drop what it's doing and change the switch state when a zero crossing happens this is the subroutine that's executed when the comparator triggers an interrupt this loop debounces the comparator which is basically means it filters out any noise and jitter to get a clean transition then the program is commanded to switch state by calling the bldc move function the ldc move function turns on the mosfets based on which step of the cycle is passed to it it also defines which comparator transition to look for to advance to the next state notice that for each case the back emf signal corresponds to a phase that's not currently powered here's what the main loop of the program looks like if the controller is starting for the first time it executes this routine that gets the motor spinning in open loop mode and accelerates it until enough back emf can be generated to sustain a good signal for switching the next part just speeds up or slows down the motor gradually based on which throttle button is pressed these lines of code define which pins to use against the comparator to determine the zero crossing of different phases and here's where the rubber meets the road these are the switch states called in the bldc move function that actually command the output pins of the atmega high or low the register bits are commanded directly with these hex codes instead of using the digital write commands in order to maximize the speed the final bit of code is just some housekeeping that makes sure the pwm input to the motor doesn't go below zero or above 255. all right let's see that code in action [Music] [Music] seems to be working perfectly now i need to modify the circuit to run on a 24 volt battery system which is what my submarine uses to do this there's two changes i need to make first i need to give the fet drivers their own regulated voltage because they can only handle up to 20 volts second i need to change the resistors for the back emf signal so that all my signal voltages are under 5 volts even in a worst case scenario where my total battery voltage is about 28 volts at full charge i made those changes to my circuit and fired it up so it definitely shouldn't be doing that let's see what's wrong after doing some debugging i figured out that the inrush current was creating a big enough voltage spike to reset the atmega chip which is why you see it start up for a second stop and keep trying again unsuccessfully here's what the vcc pin of the appmegachip looks like on my scope this spike right here is the culprit when the motor starts up it shoots to about six and a half volts then immediately down to four volts which is resetting the microcontroller to fix this i added a bypass capacitor between vcc and ground as close as i could possibly get it to the pins of the chip this acts as a short circuit for ac noise to travel to ground and should flatten out that big voltage spike alright let's see how much difference that made there's still some noise but that nasty spike that reset the controller is gone and the motor starts spinning [Music] now i need to modify the code on my appmegachip so that i can reverse the rotation direction on the fly i do this by copying the bldc move function but reversing the order of the switch states i also need to swap the zero crossing directions on the back emf detection here's a side by side comparison of the two functions the switch state order is reversed and where there was previously a rising edge trigger for the back emf comparator now there's a falling edge trigger and vice versa all right let's try it out i'm going to start off by running counterclockwise and throttle all the way up and then down to make sure everything is working [Music] now i hit the reverse switch and restart the motor and just as planned this time it's going clockwise now let's give it a real test i'm going to remove these rc boat esc's and make my esc idle the big motors on my submarine uh [Music] [Music] [Applause] all in all seems to be working well the only thing that'll need some fine tuning is the open loop startup sequence but otherwise i'm very happy with this controller however this is just a prototype before my submarine goes into the atlantic ocean it'll need a pair of much bigger escs which i'll be building in an upcoming video thanks for watching
Info
Channel: Hyperspace Pirate
Views: 349,019
Rating: undefined out of 5
Keywords:
Id: F8l9Z1HGYcU
Channel Id: undefined
Length: 15min 11sec (911 seconds)
Published: Tue Nov 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.