PROJECTS MICROCONTROLLERS
Light as Air
Using the ATM18 to control
a magnet levitation device
Udo Jürß and Wolfgang Rudolph
Overcoming gravity is an age-old dream, which we can t expect to see fulfilled anytime soon.
However, we can come closer to making it reality on a small scale. Commercial
levitation devices that cause a small piece of metal often with some sort of
covering to hover in the air have been available for many years. A coil provides
the lifting force, and a light barrier is used to regulate the levitation height. This
causes the levitated metal object to maintain a defined distance from the core of
the coil. Many of these devices are more expensive than need be.
We also want to make something hover, but here we take a slightly different
approach. Instead of a light barrier, we use a Hall sensor to detect the position of
the levitated object.
50 elektor - 9/2008
With the usual levitation devices,
which have already been described in
The ATM18 project on Computer:club2
DIY articles in past issues of Elektor,
aTM18 was developed jointly by Elektor and Computer:club2 (www.cczwei.de) with contribu-
the beam of a light barrier is more or
tions from Udo Jürss, the main developer of www.microdrones.de.
less obstructed by the floating ob-
Each month, the latest developments and applications of the ATM18 system are presented by
ject. The amount of light received by
Wolfgang Rudolph of CC2-TV in a TV broadcast on the German NRW-TV network. The levita-
the sensor of the light barrier is used
tion controller with the ATM18-AVR board described in this article can be seen in instalment
to control the amount of current flow-
12 of CC2-tv, initially broadcast on 26 June.
ing through the coil. The mechanical
and electronic construction of the de- CC2-TV is also broadcast as a Livestream on the Internet at www.nrw.tv/home/cc2.
vice is designed to maintain the lev-
CC2-TV Podcasts are available from www.cczwei.de and a few days later from seven-
itated metal object in the prescribed
load.de
position. Distance control using a Hall
sensor is based on a completely differ-
ent principle.
VDD
Magnetic field sensor
Internally
Open-circuit,
stabilized Temperature
Protection
Overvoltage,
A Hall sensor is a semiconductor de- Supply and Dependent Oscillator
Devices
Undervoltage
Protection Bias
Detection
vice that generates a voltage propor-
Devices
tional to the strength of the surround-
ing magnetic field. The voltage pro-
duced by the actual sensor element is
100
Digital
OUT
Switched A/D D/A Analog
Signal
very small (in the millivolt region), so
Hall Plate Converter Converter Output
Processing
a sophisticated bridge amplifier is also
necessary. We use a Micronas HAL815
integrated magnetic sensor housed in
10 k
EEPROM Memory
Supply
a low-profile TO-92UT package in our Digital
Level
Output
Detection
levitation controller, so this is already
Lock Control
taken care of. The amplifier, tempera- GND
ture compensation and a filter are in-
080359 - 12
corporated in the IC (Figure 1). All of
the parameters can be programmed
by superimposing digital signals on
Figure 1. Block diagram of the sensor.
the supply voltage (with pulses that
increase the voltage from 5 V to 8 V).
For instance, the measuring range can
be adjusted from Ä…30 mT to Ä…150 mT.
Hall effect
Programming is not necessary in
this case, because the device is fac-
The American physicist Edwin Herbert Hall discovered this effect, which was later named after
tory-configured for the Ä…30 mT range
him, during his doctoral work in 1879. The Hall effect is based on the Lorenz force. Moving
which is exactly right for this appli-
charges are deflected in a magnetic field, and this produces a potential difference perpendi-
cation. With a supply voltage of 5 V, the
cular to the direction of current flow.
output voltage is 2.5 V with no mag-
Hall sensors are made from small, thin sheets of semiconductor material with a low charge
netic field present. The output voltage
carrier density in order to achieve high electron velocity. This results in a relatively high output
varies by plus or minus 2.5 V depend-
voltage. If a current flows through the sensor and it is placed in a magnetic field with the field
ing on the direction and strength of the
lines perpendicular to the surface of the semiconductor, the sensor voltage changes. The out-
magnetic field, for a total range of ap-
put voltage of the sensor is proportional to the product of the current and the magnetic field
proximately 0 to 5 V. Only one direc-
strength. As the value of the current is known, the magnetic field strength can be determined
tion is needed in this application, so
from the measured voltage. These sensors are usually integrated in a package with a signal
only the range between 2.5 V and 5 V
amplifier. The thermal sensitivity of the sensor is also compensated in such devices.
is used.
Controller
the coil to keep the magnet floating in for this ATM18 project, but instead
If we bring a magnet close to the Hall the air. The current is adjusted around with software in the form of a control-
sensor with the magnetic field lines 1000 times per second. This continual ler program. Every minute departure
perpendicular to the surface of the adjustment requires certain rules. PID of the levitated magnet from its in-
sensor, the output voltage of the sen- controllers (proportional, integral and tended position, every air movement,
sor varies in proportion to the magnet- differential see the inset) are used in every change in temperature, every
ic field strength. This makes it possible electronic systems for this purpose. vibration, and many other things can
to determine the distance between the In our case the I component is not directly affect the levitated behaviour.
sensor and a magnet with a known necessary, so we can use a PD con- If the magnet moves a bit closer to the
field strength. With this information, troller. However, it is not implemented solenoid coil, the current in the coil
a controller can adjust the current in as an analogue circuit with opamps must be reduced immediately. If the
9/2008 - elektor 51
PROJECTS MICROCONTROLLERS
+5V
coil
GND
DATA
CLK
LCD 20 x 4
12V
+12V
TSOP1736
magnet
Vs
VDD
HAL815UTA
GND GND
Vo
OUT 080359 - 11
Figure 2. Schematic diagram of the experimental circuit
magnet moves even a small distance hand, the magnetic field of the fully magnets is cannibalised CD drives. A
away from the coil, the current must energised coil must be strong enough preliminary test with the solenoid coil
be increased immediately. As the coil to lift the magnet from its lowest posi- will tell you whether a particular mag-
is connected to the PWM (pulse-width tion. This means that you have to wind net is suitable. With an applied volt-
modulated) output of the microcontrol- the right coil on the right core and use age of 12 V, the coil should be able to
ler via a UL2003, this is done by chang- a magnet that is as small and light as lift the magnet from a height of at least
ing the duty cycle. The pulses are in- possible, but also strong. And you have 3 cm, but 4 cm or more is better.
tegrated in the ferrite core and coil to to adjust the device for a suitable levi-
yield an average current level. tated distance. A ferrite rod such as is commonly
found in medium-wave radios is used
Figure 2 shows the structure of our pro- Another difficulty is that the output for the coil. It should have a diameter
totype. The Hall sensor is connected to voltage of the sensor is not propor- of 10 mm and a length of 80 to 100 mm.
ADC6. The PWM output on PD6 drives tional to the distance between the coil Don t try to rush things when con-
one or more inputs of the ULN2003 and the magnet. Nonlinear controlled structing the coil. As you can see from
power stage. The coil is connected be- systems can lead to stability problems. Figure 3, you start by sliding a length
tween the open-collector outputs and On top of this, the magnetic field of the of heat-shrink tubing over the ferrite
+12 V. It is important to connect pin 8 lifting coil also affects the sensor. The rod (a) and shrinking it in place (b).
to K6 so the internal protection diodes severe requirements imposed by the You can also use electrician s tape in-
in the ULN2003 can limit the induc- controlled system make the job of the stead. After this, you can start wind-
tive spikes from the coil. Pushbutton controller more difficult. Here a bit of ing the coil (c). It consists of four layers
switches S1 S3 are used to configure help in the form of damping can t hurt. of 400 turns each, wound with 0.2-mm
the control parameters. This lets you It arises in a rather unobvious manner enamelled copper wire. You can wind
raise or lower the levitation position due to the aluminium heat sink, under the coil entirely by hand, or you can
of the magnet by up to 10 mm. Alter- which the sensor is mounted. Every use an electric drill running at a very
natively, you can use an RC5 infrared motion of the magnet creates an eddy low speed (d). After you finish wind-
remote control unit to operate the de- current in the aluminium, and this pro- ing the coil, secure both ends with
vice via an IR receiver connected to the duces an opposing magnetic field. heat-shrink tubing (e), making sure to
circuit. The parameters are constantly In this way, magnet oscillations are feed out the free ends for the leads (f).
shown on the LCD display. damped by eddy-current losses. Finally, you can fit another length of
heat-shrink tubing over the entire coil
to protect it (g).
General requirements Magnet and coil
Making a magnet hover in the air is not The magnet must be very light and If you want to avoid counting turns
a trivial task. If it comes too close to very strong. A neodymium magnet and would rather wind the coil helter-
the coil, it will immediately be pulled with a mass of less than 0.3 g is quite skelter , you can wind the ferrite rod
all the way to the coil, and the control- suitable. We used a type Q-CDM50- over a length of 50 mm with 0.2-mm
ler can t do anything to stop it. This G from www.supermagnete.de (mass copper wire until the winding reaches
means that the coil must be mounted 0.23 g) in our various prototypes. An- a diameter of 18 mm. The coil will then
at a sufficient height. On the other other potential source of small, strong have a resistance of 40 to 50 , so the
52 elektor - 9/2008
current will not exceed 300 mA with of a third hand (soldering aid) to hold was fitted to the rod, and the coil was
a 12-V supply voltage (this only holds the coil for initial testing. This makes it clamped to the bracket. The details are
true for DC current). When the coil is easy to adjust the height to the proper shown in Figures 5a d.
driven by the PWM output of the pro- value (Figure 4).
cessor, amplified by the ULN2003, the After the coil has been secured, you
current is pulsating DC instead of pure can connect everything to the proto-
Practical aspects
DC. The average value of the current is typing board and start your levita-
thus less, and the coil characteristic is Our prototype (see the photo at the tion tests. Two ready-made sample
similar to that with AC operation, with head of the article) was built around programs are available on the Elektor
the result that a distinctly lower cur- an aluminium heat sink with the sen- website for downloading. One of then
rent flows through the coil. sor mounted underneath. A brass rod was written in Code Vision, and the
This completes the coil. After you have was fitted to the heat sink, and the other in BASCOM.
carefully protected the leads and the wiring that conducts the current to
ends of the coil with electrician s tape, the coil was routed along this rod in The best approach is to start with the
you can simply use the alligator clips a suitable manner. A plastic bracket C program, since it shows all the par-
PID controllers
Our objective here is to use an electromagnet to attract a permanent magnet exactly enough to levitate it at a particular height. As the magnet le-
vitation system is an unstable, nonlinear controlled system, it must be stabilised as well as regulated. We use a PD controller for this purpose. The
task of a closed-loop controller is to continually and independently control a physical quantity in order to maintain a specified setpoint value in
our case the magnet position and eliminate the effects of disturbances. For this purpose, the controller constantly compares the actual value (the
position of the magnet) with the setpoint value (the desired position of the magnet). The control error determined in this manner is used to gene-
rate the control output, which acts to minimise the control error when the control loop is in balance. However, it takes a certain amount of time for
a system of this sort to respond and for the control output to take effect, and for this reason it must overreact at first and then underreact imme-
diately afterward in order to avoid overcompensation that would cause control failure. This requires the control output to have a damping effect,
depending on the system characteristics. The behaviour of the controller is described by differential equations.
The magnitude of the P component varies in proportion to the control error (difference between the actual value and the setpoint value). This only
affects the proportional gain factor.
The D branch of a controller is a differentiator that must always act together with the P component (or the I component). The D component arises
from variations in the control error over time and is multiplied by the integral action time. It does not depend on the control error, but instead on
the rate of change. A large integral action time cause a large change in the control output and often causes instability in the control loop.
An integral component is used when the control error must reduced to zero (or as close to zero as possible). It is not used here because the levita-
tion device always works with a control error and only the control gain is adjusted. The slope of the control curve decreases as the distance from
the sensor increases, which is offset by increased gain. This compensates for the nonlinear characteristic of the controlled system.
Clear Down , Compare B Pwm = Clear Down
Listing
P = 0.1
Example BASCOM PD controller
D = 60
Atm18 PD regulator
Do
S1 At Pb3 = Up
If Pinb.3 = 0 Then P = P + 0.0002
S2 At Pb4 = Down
If Pinb.4 = 0 Then P = P - 0.0002
X = 0
$regfile = m88def.dat
For N = 1 To 8
$crystal = 16000000
X = X + Getadc(6)
Next X
Dim N As Byte
X = X / 8
Dim X As Integer
Dim Y As Single
If X < 512 Then X = 512
Dim Z As Single
Xp = X - 512
Dim Xold As Single
Xp = Xp * P
Dim Xp As Single
Dim Xi As Single
Xd = X - Xold
Dim Xd As Single
Xold = X
Dim P As Single
Xd = Xd * D
Dim I As Single
Dim D As Single
Y = Xp + Xd
Y = Y / 2
Config Adc = Single , Presca-
If Y > 255 Then Y = 255
ler = 32 , Reference = Off
If Y < 0 Then Y = 0
AD-Wandler starten
Start Adc
Pwm0a = Int(y)
Config Timer0 = Pwm , Presca-
Loop
le = 1 , Compare A Pwm =
9/2008 - elektor 53
PROJECTS MICROCONTROLLERS
ameters on the display. Right after you
a
switch on the supply voltage or reset
the circuit, no current flows through
the coil because the proportional factor
of the controller is zero. Place the mag-
net above the sensor, orient it to obtain
a maximum reading for the displayed
Pv value, and press button S1. This
should cause the current to increase.
You can also see this from the increas-
b ing brightness of the LEDs on the out-
puts. If nothing happens, the magnet is
probably the wrong way round. Turn it
over and repeat the experiment.
The longer you press S1, the more the
coil current will increase. Suddenly the
magnet will start to rise and then re-
Figure 4. A simple experimental setup.
main suspended in a stable position.
You can press S1 to make it rise even
higher. If you press S1 and S2 at the
c
same time, it will drop gradually. At
some point, you will doubtless overdo Hall sensor data acquisition and tim-
the levitation height and the mag- ing generator
net will fly up to the ferrite rod with The A/D converter is used to acquire
a bang. Now you know the maximum the Hall sensor data and as a timing
levitation height. You can probably in- generator. Eight sensor readings are
crease the levitation height slightly by acquired in an interrupt routine within
carefully adjusting the position of the 1 millisecond. After this the adc_
solenoid coil. The coil should be just ready flag is set. The main program
d
high enough that it can still lift the loop uses this flag for synchronisation.
magnet from the surface of the heat The function adc_get_average() cal-
sink.. S1 adjusts the proportional fac- culates the average of the eight sen-
tor of the controller, which effectively sor readings, which forms the current
means the control gain. You can also actual value for the PD controller. This
use S3 to alter the proportion of the averaging suppresses noise on the
differential component, which is im- measured signal.
portant for stability. However, in most
cases the default value is suitable. Controller
e
If the magnet refuses to lift, the direc- The PD controller is recalculated 1000
tion of the magnetic fields may be to times each second. Due to this con-
blame. Try reversing the polarity of stant time interval, the control algor-
the coil. You can also use a voltmeter ithm does not have to calculate the
to check the output voltage of the sen- time, which saves processing time.
sor. It should be close to 2.5 V with no The average sensor value is first cal-
magnet present, and the value with the culated in the function mlc_update .
magnet lying above the sensor should The P component is calculated from
be more than 4 V. Some other possibili- this actual value. The D component is
ties are that the magnet is too weak or calculated as the difference between
f
too heavy. However, this should have the previous and current actual values.
already been sorted out by the initial The control output (the pulse width of
test without the controller. the PWM signal) is formed by adding
the two components.
Actuator
MLC in C
Here the actuator for the controlled sys-
The C program for the magnet levi- tem is the electromagnet in the form of
tation controller (MLC) is very large a ferrite-core coil. A PWM signal with
g
and can only be described here in a pulse rate of 32 kHz drives the power
general terms. stage (ULN2003). The coil is switched
to ground. Thanks to the high PWM
frequency and the large inductance of
Figure 3. Coil construction stages: ferrite rod with heat-shrink
the coil, the coil current is strongly fil-
tubing (a) shrunk onto the ferrite rod (b); start of coil
tered (integrated). This yields a con-
winding (c); fully wound coil (d); coil ends covered with heat-
stant magnetic field with a low ripple
shrink tubing (e) and with the leads fed out (f); finished coil
covered with heat-shrink tubing (g). component.
54 elektor - 9/2008
a b
Figure 5. Details of the prototype assembly: (a)base plate (aluminium heat sink), (b)Hall sensor, (c)brass rod with coil leads, (d)coil bracket with cable ties.
c d
Display output the control loop the magnet exactly above the sensor
To avoid reducing the control frequen- 5. Start the next control cycle by positioning it to obtain maximum
cy as a result of time-consuming dis- at step 1 coil current.
play outputs, the outputs are divided
into many individual jobs. The function RC5 control The controller performs its calculations
mlc_write_lcd() uses a state machine With an IR receiver connected, you can with real numbers (single precision).
to perform a single display output in use an RC5 infrared remote control unit Here again the actual value is obtained
each control cycle. to operate the device remotely. Button by averaging eight individual readings.
1 increases the P value, while button 4 The controller can only use the range
Control process decreases it. Button 3 increases the D between 512 and 1023. The lower the
After the individual modules have been value, while button 6 decreases it. In ad- magnet position, the higher the meas-
initialised, the same process is ex- dition, button 0 acts an emergency stop ured value. The measured value is mul-
ecuted repeatedly in an endless loop: and causes the P value to be set to 0. tiplied by the P factor to yield the set-
ting for the PWM value. The system
1. Update the control loop: would also work without a D compo-
BASCOM example
mlc_update(); // Update magnet nent, but the motion is damped if this
levitation control The Basic program (see listing) has in- component is added. If the magnet ris-
2. LC display output: tentionally been kept simple, so it does es quickly, the controller anticipates an
mlc_write_lcd(); // Do a single not include the LCD and remote control imminent overshoot and reduces the
LCD operation functions. Only the P factor (and thus current accordingly.
3. Scan control parameter buttons: the effective levitation height) can be (080359-I)
mlc_scan_buttons(); // Check the adjusted using the S1 and S2 buttons.
Assembly note
Kp and Kd pushbuttons When the program is started, P is as-
4. Synchronise with A/D converter: signed the value 0.1 to provide a cer- A parts kit with a ferrite rod, HAL815 and
while (!adc_ready) // Synchronise tain amount of gain so you can place magnet is available from www.elektor.com.
9/2008 - elektor 55
Wyszukiwarka
Podobne podstrony:
ATM18 On the AirOEiM AiR Przykladowy EgzaminHeadlights, Pickup with daytime running lightPytania na test z AIR v217 Benthic macroinvertebrates as indicators of water quality386 Homemade Light BulbsAS 801322 The climate of Polish Lands as viewed by chroniclers, writers and scientistsOblicza zdrady lightVisual Resolution in Coherent and Incoherent LightMONEY AS DEBT 2Instrukcja naprawy Air Top 3500ST?więcej podobnych podstron