Electromagnetic Levitation (Part 1): Sensor Feedback

I have been working with superconducting levitation for a while, which is vastly superior to conventional methods of electromagnetic levitation, and this project was part of my effort to wrap my head around what it would take to reproduce the levitation performance of superconductors using conventional materials & components. This post will be followed up by Part 2, a project that further simplifies the circuitry (sensorless) as well as replicating even more of the nice properties of superconducting levitation.

Here is an example of superconducting levitation. Note how it works just as easily as regular magnets do: as I approach the superconducting material with a magnet, it leaps up to meet the magnet, as another magnet would, except it stops a certain distance away, instead of slamming into it. Likewise, I can daisy chain superconductors together, just like I can attach a bunch of magnets back-to-back:

There are many webpages out there that show how to build electromagnetic levitators. However, the results are usually not as magical as are attained with superconductors, because:

  1. They require careful placement of the object to let the levitator “grab” it
  2. The object is prone to falling or unstable runaway oscillation when disturbed

As can be seen in the video below, my levitator will “grab” a magnet out of your hand, without any careful placement, and it’s stable enough to move the magnet around freely and smoothly. This replicates a bit of the performance of superconductors for levitation:

This post has three more parts:

A. Theory of electromagnetic levitation. 

B. Description of my simple hall sensor based levitator. 

C. What makes my levitator work so smoothly. 

A. Theory of electromagnetic levitation

So, before getting into the project, I figure it is worthwhile to explain briefly what problem is being solved. Why is levitation hard? Magnets can lift things, so can’t you just place magnet A at the right height above magnet B, so that magnet A doesn’t fall, and hangs in air? After all, since gravity’s force is constant, and the force between the magnets varies inversely with the square of the distance between them, there must be a point where they are equal. For example, with the magnitude of the magnetic attraction in blue, and the gravitational force in red, and the distance along the X axis:

Screenshot from 2017-03-23 21:55:08.png

f(x)=1
f(x)=1/(x^2)

There’s a point there around x=3 where the net force is zero! Showing the net force, that is gravity (pulling down) vs magnetic force (pulling up) makes it even clearer:

Screenshot from 2017-03-23 21:55:19.png

f(x)=Screenshot from 2017-03-25 19:35:52.png

So why won’t the magnet actually sit still if it’s positioned at that zero-crossing point? Well, nothing in nature is perfect, and so we won’t place the magnet perfectly at that point of zero force. And, even if we do, any small disturbance, such as an air molecule striking the magnet, will push it away from that point. What happens then? Well, here’s an illustration:

asdfarr.png

Our point of zero force is marked with the blue X. If the magnet drifts a little bit up (to the left in the graph), following the blue arrow, the magnet’s force gets even stronger. That means it moves moves up even more, which makes it stronger yet, and so on, until the magnets slam together, in familiar fashion. Likewise, if the magnet drifts a little bit down, the force from the magnet pulling up diminishes, following the green arrow, and now is less than that of gravity pulling down. That means the magnet falls down some more, which makes the magnet’s force even less, and so on, so that the bottom magnet falls endlessly away from the top magnet (hitting the floor).

This point is not stable, it is a knife-edge of instability, as anyone who has tried this with magnets in their hands can tell you (be careful of your fingers if you do!).

It turns out that there is a theorem in physics, called Earnshaw’s Theorem, that shows this is impossible in all cases. You can’t add more permanent magnets to create more stability, in any configuration. Essentially, Earnshaw’s Theorem implies that you always must control at least one degree of freedom in some way other than static, permanent magnets. That’s why old-school magnetic levitation toys always had the levitated object touching something, to provide stability:

So how is free-floating magnetic levitation possible? Some time-varying force must be introduced to the system to create a zone of stability, where movement away from the balance point produces net force back toward it. One very simple way to achieve this is with diamagnetic materials, for example Bismuth. This is explained very nicely on this page . To put it in the terms we’ve been using here, Bismuth is repelled by magnets, but it doesn’t just repel like a magnet, with force inversely proportional to the square of the distance from the magnet, instead it becomes stronger as the magnet approaches. The Bismuth also provides stability to the magnet’s tilt, because as one side of the magnet approaches it more closely, the repulsion force is also stronger on that side, righting the magnet. Two magnets repelling want to flip over, and so destabilize each other’s tilt, creating yet another barrier to stable levitation.

Here is a video of an experiment I did with Bismuth demonstrating this property. The height is varied by varying the current thru a coil up above the top piece of bismuth, out of view.

However, Bismuth’s diamagnetic repulsion is very small. Superconductors are far more diamagnetic, and this is one of the properties that makes them so useful for levitation.

If we don’t have something very diamagnetic at our disposal, we can create a time-varying force through feedback, such as through active sensor feedback as in Section B below.

B. Explanation of my simple hall sensor based levitator

The basic design is shown in this schematic. Note that, physically, the hall effect sensor is placed in the center of the coil, and so there are 5 wires running from the “head”, the part you see me moving with my hand in the video, to the breadboard (VCC, GND, and VHALL, as well as two for the coil):

