Electromagnetic Levitation

Status
Not open for further replies.

lurkingdevil

New Member
**broken link removed**
old circuit - **broken link removed**
I'm trying to build a electromagnetic suspension device. The circuit is above.

IR Led beam and photodiode method is used.

New circuit, microcontroller removed but it still isn't stable.



I'm using arduino to control it. The voltage of the photodiode is fed into the arduino's analog pin. The electromagnet is controlled via PWM from arduino.

But I simply can't get it to work. I've tried various simple algorithms but none work. The object vibrates fiercly when held at the balance point. uC Analog to Digital Converter reads 722 when the beam is obstructed, and 20 when there is no obstruction.

If there is no issue with the circuit, then please help me with the program/algorithm I should use. I'm novice at this so my algorithms usually tend to be very simple and maybe not good enough.

About the voltage amplifier, I had first skipped it and connected the uC pin straight to the MOSFET. It worked initially but the MOSFET died soon. The reason is that its not logic level MOSFET. I used it because thats what I had with me. Here is my thread about it.
 
Last edited:
From your other post.. I would remove the 100 nf cap and replace it with a 47k from base to emitter. I think I would also make the 10k from the gate of the FET about 1k to speed it up a bit. Not sure about how to control it.
 
You probably need to speedup your feedback loop to get rid of the low freq oscillation.

The diodes across the solenoid coil give you a slow current decay so it will limit how fast the magnetic field can be reduced. Try putting a 20v 5W zener diode in series with the diodes, but reverse polarity to the diodes.

Then your feedback system looks slow too as you are working in analogue and will have time delays to get the ADC reading etc. Try taking all delays out of your code and making the feedback loop as fast as possible and just making the PWM on and off based on one setpoint.
 
From your other post.. I would remove the 100 nf cap and replace it with a 47k from base to emitter. I think I would also make the 10k from the gate of the FET about 1k to speed it up a bit. Not sure about how to control it.

Sorry, I got the scehmatic wrong. Its fixed now.
 

My power supply is 15V, how can a 20V zener work?

I have sped up the ADC. It now takes 16uS to get a reading. Fast enough?

Basically here is the pseudocode :
Code:
int setPoint = 550;

loop() {
input= AnalogRead( input pin);   //ADC input
if (input > setpoint) digitWrite(outPin, HIGH);
if (input < setpoint) digitWrite(outPin, LOW);
}

If I hold the magnet at the balance point it vibrates at a high frequency. As I let it go, the amplitude of vibrations increases and it shoots through towards the coil.
 
hi,
As you pulse , switch OFF the coil current it will generate a back EMF voltage, which could be many times higher than 15V.
The 20Vz will conduct when the back EMF is greater than ~20V and protect the MOSFET from over voltage.

When the back EMF falls below 20V the current flowing in the coil due to the back EMF and the Diode will cease and the coil field will collapse faster than it would without the zener diode.

OK.?
 
Last edited:
But if I put the zener in series with the other diodes, then the current will eventually be limited by the other diodes.
 
But if I put the zener in series with the other diodes, then the current will eventually be limited by the other diodes.

How will that be possible , if the zener is in series with the other diodes.?
The zener will not be conducting
 
Hi,

Just a quick question here:
How does the uC know if the object is above or below the 'beam', or is there some physical limiting mechanism for limiting the objects height or is it assumed that the object can not get high enough to lower the photo diode response?

Also, what is the inductance of the coil?
 
Last edited:
Once the object is completely blocking the beam(or above the beam), the value of the 10 bit ADC goes above 700. Usually 722.

When no obstruction in beam, the adc reads 22.
I am using a abritrary value of 550 to keep the object somewhere between above and below the beam.

I don't know the inductance of the coil but its plenty powerful to pull the object up at even 70% power.

I am considering replacing the uC with some op-amp circuit.
 
What is not clear to me from the pseudo-code you wrote is how you controll the PWM output ? What frequency do you use ? And how do you controll the width of the pulse ?

Normally, you should use a frequency of a few hundred Hz, maybe between 100 and 300Hz. Then, you should control the with of the PWM proportionnally to your ADC value. If the object is too low, the widht should be increased to give more power to the magnet. If its too high, the width should be decreased.

You need a simple PID algorithm to achieve that.
 
The pseudo code I posted didn't have PWM in it.

I have tried so many pwm codes, some better than others but none was able to make the object float without me supporting it.
The problem is that the pwm needs to vary depending on the object's weight.
 
Levitating an object and keeping it stable requires a good control loop. A PID loop is difficult to design and optimize. You will likely need to control the PWM duty-cycle to achieve stable control.

