Rather than needing to model PWM effects on levitation you can run the PWM at much higher than critical rate then either
Filter to DC.
This can drive an eg FET driver. OR
Send unfiltered PWM to FET and drive inductor with recirculation diode for when FET is off.
This now becomes a buck converter. Changing PWM % changes inductor current.
You can add a sense resistor and measure current.
With due design the sense resistor can have one end grounded allowing ease of I measurement with microcontroller's ADC.
eg M1 is a P Channel high side MOSFET. If inductor supply is the same as microcontroller supply (which is not usually the case the gate can be driven at microcontroller voltage levels. If eg mc has 5V supply and inductor has say 12V supply a level-shifting driver is needed. Details on how this can be achieved can be discussed if this is the path taken. D1 allows current "recirculation" when MOSFET is off.
R1 allows current sensing.
Depending on inductor resistance it may be desirable to provide additional loss in the recirculating path to allow faster field decay to improve control response times. Or not.
simulate this circuit – Schematic created using CircuitLab
_______________________________
I see lots of people suggest using a TIP120 for driving a high current load from a uC. But it seems a FET is a much better choice since it allows faster switching and is less power hungry.
TIP120 is less bad than some - 5A 60V Darlington. Min current gain is 1000
BUT C-E saturation at 3A is 2V max @ Ib=12 mA,
and 4V at 5A at Ib = 20 mA.
At 3A that's equivalent to on resistance of R = V/I = 2/3 = 666 milliOhm or
at 5A = 4V / 5A = 800 milliOhm.
Heat = 6W and 20W.
FETs with much much much lower Rdson are cheap and available.
Also 12 mA drive is liable to be near upper limit for some uCs and 20 mA worse.
FET drive needs are low at low speeds and if higher speeds needed a 2 transistor gate driver (NO other parts) can be used.
PWM with recirc diode as in other answer looks good.
An N Channel FET is equally good from a power switching point of view.
N Channel speed is no problem - required switching speeds will be well below what can be accomplished with typical devices.
The above P Channel method puts the "switch" high and allows the sense resistor to easily have one side grounded. This makes it simple to use an ADC to read V_Rsense in microcontrollers with ground referenced ADC's and keeps Rsense under Vdd_mc.
An N Channel switch on the "low" side slightly simplifies FET drive but makes Rsense voltage slightly harder to read as Rsense is then usually either floating or attached to V+_solenoid. Usually you then either use a current mirror to "reflect " Isensed to a ground reference point or use a differential amplifier to do the same.
Rsense is then usually at DC level of > Vdd_mc if Vinductor >> Vdd_mc as is often the case.
Iron is a poor conductor compared to copper so making an electromagnet from iron wire is off to a bad start. Next, an electromagnet has basically a massive air gap and this is the bit that attracts i.e. the working end of an electromagnet is the air gap. This is generally why the attractive force produced by a solenoid electromagnet has nothing to do with the permeability of the core: -
Force = \$(N\cdot I)^2\cdot 4\pi 10^{-7}\cdot \dfrac{A}{2g^2}\$
- F = Force
- I = Current
- N = Number of turns
- g = Length of the gap between the solenoid and the magnetizable metal
- A = Area
Best Answer
Simple answer: Current. The strength of the magnetic field depends on the current that flows in a linear fashion - Double the current, double the magnetic field. Since the resistance of the conductor is the thing that determines the current, you need more voltage to have that current.