HallSensorLevitation (6).png

As you can see, there’s nothing special about the circuit. The basic operation is:

  1. When no magnet is present, the hall effect sensor’s value is low, so VHALL is lower than the HEIGHT_ADJUST voltage. Thus the coil is fully energized, which creates a magnetic field.
  2. When a magnet approaches, it is attracted by this field, and begins to move toward the coil.
  3. As the magnet moves toward the coil, its field* is sensed by the hall effect sensor, raising VHALL.
  4. As VHALL approaches the height adjustment potentiometer’s voltage, the coil is partially de-energized, the magnet’s approach slows (counteracted by gravity), and the system eventually reaches equilibrium** with the magnet at some distance from the coil.

*  Note that the coil’s field also influences VHALL. The sum of these two actually determines the HEIGHT_ADJUST voltage threshold required for a given levitation height. I just figured it out experimentally using a voltmeter. 

** The voltage at the MOSFET gate actually looks like a PWM signal. This is likely caused by a hysteresis effect involving the coil’s own magnetic field. When the coil is energized, it will be de-energized when the magnet is a bit above threshold height, since the magnet’s field must cancel out the negative influence of the coil on the hall sensor. This may actually be a source of efficiency in the design, largely avoiding running the transistor in the active region, at the expense of a small mechanical oscillation. 

Returning to our equations and graphs from the previous section, the force on the magnet vs distance from the coil in this system looks like this:

gimp_levitator_eq.png

f(x)=gimp_levitator_eq.png

The meanings of each of the parts of this equation are:

  • 1: gravity is constant
  • Screenshot from 2017-03-25 19:09:54.png:The hall voltage sensed goes with the inverse square of the distance between the magnet and the coil, as it is linear with field strength at the hall sensor. At a certain threshold (the reason for the -1), set by the HEIGHT_ADJUST voltage, the coil begins to energize, and the current through this coil modulates the field strength. The coil only energizes in one direction, thus the min(0, …).  Note that, in reality, the transition in coil current tends to be quite a bit sharper than this, due to the behavior of the op amp, but this is not important for basic understanding of the system.
  • Screenshot from 2017-03-25 19:12:06.png: The magnetic force varies inversely with the square of the distance between the magnet and the coil.

This seems really straightforward, but if you’ve worked with control systems before, you’ll probably have noted the potential for oscillations to build up in this system. While it does turn out to be possible to use just this circuit to levitate a magnet, it’s very sensitive, and just gently blowing air on the magnet can cause it to enter wild gyrations, ending up with it falling down. While active damping / compensation could help in terms of stabilizing distance from the coil, there’s still no tilt stabilization at all in the system, so moving the coil around will still set up long-lived oscillations.

This video shows the “long lived oscillations” common in even well damped single-axis levitators. There’s simply nowhere for the energy to go (except into the finger at 1:12):

C. What makes this levitator so smooth

Some levitators actively dampen this oscillation: the “executive levitator” desktop style ones even incorporate multiple hall sensors and coils, which achieve damping in multiple degrees of freedom, but my solution was much easier.

A large part of the robustness of superconducting levitation is actually provided by superconducting materials’ AC Losses. Superconductors are able to conduct DC with zero resistance, but whenever the current changes, a there is loss of energy to heat. So, if one imagines a magnet levitated over a superconductor statically, there should be no loss of energy, and thus it can stay levitating indefinitely. However, if the magnet is disturbed, it begins to oscillate back and forth, as its movement induces currents in the superconductor that create magnetic fields that oppose its movement and send it back in the other direction. This might continue forever, except for the superconductor’s AC Losses: each time the current changes, some amount of energy is dissipated as heat. This causes the magnet to return to rest in a static position again.

Following the same principle, for stability I put a plate of aluminium between the coil and the magnet. Being an imperfect conductor, the aluminium dissipates energy and slows down the magnet every time the magnet moves, because a moving magnet induces currents in the aluminium which then create a magnetic field that “pushes back” against the magnet’s motion, and these currents encounter resistance flowing in the aluminium. This replicates the stabilizing effect of the superconductor’s AC losses, dampening every possible degree of freedom, even allowing the coil to move around without dropping the magnet. Given that aluminium is not a perfect conductor of DC, however, the active control circuit is still necessary to control the height of the magnet, as the eddy currents in the aluminium die out quickly when the magnet stays still.

Here is a video that illustrates the stabilizing effect of the aluminium well:

Advertisements

Ultrasonic Levitator (Old project)

This is a project I did about 6 months ago, when I was a lot less confident in electronics. However, I did get it working eventually. Thanks to mikeselectricstuff for inspiring the project with his video: Ultrasonic acoustic levitation

My initial design was somewhat complicated, involving an “auto-tuning” mechanism that allowed an Arduino to adjust the frequency of oscillation, generated by a 555 timer, using a digital potentiometer, to maximize the current consumed, as measured by a shunt resistor. Ultimately, I found that the ideal frequency was always exactly 25khz, despite the results seen by Mike (mentioned above), and so I just directly generated that frequency from the Arduino, and things worked fine. The driver just uses a transformer I wound on a ferrite toroid, with two primary windings wound in reverse directions, driven by two N-channel MOSFETs, each driven by a different pin on the Arduino. So ultimately I had a much simpler solution to build than Mike’s:

UltrasonicLevitator (2)

There should be resistors between the arduino pins and MOSFET gates. 

And here is the transformer up close:

IMG_8870

The transformer generated about +- 100v from about 7v input, from what I remember, and that was sufficient to levitate the bits of wax paper I was using. More power actually destabilized the levitation.

Here are some videos of the results:


This was true high-fps slow motion from my iPhone, before YouTube messed with it. Oh well. 



Optical Mouse Robot

As a part of my work developing Plobot (http://plobot.com/), we were trying to think of ways to improve the robot’s performance on carpet. The trouble is that a degree of wheel slippage is inevitable on carpet, and so encoders cannot be very accurate. Another team member, Maciej, suggested an interesting solution: the sensor from an optical mouse.

So, after doing some reading on the topic, I went around the corner and bought a cheap optical mouse, and took it apart. The inside looked a lot like this:

IMG_8802

I knew from my reading that the maker of most of these low-cost optical mouse sensors is Pixart, and I saw “KA8” written on the module, so I typed “Pixart KA8” into Google and this datasheet came up: PAW3204DB-TJ3R

Seeing the staggered pin arrangement was the same in that document, I became confident that I had the right datasheet, and I extracted the module from the mouse PCB. I then cobbled together my own circuit based on the schematic in the datasheet, running the module at 3.3v and communicating with it with an Arduino Uno. I added voltage dividers on the two serial lines to level shift.

My optical sensor proto-board

Unfortunately I saw a lot of garbage coming from the chip, and the serial protocol was not defined in the datasheet. I searched Google some more and came across this more complete datasheet for a related part, which turned out to have the same serial protocol: PAW3204DB

I then realized that the serial synchronization was essential to getting meaningful results from the module. I added code to synchronize every 100 read commands, and was able to read the product ID. As it turned out, I was in fact working with the PAW3204DB, and had been overvolting it the whole time at 3.3v. I was lucky that it held up. I added a voltage divider and a large capacitor on the power supply to get a stable 2.7v, with the optical sensor consuming < 10mA. I also made other minor tweaks such as adding the 34k resistor on OSC_RES.

Using the PAW3204DB datasheet, I was able to get tracking data from the optical sensor board, and with the help of another teammate, Rudi, I assembled a rough but adequate robot body to test with. I used the current revision Plobot board I had on hand as a driver.

NOTE the capacitors soldered to the motor leads and case. These EMI suppression capacitors were actually essential to making the robot work! Without them, the optical sensor module would malfunction severely when the motors ran. This issue frustrated me for a few hours.

Finally, after writing a quick and dirty control program using the Atmel microcontroller on the Plobot PCB, I had a working robot built around the optical sensor. No encoders or motor feedback sensors of any kind!


And it worked for my purpose, allowing the robot to tolerate a great deal of wheel slip, almost “skating” on the carpet:


The results with this sensor were not accurate enough to be a full solution for moving on the rug on its own. However, it could work well to complement encoders to detect slip, and I will be experimenting with higher quality sensors as well.

 

The control program works on the principle that when robot rotates, the optical sensor senses horizontal (X) movement, since its horizontal axis is always tangent to the circle. When the robot moves forward/backward, it senses vertical (Y) movement. So, when going straight, motor power is balanced to minimize X movement. While turning, it is balanced to minimize Y movement. Likewise, when going straight, a certain total Y offset is counted to determine the length moved, and when turning, a certain total X movement is counted.

 

 

Super Simple Class D Guitar Amp

Tonight I created a working guitar amplifier on a breadboard. It runs on 12v, and produces a decent amount of power (~1 watt) for practicing purposes when connected to a suitable speaker. I used a medium sized 4 Ohm one, visible in the video. The circuit is shown below:

 

The simplicity of the circuit stems from the use of this cool oscillator:

A sawtooth waveform at approximately 50Khz, with a nearly-linear ramp, is produced by the S9014 BJT. This waveform is approximately from 5v to 9v:

IMG_8558

The guitar signal is 200-300mV peak to peak, and the sawtooth is scaled to match this amplitude. Both the guitar signal and the sawtooth are coupled to 1/2 the supply voltage, with  a potentiometer used to fine tune the overlap between the signals.

Finally, both signals are fed into a comparator (LM311), and the output from this drives the gate of a MOSFET. A 10nF filter capacitor is added to the sawtooth signal to reduce oscillations caused by feedback from the speaker via the power supply rails. Some hysteresis on the LM311 would probably help even more. The large power supply decoupling capacitance also helps to address this: without it, spikes appear in the oscillator waveform, and wild high frequency oscillations can appear in the output.

Despite amplifying essentially only half the waveform, and various other limitations, the sound quality is surprisingly good. See video of the amplifier in action here: