Levitating glass

Hi,
I’ve spent a lot of time on magnetic levitation and I’ve found my findings below.

step one, something about the theory of how it all works:
The field of neodymium magnets creates a „magnetic hemisphere“ along which the floating object (magnet) moves. The coils only keep the levitating magnet in the desired position.

The position of the levitating magnet is sensed by two Hall probes. The signal from the probe is amplified using an amplifier and then evaluated using stm32. According to the evaluation, a reaction occurs that brings the levitating magnet back into position.

So what will we need for this:

How connect:

step 1: supply

Stm32 can supply a maximum of 5V. For that reason, we will use a voltage stabilizer 7805C with which we will adjust the voltage to 5V and thus power the stm32 board. Capacitors in the circuit stabilize the voltage when the current drawn changes. Using a voltmeter, we can verify that the circuit is connected correctly.

connecting 7805C
stabilizer 3,3V

step 2: output to mosfets

connecting to stm seems to be random but it’s not. Pins B5,B7,B11,B15 are chosen for the purpose of appropriate chip power distribution. But we’ll get to that later.

step 3 measuring

To detect the position of the magnet, we will use a differential amplifier, which will take the signal from the Hall probe and subtract from it the voltage entering the probe. The resulting difference will then be amplified and sent to our stm32 board where we will process it.

connecting the amplifier

The amplifier must not be powered with a value greater than 3.3V, because then it could damage our stm32 board. Most pins are only 3.3V tolerant.

stm32f103c8t6 diagram

The Hall probe must be powered by a voltage greater than 4.5V. The output from the probe is connected to the amplifier.

conecting hall probe

This completes the wiring of the main part of the circuit. but I would still add a few control and communication elements.

  • controller with buttons
  • serial port connection connector
    In this case, I used quite a few non-standard RJ45 connectors.
button connecting

B14 = +
B13 = –
B12 = change

controller with buttons
box for connecting

For easier tuning of the assembly, we will connect the controller in parallel to the running of the loop and thus it will be possible to change the selected running values. We won’t have to re-upload the entire program to the stm chip every time. The RJ45 connectors are not important for the connection. I only used them so that the cables could finally be disconnected. One is to connect the controller and the other is to connect the serial port for terminal output and ST-link.

After complete wiring it could look like this

full conection

step 4 programing

I used STM32 Cube IDE 1.7.0 for programming, it’s free. STM32CubeIde_download

The disadvantage is that programming is more demanding. On the other hand, it has a lot of advantages that the arduino didn’t offer me. Here I can work with bus frequency and adjust the control exactly to my liking. The biggest bonus is in the use of DMA. Using DMA, I can write values to the terminal without slowing down the loop. Without the use of DMA, the running of the loop will be suspended for the time necessary to write out the values via the serial port. In the same way, I can work with the flags of individual events here.

Download:

source code_download

step 5 tuning:

For successful tuning, I recommend proceeding by individual axes. Break the circuit of the Y-axis coils and tune only the separate X-axis.
If I connect the P9 port output to the usb serial RxD, then I can monitor the current setpoint value. I am using the arduino programming console to monitor the data.

Every time the TIM4 value overflows, data is written to the console using DMA. So the thread will not be delayed, but the DMA will do the work.

To begin with, I recommend setting the setpoint X value to approx. 1500 and then using the trimmer to fine-tune so that the magnet is in the middle between the coils. The setpoint value is not fixed. Based on the evaluation of the number of impulses per coil, the setpoint is shifted so that one of the coils is not overloaded. If I disconnect all the coils and hold the magnet still in the middle, the value I see on the terminal should gradually adjust.

So I don’t see the current value from the hall probe in the console, but the currently set setpoint value in the program. For the next upload of the program to stm, it is a good idea to overwrite the value according to the last one in the console. That is, if I don’t move the trimmer.

In the case of connected coils, it is necessary to monitor the temperature. If the magnet does not oscillate in the middle, one of the coils is overloaded and thus burns the coil after some time. I recommend using sources up to 2A.

If you like my page and instructions, I would be happy for a comment or share. 🙂

Project completed

8
2

Like

18
1

help:

How set GPIO, CubeIDE

How set GPIO