You might look at Fuzzy Logic control. It uses If-Then commands as you have in your pseudocode, but more of them to stabilize the loop.

Here's a demo using Fuzzy Logic to balance an inverted pendulum (a difficult task):**broken link removed**

Here are some other Fuzzy Logic references:
https://www.fuzzy-logic.com/
**broken link removed**,
 
So I got rid of the microcontroller, and using just an op amp to control.

Is the circuit okay?
That simple circuit is a bang-bang type of controller and that won't give you stable levitation (by definition a bang-bang loop has to oscillate for control).

For a stable loop you could go with a PID loop by adding an integrator and a differentiator to the proportional signal. But as has been noted it can be difficult to determine what the integrator and differentiator time constants are needed for a stable loop.

Basically you are trying to use a simple circuit to perform a complex control loop function and that will not give you the results you want.
 
You almost make me give up

At this point even if I can get this to levitate for 45 seconds, I'd consider it a success.
 
Last edited:
From what I have seen from working projects like this on the net you need to get it to oscillate. If the feedback is setup right it will oscillate around the feedback point (set by the height) and regulate height.

The slow mechanical time constant of the object (mass) means it has to oscillate faster than the object will move so you need lots of positive feedback. So in operation the oscillation might be a few hundred Hz, and the average duty is controlled by the optical feedback so once the object gets higher than X it reduces the ON duty.

(As a starting point) I would use a comparator oscillator running about 80% ON duty, then the optical feedback used to reduce the ON duty. You need to tune it based on how many mm movement of the object height controls how many % duty reduction. If that is too much gain it will oscillate mechanically (as you are getting) and if not enough gain there it will be slow probably slam the object to the top then drop it...

And as said before you really need to speedup the current decay in the coil, as anything like a constant field there will be very hard to regulate the height, you really need that coil field to be switching completely on and off (so its "lifting" and "dropping" the object constantly at a couple hundred Hz).
 
Last edited:



Hi again,

I asked about the inductance because large inductance and low voltage means slow response. But probably the main issue in this system is the non linear forward control element, which is the variable pull from the electromagnet. It's probably going to be an inverse square law, which means the higher the object gets the more force is pulled on it by the electromagnet. That's not linear at all. These simple loops can work with linear systems but i have a lot of doubts that they can work with a non linear system like this unless it is close to being linear (magnet far away).

Because of this non linearity and without doing a complete analysis on this system one thing you can try is to make the control algorithm such that the higher the object gets the shorter the pulse width is made. You can start out with a simple relationship like 2:1 or something like that and maybe play around with that ratio. Just for example, say you have a full on pulse width of 90 percent and say that is 750us just to use round numbers. That would mean 750us while the object is very low (low ADC reading). When the object gets about half way up (ADC say around 350) you would only allow a pulse width of 400us, and for the object all the way up maybe only a pulse width of 50us. These are just an example which probably needs adjusting, but this illustrates the kind of control law you probably have to use to get this to stabilize.
In this example the control law is simply:
PW=(700-ADC+50)*1e-6
which simply means you take the ADC count and subtract that from 700, then and add 50, then multiply by 1e-6 and that is the required pulse width. Of course this simplifies to (ADC+650)*1e-6.

Dont quote me on the actual numbers though, you'll have to play around with that. You'll have two numbers to deal with, the lower one and the upper one.
The upper one comes from the max ADC count which we approximated above to be 700, and the lower one is somewhat arbitrary as you'll have to experiment with that one. The upper pulse width will come from whatever you can get out max right now, and the lower one is adjusted until you get something stable.

Another example:
Say the max pulse width is 1000us and you choose first a min pulse width of 100us (one tenth the max). That means we need 1000us when the ADC is close to zero and 100us when the ADC is 700.
We have two data points:
1000us ADC=700, and
100us ADC=0
so we have:
K=(1000-100)/700
and
PW=(700-ADC)*K+100
where PW is the pulse width in microseconds.
Note that K above is computed from subtracting the min pulse width from the max pulse width and dividing by the max ADC count, and that the '700' is the max ADC count ever obtained.

This is a linear approximation to the magnet/object response so there's a chance you may have to move to an inverse square control law, but it's worth a shot to try it like this first.

Alternately, maybe you could search on the web for a project like this that has already been completed and try to find the control law they used and maybe modify it a bit.
 
Last edited:
Wow thats quite a lot of information...

I will try to add some positive feedback.

My uC died sadly..

I'll have to get this to work with analog circuits. I don't know PID, and if thats what I need to get this to work, then this will have to wait till I learn PID.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…