Let's Make Robots!

BLDC motor controlling, the hard way

I am going through two processes now...

The first, is removing the spider webs from electronics capabilities of yesterday ; The second, is (during this process) controlling an HDD 3-phase BLDC motor with arduino.

Yes, I know I can simply use an ESC component and save myself the hassle of "figuring it all out", simply plugging in the speed controller to the motor 3 pins, 12V battery and simple signal from my microcontroller (arduino) to set the speed/direction .. and voilla. That's it.

BUT..where's the fun in that??

For the sake of learning the fine details of how a the phased motor is controlled, I rather "do it all" myself. Just rely on my Arduino for feeding the 3 phase lines through three PWM outputs with extra three digital outputs for indicating a "not connected" state (so to have 3 states: +,-,NC),, fed into 6 sets of gate drives and possibly going through another layer of driver... etc..

Basically, I am following http://www.jimfranklin.info/microchipdatasheets/00857a.pdf (see diagrams on pages 29, 30)

So from what I understand.. and I would LOVE your help in knowing where my below description is off:

1. each of the three phase lines (dubbed A, B and C) should be connected in one of three states: VCC, GND, NC ... Those states are set according to a 6 options, creating an always switching flow trough two coils in one direction of the other - info can be seen here: http://bldc.wikidot.com/p-esc-motor

2. cycles should be timed according to the position of the motor, which is referred to sensor enabled control that can be based on hall sensors.. OR can be based on back EMF.

BUT can also be sensorless, by just ignoring things and timing according to a certain preset you set for a desired speed. (less optimal, but should work quite well, especially with some tunning) 

3. The speed of the motor, and the torque will be set according to the voltage you feed as well as the timing/frequency of the cycle. Torque is also influenced by the right timing of the state switch.

4. protect the microcontroller by not having it connected directly to the motor, in any way or form. protect things from returning currents from the motor (as motors are "noisy")

Basically, that's it. Now, how is that done? Using which components? For this, I will describe my understanding of the digram in the referred PDF..

Again, corrections are highly appreciated, and actually sought after..

a. The 3 states generation: I have two options. I think..

a.1 : In this Here I am following the diagram on the PDF ::: My microcontroller will generate 3 voltages via PWM, as well as 3 high/low signals allowing switching between GND and NC. overall 6 signals. each pair controls a state of one of the 3 phase pins of the motor. The PWM will range between 255 (5V) and 0 (0V, which is equivalent to NC, depending on the electrical circuit). The second line will be used to basically control the switching between the NC state and GND(-) state. By using two gates (in this case: IRF5305 and IRLI3705, as described in figure B-1 on page 29), I can have a phase line connected either to ground or to the the voltage. Using PWM, that voltage is "basically" variable, ranging between my 12V and 0V. However, in this solution I am not sure why I need the TC4469, and not rely only on the IRF5305 and IRLI3705 gates only? Anyone has any idea? aren;t the gates alone, enough to isolate an arduino from the motor and 12V? Can't they be fed directly by C1,C4?

