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.

One idea I have is keeping the HDD intact, with the plates as well, and trying to hack into its control board, so that instead of controlling the engine and coil directly, I will tell the board itself to "seek" a certain cluster. Mapping different clusters to degrees, I could then control the angle of the heads very accurately, using the already existing mechanisms and electronics. That requires a different level of hacking.. interface and protocol hacking. But that one is for a later time.

I was thinking about ascelleration/descelleration, but indeed reached to a point where I realized I needed to know the exact position to do that, and thats a no-go, as the idea is to drive the heads passively, without reading the disks (which are now gone).

As for current, a pretty considerable force can be created, when pushing it to the limit. Which gave rise to another idea... a spring (or rubber band, for short term experimentation). When attaching the heads to a spring, pulling the heads to one direction, it is way easier to control the position of the head, by applying different currents. It worked well enough.

At this point, I realized what I was looking to do with the coil is not really a suitable use for those. I have a specific idea in mind that I am thinking about implementing and it seems that a galvanometer or a fast step motor would be more suitable for my needs. So at this point its back to the drawing board :)

But it was certainly fun tearing down HDDs and messing with their inside. It was very educational so far, learning the schematics of an H bridge, implementing a crude ESC and running an HDD 3-phased motor. I am waiting on the scope now, and other parts to be able to implement a back EMF enabled ESC, as well as my own H bridge driver.

In parallel to that, I will move forward with my design and start experimenting with Galvos and step motors now. Shopping time!

What it sounds like you are trying to do will be VERY difficult if not impossible.  To move the head quickly isn't all that difficult, but it isn't simple.  To move it quickly to a fixed position and keep it there will take some serious feedback and current control. You have to consider Newton's laws of motion and basic magnetic theory.The coil produces a force that acts against the force of the permanent magnet. The force in the coil is proportional to the current through it.  When the two forces are equal and opposite, the head stays in place.  If the sum of the opposing forces is not zero, the head will accelerate and move to the new equilibrium position, probably oscillating there before stopping.  To move it quickly requires more force, F=MA or force = mass times acceleration.  Rearrange to get A = F/M.  More force means more acceleration.  The force in the coil is proportional to the current, but the current in a coil can't change instantaneously.  That is the inductance.  The larger the inductance, the slower the current changes.  You need higher voltage to get higher rate of change, but if you leave that voltage you will provide too much current.  So what you have to do is provide a high voltage for high acceleration until you are about halfway where you want to go, then reverse the voltage to decelerate to your fixed position.  That will need position feedback to be accurate.  To KEEP it in position if another force is applied, say your hand, requires feedback to sense it is being pushed and apply the needed current (using something like a PID algorithm).  But there is a severe limit.  The coil can only handle so much current.  It isn't designed to produce a lot of force, only what is needed to position the head quicly.  If you try to apply too much current you will burn out the coil.  All this will require some pretty fancy electronics and control algorithms and position sensors and probably still won't work very well with external forces applied.That coil probably can't handle more than 1 amp for a VERY short time, milliseconds or so, and an average of about 200 mA before it burns out.  That won't get you more than about an ounce or so of force.  Larger amounts of force will require larger coils wound with much larger wire.

The hard drive positions the head accurately with feedback.  Usually, one surface is dedicated to having factory recorded tracks that the head can sense so the controller knows where the tracks are and can position the head very accurately. It senses how strong the pulses are on those dedicated tracks and knows when they are strongest it is right over a track. The system is designed for least mass to allow fastest acceleration with the least amount of force.

seems to be that the HDD can control the head position, very fast and very accurately

http://www.youtube.com/watch?v=4sz4VHCj2Ho

It pretty much doesn't work like I need it to..

What happens when I feed it direct voltage/current, is that, at best, its moving a LITTLE, but does not get to, and stays VERY fixed at a certain point. Its pretty easily deflected with the hand and doesn't seem to really be fixed on a certain point.

What I need is for it to stay VERY firmly at a given point/angle.

Look at this video for example: http://www.youtube.com/watch?feature=player_detailpage&v=uJKxUPlhvZY#t=341s (at 5:40). The head moves to a very specific exact position, and stays there quite fixed. It then can jump from any point, to any point, very quickly and accurately.

I can't seem to get my coil to do that.

bdk6.. Before I address your notes, let me first say.. I broke the speed barrier I had before.

I did so by:

a) Improving the code, by switching the arduino ports all at once, using the port buffers instead of individual port commands. This helped greatly, as now I turn off one circuit and turn the other one on at the exact same time, instead of sequentially. 

b) Accelerating slowly towards the higher speed. (though, again, its a temporary solution because I don't have access to the back EMF or hall sensors)

c) other improvements to the code such as bitwise operations, getting rid of debugging (which slows down the execution) etc..

I'm still not sure what RPM I have, but it seems fast. Would wait for some sensors which might help me soon, measure speed. I also need to be able to commutate better, by reading position or using backEMF.

I got to a point where the motor is actually running on 14V and on a loop of 400microSec... meaning, each cycle roughly takes 2.4 miliseconds. If its 4 cycles per rotation, its 100 rotations per second or 6000RPM. Not too bad not totally sensorless controller ;)

 

1. Rearding the back EMF.. Yes. I think I could do that. I am not sure if such readings could be done fast enough to catch up with high RPM. Old disks operate at 5400 to 7200 (New ones are at 10-15K). And indeed, as evidently is true, each rotation is few cycles.. so the back EMF is probably at a rate of 4-8xRPM. So.. we are talking about 20K-cycles per minute or so. That is 360 readings per second. If Arduino can managed to read at a speed of 10K as you say, it would be fast enough. Having said that,  I can't reall read the BackEMF directly in the arduino, as it is coming back from the engine, and that one is in the 12V range which can not be connected directly to the Arduino.

