# What's the best solution for creating a magnetic field around a small cylinder?

I'm a beginning electronics hobbyist so forgive the naive question.

I'd like to have a small cylinder (1cm radius, 3-4cm length) where I could control a magnetic field around the cylinder with voltage.

Basically, if you were looking down at the circle, I would like to control the clock's hand position magnetically. Is that possible with inexpensive electronic components?

• this looks like an XY question ... asking a question about a percieved solution to an unspecified problem, instead of asking a question about the problem ... what are you trying to do? Mar 17, 2023 at 15:26
• Ditto the above. State what are you trying to do (rather than how you are trying to do it). Mar 17, 2023 at 15:36
• So, say you put a compass needle into this device; you want to be able to control its angle (in any direction within a plane), independent of any background field (simply to say, the compass isn't merely pointing in its natural (Earth's magnetic field) direction)? Mar 17, 2023 at 15:55
• You want a rotating mag field like this? en.m.wikipedia.org/wiki/Rotating_magnetic_field Mar 17, 2023 at 18:32
• @LucianThorr I think the answer you have is correct if there is only one magnetized clock hand to control. (Second hand?) Is that all you needed? (It can be done without DACs or an MCU, by the way -- old school using analog.) You should want to get out a proper log book and set down and work out the theoretical requirements for any design, make predictions in the log book, perform experiments, and then compare those with the predicted results, re-evaluate and re-attempt, etc. It's good practice to get into, if that's not already the case. Mar 17, 2023 at 19:28

Required geometry is two loop coils, wound longwise around the cylinder:

The windings don't need to cover the top/bottom of the cylinder, they can make a semicircle around to the other side; in that case, group half the turns to one side, and half to the other, so equal numbers of turns make the shape of a full circle on the face but half are carrying current counterclockwise the other half, thus canceling out their field contributions.

This is precisely how an AC motor is wound, albeit in more sections, which gives higher efficiency (efficiency probably won't matter for "twisting a compass needle" sort of applications). You could just as well open up a three-phase two-pole motor, remove the rotor, and use the space within -- with suitable drive of course (namely much lower voltage, as it won't handle rated voltage without the original rotor in place).

To run from an MCU, set up the following system:

In software: generate quadrature i.e. sine and cosine values. These are either driven by an angle setting, or the angle advances at a regular rate (consider a DDS algorithm) to get some spin rate. Or maybe you want to put acceleration or funny waveforms or whatever into it, you can do that at this point as well; you're just inputting an angle in any case.

Send the sin/cos values to a pair of DACs. They will need to be either bipolar output range, or offset around a mean value (in which case add the necessary offset in software). (If you don't need rapid changes, you can use PWM outputs, with an adequately low cutoff lowpass filter to remove most of the ripple.)

Wire the DACs to a pair of transconductance amplifiers (i.e., voltage input, current output). These should be bipolar, and can be single op-amps for example. Power op-amps may be used for additional current capacity.

You'll need either a bipolar power supply, or differential-output amplifiers (or pairs of single-ended type amps, set up to generate complementary outputs i.e. one inverts the voltage of the other) to drive the coils.

What this does:

At the center of each loop, a magnetic field is generated, pointing perpendicular to the plane of the coil. Magnetic field can point in any direction, between all three axes -- it's a vector. Two coils are thus required to generate a field in any direction in one plane, or three to point in any direction, period.

The magnitude (strength) of the field is the sum of applied fields. If you have coils in the same (spacial) direction but opposite direction of current flow, they cancel out; if you have coils at perpendicular angles, the field is the vector sum of their contributions; if the coils are identical (same dimensions, turns, and applied current), and 90° apart, then the vector will point at 45° with magnitude $$\\sqrt{2}\$$ times a single coil's strength.

Because the angle is, well, an angle, and because the magnitude depends on applied fields in this way, the smoothest motion is had by applying sine waves to each coil, with one being phase-shifted 90° (hence, sine and cosine). The simplest (naive?) approach would be to set one coil to ±max, and vary the other linearly, then set the other to ±max and vary the one, etc.; but this describes a diamond, not a circle, so the angle won't be proportional to the linear fraction, and the magnitude will vary (not that a compass needle will notice, but the varying strength has implications for the smoothness of rotation, and hence is carefully controlled in practical motors).

Or, if you don't care much about smoothness, and want to optimize for speed -- or are going fast enough that smoothness doesn't matter anyway -- the sin/cos waveforms can be smashed into square waves, and you get a quadrature pulse sequence, just as is used to drive a stepper motor (something else to read up on, perhaps).

With the magnetized rotor, this is a PMAC or synchronous machine, by the way!

• Thanks Tim, this is (I think) exactly the solution I was looking for. I had imagined something with many loops in each direction, I didn't realize that I could get 360 degree control with 2 perpendicular loops. That makes this MUCH more feasible. Mar 17, 2023 at 19:00