a.2. Instead of this, I can follow a different guide instead (see soon)  ::: I can use a L6234, connect all 6 arduino outputs described above, and skip the need for the TC4469, IRF5305 and IRLI3705, as its all included inside the IC. Right? Though, both where is the fun in that AND its hard (for me) to find L6234. Reading up on it, its basically a triple half-bridge driver. Right? SO, I COULD instead use any other triple half-H or even three seperate half-H ICs. Right??  [http://www.instructables.com/id/BLDC-Motor-Control-with-Arduino-salvaged-HD-motor/step8/The-Power-Electronics/]

How is a.2 different than a.1? Which approach is better? Which approach would isolate my arduino better? and ACTUALLY what is the point, at all, in these TC4469?

b. The positioning of the different capacitors is to protect the circuit from the engine's feedback. Right? When looking at the digram on page 29, I am left with 3 questions:

b.1. Why is the capacitor setup at the top-right of the diagram (where R19 and C6 are located) exist only on the A line? why not on B and C?

b.2. what is exactly that "floating" bit on the middle left, where C1 is connected from the 12V power to GND directly? Why is it not connected to the rest of the diagram? Or is it actually connected, only not specifically indicated as part of the rest of the diagram, since its basically just an "AC protection" of the ENTIRE 12V feed?

b.3. The three resistors R7,R8 and R9 are said (according to note (3)) to be there for controlling the rise/fall of the driver. Here, i'm assuming its for converting a square wave of the phased feeds to something more trapezoid like. However, I can't see how just a resistor would actualy modify the votage in such a way. I would expect that to happen because of a capacitor setup. Not because of a resistor. What am I missing?

 

 

Lastly, I want to sneak in another question I have very hard time finding a good answer for...

How can I find what OTHER components might replace an existing component in a given diagram.

For example, in the diagram I linked to and referred to, there are the MOSFET gates: IRF5305 and IRLI3705. However, if my local electronic store does not carry them.. how can I tell which OTHER equivalent components exist which I might use instead? (and how do I know what implications such a switch may have?).. for example, in case of capacitors (in DC digrams), it is almost always fine to replace a capacitor with a different one of higher capacity. Very rarely there is a potential disadvantage or negative implications to it. However, while its easy to do that, as most capacitors are basically 'the same", a specific IC like IRF5305 or IRLI3705 is (at least for me) totally not the same as all others. I am not even sure if IRLI3705 can be replaced by IRLI3705N....

 So how do I tell?

Would greatly appreciate any feedback, and would love to post updates about the progress of my process.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

So.. Update

I didnt get yet the individual components, to build my own half-H.. But I got a 4 channel DC motor driver. Its Full-H, but I figured that as long as I have Enable per motor, Full-H can be simply used as Half-H, if I just use one terminal of the bridge. 

So I indeed plugged the arduino to the driver, used 3 of the 4 channels, wrote a little Arduino sketch cycling through the 6 states, plugged the three outputs (though only the first "pin" of each) to the three coils on the HDD, and.. what do you know.. the motor turns.

Depending on the delay between the states, different speeds are reached, Also, for now I control the voltage via the power supply. Its effect is how jerly the movement of tyhe motor is on very low RPM and to some degree how strong (and less-so, fast) the rotation is.

So, the theory employed successfully. a very basic ESC using Full-H in a Half-H configuration with arduino. I still plan to build my own Half-H using MOSFETS though.. I'm not chickening out of this one.

AND for now its a sensorless ESC.. so can't really trust on a good motion, because the change between states it TOTALLY no based on the position of the motor, as it actually should do. For this, I have to measure the back EMF.. but I can't really do that until: a) I get my oscilloscope to be able to "see" what I get on the a common leg. b) I pipe the output of this leg through a comparator and schmitt trigger and feed it into the arduino (probably using interrupt), to be able to control proper timing of phase switching.

I did get into some problem. I can't really get the motor to get to real HDD speeds.. like 5400RPM or 7200 or whatever the HDD is supposed to be able to operate at. I can't really tell why yet. The phases are properly set, as far as I can tell. And I've trued it with different voltages.. what I don't really know is what is the right interval to switch the phases at. The delay is a key component here. 

I have to keep on digging. Any advices?

Glad to hear you were successful.  

I have a few ideas that might help.  First, you can use the ADC on the Arduino to read the back EMF.  The ADC on the Arduino is capable of taking over 10000 readings a second, but I don't know how well that is supported by the Arduino libraries.  If you can read any where near that fast it should be good enough to see the voltages and waveforms.  No scope needed.  I don't know when the best switching times are, but I think the App Note you listed mentions this.  

Second, to get full speed, you will probably need to accelerate up to it, changing your switching speed.  You will probably also need to apply near full voltage (probably 12 V for a HDD motor) to get full speed, but you should use lower voltage as you accelerate.  Raise the voltage with the speed.  You can create a variable power supply with the Arduino by using a PWM output feeding into a large pass transistor to provide enough current.

Third, the motor may have more "poles" than windings.  Just like a stepper motor with 4 windings might have 48 or more steps.  The BLDC motor works the same way.  In that case, you have to apply a complete phase sequence more than once (2,3, or more times) to get one revolution.  If the motor speed is consistently 1/2 or 1/3 or 1/4 etc the speed you expect, that is most likely the problem.

Good Luck!

I am also currently working on a project where I want to control a 3 phase brushless motor from an Arduino controller. Have a look at this site here: http://en.nanotec.com/steppermotor_animation.html

It has some great animations for brushless motors that show basic schematics, pin states, etc.

Remember that depending on what timer is controlling your PWM pin, the frequency may be different. On standard Arduinos pins 5 & 6 have a 1KHz PWM frequency while pins 3,9,10 & 11 have a 500KHz frequency.

It will help if you are PWM your pins all at the same frequency. As some libraries and commands such as tone() use timer 2 it may be better if you use an Arduino Mega or compatible controller. This will give you 3 extra timers and 8 extra PWM pins to work with.

Brilliant find!

Very nice animation and demonstration of what is hapenning as the motor turns. Indeed it confirms I got it right.. and also shows why/how PWM is used to control the speed (although the part that is not fully demonstrated there is how the voltage and frequency of the cycles related to eachother).

I indeed use the Mega 2560 r3. However, important note I can share with you is.. you can contro.l the PWM frequency/cycle on an arduino! Have a look here :D http://playground.arduino.cc/Main/TimerPWMCheatsheet

Since for a 3 phase BLDC you need 3 signals, you just use pins 9, 10 and 11.. and set the freq of timer1 and 2 to 31250. Both timers support it.

There are a couple more things I meant to mention but forgot.  All the +12V symbols are connected together and all the GND symbols are connected together.  So that means your "floating" capacitor is actually connected across the power supply to filter the entire circuit.  Drawing it this way is just to remove clutter.  Also, another reason for slowing down the on and off times is to prevent "shoot through."  that is when the transistors don't turn on and off fast enough and they both end up on at the same time.That will cause a near short and large current spikes.  One last thing I didn't fully consider before.  If you don't use PWM at first, you need to use a low voltage.  The starting current of the motor can be quite large.  A low voltage combined with the internal resistance lessens that startup current.

in the application note.  That appears to be a very good app note, typical of Microchip.  I suspect that reading and re reading that app note until you understand all of it would make you more knowlegable than most engineers about motors and motor control circuits.  What I found there will help answer some of your questions.  I'm no expert on motor control, but I think I can answer most of your questions.

First, I see what you are talking about with the PWM now.  Yes, that is a good way to get better control, but shouldn't be strictly necessary for basic control.  I would try to get everything else working first, then add PWM later.

Second, if you want to build the H bridge from scratch, by all means do so.  Just have extra parts on hand since you will likely blow some up.  If you don't use those exact MOSFETS you may need diodes to clamp the voltages.  Some MOSFETs have them built in, some don't.

The 12 V or whatever voltage used can be generated by whatever means you choose, but there must be some sort of driver (transistor, chip) to interface to the microcontroller.

The MOSFETs have an advantage over most chips.  They can control much higher current for larger motors.

What I said about wanting fast switching is true, but not a complete picture.  The faster you switch a current on and off, the more radio frequency interference you generate, and more voltage spike on the motor coils.  It is a balancing act, fast enough but not too fast.  About 1 microsecond is usually good.  The current a microcontroller pin can source and sink might not be enough to charge and discharge the MOSFET capacitance that quickly.

What I said about the gate voltage is also true but incomplete.  There are two polarities of MOSFET, just like NPN and PNP transistors.  They are called N channel and P channel and are similar to NPN and PNP respectively.  N channels work better and are more efficient and cheaper.  P channels make the "high side" drivers (the ones that connect to +V ) simpler because they turn ON with a LOW voltage on the gate instead of the HIGH voltage required with the N channel.  Most H bridges use all N channel because they work better and are cheaper.  The app note circuit uses P channel (look at the arrows in the MOSFET symbols) on the high side for simplicity.  That is why they don't require higher (15-24 V) voltage to drive the gate.