Regardless, what would make more sense is to feed the backEMF into a voltage comparator and (as the notes say) look for the zero-crossing. Then, take 33% of the cycle time as a delay and use that as the queue to move a phase... However, once you do that, you start moving things out of the Arduino and into electronics.. Basically moving into building a full hardware-based ESC with discrete components. Very cool, but might be a little too far for what I want to do, which is learn the basics of it all. For that, I would probably limit the top RPM I aim for, to something that the Arduino can handle. However, before messing with EMF, I probably would benefit greatly from an Oscilloscope, as I can "see" the data I'm supposed to work with. Plus, it would be nice to be able to tell: a) What RPM I'm at. b) What Torque I have. I can do (a) once I get some reflection sensor of the sort. Any idas about (b) though?

 

2. About acceleration, yes. I already did that. The voltage required, takes a fine balance, as the commutation timing is "blind". For now I use fixed voltage as fed from the second power supply, and depending on what I'm testing, change the voltage on that supply to see the effect.

3. yes. I'm not sure how many, but I think about 4 to 8 of those cycles are needed. I can test it tomorrow.

Now I need to

I) Test the speed and possibly torque

II) Get an oscilloscope

III) Get BackEMF into the equation

 

 

A lot of the questions you still have are answered in the app note.  You just have to look a little closer.  There are waveforms of the back emf shown in the app note.  It goes between  0 and the applied voltage when measured at the "disconnected" terminal of the motor.  Those three mystery resistors and capacitor connected to terminal A are a voltage divider that scales the voltage down so that it doesn't exceed 5 volts and can be fed directly to the processor ADC.  Remember the voltage there will be proportional to the applied motor voltage.

Look at the datasheet for the AtMega 328.  The ADC section tells you how fast it can read and how to do it.  The chip is capable of a lot.  I have no idea how well the Arduino libraries use it.  I don't use Arduino.  You can always write your own, if need be.  If you really want to use the comparator method, the AVRs all (I think all, at least most) have a comparator on chip.  I have used it to read TV sync pulses.  It is plenty fast enough for this.  Keep in mind the reference voltage on whatever comparator will have to be scaled to the supply voltage as well.  Another voltage divider.  A counter on the AVR can also measure the RPM.  You could use an IR emitter and detector with some mark on the motor to start and stop the timer input.  That will measure the time for one revolution, and 1 / time = frequency in revs per second ( * 60 = rpm).  

I'm not sure of an easy and good way to measure torque, but I bet google can give you a lot of ideas.

An o'scope is great, and you will need one, but you can do a LOT without it.

Congratulations on your success.  You've made a LOT of progress.

Thanks bdk6

I indeed feel I made a lot of progress. My main goal was not to turn the motor.. but brush off the spider webs from my dormant knowledge of the past. In that respect I did manage quite a bit :) I didn't really set out to turn the motor on (as I could have slapped an ESC and rid myself of the "problem"), but to learn about it, and about many other aspects of electronics.

Yes, the motor turns. No, its still sensorless and even blind.. as I've not yet taken into account back EMF.. though I intend to anyway. I am using a ready made Full-H driver, yet I intend to replace it with my own, again, for the sake of using MOSFETS directly - again, a learning experience.

Once I get back-EMF into the mix, which is how HDDs actually do it, as evidently there are no Hall sensors on both HDDs I use, I will also be able to control the speed of the motor. And only then, will I just replace the whole thing with an ESC :)

I'm waiting for the Oscilloscope to be able to make smarter plans. For example, I need to know what to expect in terms of voltage on the disconnected terminal. Actally, schematics I saw just connect all three phase terminals together and use the common voltage (somehow) as a feed for the backEMF measure (not sure why.. have to read more). But I can't really read the values of the back EMF eaily without a scope and "see" what voltage should I am for as the zero-crossing value. A scope will immensley help here as I can experiementally see what I should be looking for, programatically.

 

 

And in that note, I am on to the next challange, still within the same realm. Now, the HDD heads, or in other words, the voice-coil.

I already managed to connect the coil, via a full-bridge to be able to switch the head all the way left, or all the way right. This is done by applying -9V or +9V to the coil. That easy.

HOWEVER the goal is not to lock the head into a 100% LEFT or 100% RIGHT position, but instead, to fully control where the head is at in that range. I tried several things..

First, I tried applying a certain in-between voltage - that cobviously didn't work, though I didn't really expect it to ;)

Second, which made a little more sense to me was - oscillating the voltage on the coil between -9V and 9V, rapidly, in hopes that it would stick to the middle. While it buzzes and shrieks, or depending on the frequency, also shakes, it does NOT stick to a given position. Instedad, it floats around a certain place lightly, without much force. 

I would love to hear your thoughts on this one before I dig further (and I did already some light reading)...

Any guesses as to how to make it stick firmly at a given angle?

And by the way, happy new year to everyone.

The voice coil generates a magnetic field that acts against the permanent magnets.  It is very low resistance, probably on the order of 1 ohm or so.  The magnetic field strength depends on the current through it.  Probably something like 100 milliamps will deflect it fully.  You can use any voltage and a resistor, but lower voltage is better.  The strength of the magnetic field determines position.  I would start with your 9 volts and a 1 K resistor, for about 9 mA.  See what that does.  Go from there. 

BTW, the drive is ST320014A ( http://www.seagate.com/support/disc/manuals/ata/usx20pmbu.pdf )

5400 RPM. So maybe I reached its maximum speed.. Would be nice to measure.