As for cross references, there are a LOT of possibilities.  Google is your friend.  If you search "semiconductor cross reference" you will get a lot of useful hits.  Also, search for part numbers like 754410 and get data sheets.  Also, generic terms like "quad half h bridge" will get lots of hits, too.  The best way to learn how to find that information is try lots of different things.

I know this is long, but I hope it helps.  Maybe I didn't make too many mistakes.  Any more questions?

Will certainly read the pdf again (and again) :)

With regards to the PWM, I agree. First I will get it rotating, and then I will get to expeiriment with the frequency of the cycle and the PWM/voltage. One thing that would be interesting, is to see how I can somehow measure the torque/power of the motor.. to be able to tell how the different variables (timing, pwm, frequency) affect the motor. When I say timing, I mean, since I begin with a sensorless mode, when do I switch between the states? certainly, at a second phase, it would be good to try to use Back EMF to attempt sensor enabled mode. for now I know just a little about the theory. But I find the idea of hall sensors to control the timing, to be a little bit too much of an effort.. if anything, it would only make sense if the motor already had those sensors built in, which in most/all HDD motors I saw, they don't exist.

I do want to try and build my half-H bridges from "scratch", using gates. That would allow me to, as you said, blow up parts until I get it. I find/found it always, to be a very effective way to learn. Learn by burning parts is always fun, albeit a little more expensive. ;) BTW, now I need to learn a little the difference between a gate and a transistor. From a quick read, I see that when you say MOFSETs you mean gates.. so we use gate and MOFSET as a synonym. Right? I mean, in the schematics, the 6 "things" there are MOFSET gates. That explains the diagram of those and why they look a little like transistors, and a little unlike as well.. since MOFSETs have 4 terminals, but B and D are connected together, so its "baically" 3 terminals, which is "like" a descrete transistor. Correct?

You mentioned that if I use different gates, I need to either make sure they have voltage clamping inside, or have my own. So.. looking at the two types in the PDF, those have it inside.. as the sketch shows (using Zener diode, judging by the schematics) What I am not too sure is why there is the need for that. Can I assume it is because of voltage that might be building up in the engine inself? And if so, how much (/how bad) can those voltages be? what do I need to prepare for, with regards to zenner diode setup? You mentioned that voltage buildup when you talked about the fast-swithing and electromagnetic interferences.. the faster the switching, the higher the voltage buildup. So I am wondering how bad it can get. Certainly, considering I'm using Arduino, the intervals would be considerably more than 1 microsecond, as its the smallest sleep interval the microcontroller has.. so its certainly going to be slower that that.. at least I think it is.. I didn't consider yet using timer based interrupts.. but I suspect an order of magnitude (or two) slower. We'll see.

I totally understand the need for a driver between the engine/h-bridge and the microcontroller. That one runs on 5V while the bridge and engine on 12V. so I get it. ready made ESCs sometimes even go further and use opto-isolators. Would you say its a very smart addition to use? (I just received my shipment of some opto-isolator ICs :))

The pdf actually has BOTH N and P gates. you mentioned its for simplicity sake. What does it simplify exactly? and why not use only Ps then? I am assuming that if I wanted to use only Ns, all I would have to do is INVERT the input of the highs? Easiest would be to do so at the source - the arduino, right? BUT ANOTHER very simple solution would be to use a logial driver that does a NOT operation. Correct? I mean, instead of the TC4469, to use another TC446x.. or just look for a smarter way to connect it differently so that I switch the low and high of the arduino. Right?

As for cross-referencing, I'm going to try that now :)

I definitely recommend adding the PWM.  It will make a much better system in the end.  It is easier to start without it, and there are other ways of accomplishing the same thing, but overall it is the best solution I think.  My experience with HDD motors is that they DO have hall effect sensors built in.  Usually, they have them buried inside where they are hard to find.  There will often be six or more wires, some for the motor and some for the sensors.

Your terminology calling MOSFETs gates is confusing.  A gate is usually a logic device, like an AND or OR gate.  A MOSFET is a type of transistor, Metal Oxide Semiconductor Field Effect Transistor.  It has a terminal that is called a GATE.  That is the control terminal, similar to the BASE of a junction transistor (NPN or PNP)..  It is called the GATE because it controls the flow of current between the SOURCE and DRAIN of the MOSFET.  It is insulated from the other two terminals by a layer of METAL OXIDE, which is where the name comes from.  There is no electrical connection.  The electric charge on the gate causes an electrical FIELD in the rest of the MOSFET which controls the current flow..  The fourth terminal internally connected is called the SUBSTRATE.  It is "almost" always connected internally.  There is a CHANNEL between source and drain where the current flows

The two types of MOSFET, N channel and P channel, work opposite each other, similar to NPN and PNP transistors. An N channel, the most common and most efficient, require the voltage to be higher on the gate than on the source to let current flow.  The P channel requires the voltage on the gate to be lower than the source to allow current flow.  That is why they are used only in the top side of the H bridge.  They don't require the higher voltage that the N channel would require.  They could be used in the lower half, just like N channel could be used in the upper half, but then they would require a NEGATIVE voltage on the gate since the other two terminals would be at or near ground.  P channel are not usually used because they have higher resistance, switch slower, and cost more.

The voltage clamping diodes CAN be Zeners and usually the ones built in are.  That isn't necessary.  The internal ones are Zeners to protect the MOSFET from static charges and overvoltage conditions.  If you look closely at the diagram, the diodes are in REVERSE in the circuit.  They normally do not conduct.  They come into play when the motor current is switched OFF.  The current flowing in the motor (or ANY conductor) creates a magnetic field.  When the current stops, the magnetic field collapses, which GENERATES an electic current to get rid of the stored in the magnetic field.  That energy causes current to keep flowing, but the voltage is reversed.  The diode shorts out that reverse voltage.  It should NOT be a standard rectifier diode.  They can't switch from non-conductiong to conducting fast enough.  That voltage can get high enough to spark.  You need a schottky or high speed diode that has the same current rating as the motor.  Switching the driver slower gives the magnetic field a little time to decrease before it is cut off.  

The switching time is how fast the input on the gate goes from low to high, or high to low.  It has no relation to the speed of the processor.  Only how fast the circuitry is.  The switching time of a typical Arduino pin is about 5 nanoseconds.  Driving into the capacitance of the MOSFET would slow that down to several microseconds if the pin was connected directly.  The driver chip can drive it much faster.

Hope this helps.  Let me know if anything needs clarifying.

Sure. got the MOSFET part.

Not so sure about the Zenner vs Schottky though. I absolutely understand why a diode in the reverse position is needed. But not sure how Schottky gets in. Is it INSTEAD of a zenner? and a better choice for this one purpose?

Reading up on it, it seems the voltage drop of it is 0.3 instead of 0.7. so that's good. And as you say its fast switching, so thats another plus. But what I can't see is why then, zenner is an option at all?

When the MOSFET is designed/built, any type diode desired can be put on the chip for free.  A zener is used so that it also provides protection from overvoltage applied between the drain and source.  So if you accidentally apply say 50 volts to a 25V MOSFET, the zener conducts instead of destroying the MOSFET (in the reverse, zener direction).  It acts like a normal diode otherwise.  That can be important in some types of circuitry (like radio transmitters) and to help prevent damage from static discharge.  Not much good for too high power supply since that can provide enough current to burn out the zener.  It really isn't needed for this type of circuit, so adding it is not really a good idea.  Discrete zeners usually aren't as fast as shottkys.  In short, zeners protect the MOSFET from overvoltage in BOTH directions.  The Shottky only in the direction needed by your circuit.

The lower voltage drop of a shottky is actually a disadvantage in this case.  But not enough to matter.  Higher voltage helps dissipate the energy a little faster.  The switching speed is by far the most important criteria.And yes it is instead of the zener.