This is only a preview of the June 2024 issue of Silicon Chip. You can view 57 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Arduino Clap Light":
Items relevant to "ESR Test Tweezers":
Items relevant to "MicroMag3 Magnetic Sensor":
Items relevant to "USB-C Serial Adaptor":
Items relevant to "DC Supply Protectors":
Items relevant to "WiFi DDS Function Generator, Pt2":
Items relevant to "Arduino bin reminder":
Purchase a printed copy of this issue for $12.50. |
Using Electronic Modules with Jim Rowe
MicroMag3 3-axis
Magnetic Sensor
The MicroMag3 can measure the strength of a magnetic field in
three orthogonal axes (eg, North-South, East-West and Up-Down).
In effect, it combines the functions of a magnetic compass and an inclinometer.
T
he MicroMag3 can measure
magnetic fields over a wide
range of strengths with high resolution and operates from 3V DC, drawing less than 0.5µA of current. It has
SPI (serial peripheral interface), so it
can communicate with just about any
microcontroller.
As you can see from the photos,
this module is quite small, measuring
only 25.4 × 25.4 × 19mm, with the last
dimension including both the Z-axis
sensor mounted vertically on the top
of the PCB and the two 7-pin headers
under the sides of the PCB.
Manufactured by US firm PNI Sensor Corporation based in Santa Rosa,
California, it uses a patented technology called Magneto-Inductive Sensing.
The module is specified as being
able to measure magnetic fields over a
wide range from -1100µT to +1100µT.
1T = 1 tesla = 10,000 gauss = 10,000G.
So 1100µT = 1.1mT or 11.0G. The
measurement resolution is specified
as 0.015µT or 0.00015mG.
The MicroMag3 and later versions
using the same technology have found
their way into a significant number
of navigation devices for automotive,
marine, aeronautical and even space
vehicles.
Before we delve deeper into how
the MicroMag3 works and how it
can be used, we should mention its
availability. We bought a couple of
the modules from Altronics, which,
at the time of writing, has them available (Cat Z6300) for $5.90 each, plus
delivery costs.
It looks as if Altronics obtained them
from the US firm SparkFun Electronics, but when you go to their website
(www.sparkfun.com), they advise
that the product has been ‘retired’
from their catalog and is no longer for
sale. Then, if you go to the PNI Sensor
Corporation’s website (www.pnicorp.
com), they have dropped all references
to the MicroMag3 and only provide
data on later versions.
You can still find the data sheet for
the MicroMag3 on the SparkFun website if you go to www.sparkfun.com/
products/retired/244
So Altronics is the only current supplier of the MicroMag3 that we could
find, suggesting that if you want to get
hold of one, you may have to be quick!
How it works
64
Silicon Chip
Fig.1: the MicroMag3 sensor
module uses a PNI 11096 ASIC
(application-specific integrated
circuit). The upper right-corner
of the diagram shows how the
sensors are orientated.
Looking at the photos, you will see
a single IC on the PCB, in a compact
28-pin SMD package. It is labelled
PNI 11096 and is described in their
data sheet as an ‘ASIC’ or application-
specific IC.
Apart from some SMD resistors and
capacitors, the only other components
on the PCB are the three tiny magneto-
inductive sensors. Labelled MS1, MS2
and MS3, these each measure only 6.0
× 2.1 × 2.21mm. They are used to sense
and measure the magnetic field in one
of the three axes.
Australia's electronics magazine
siliconchip.com.au
Fig.1 shows the circuit for the
MicroMag3 module, with the PNI
11096 ASIC in the centre and the three
magneto-inductive sensors to its right
– each with a pair of biasing resistors.
Along the bottom are the pins of the
7-pin header provided to allow control
by and communication with an MCU
(microcontroller unit).
The first three pins (SCLK [serial
clock], MISO [master-in, slave-out]
and MOSI [master-out, slave-in]) are
the SPI interface, while the other pins
control the ASIC. Up the top are the
pins of the second 7-pin header, with
only two used to supply the ASIC with
3V DC power.
At upper right in Fig.1 is a small
diagram showing the way the three
sensors are configured to measure
the three magnetic axes. The MS1
sensor measures the field in the X or
North-South axis, MS2 measures the
field in the Y or East-West axis, while
MS3 measures the field in the Z or
up-down axis.
According to the PNI data, the sensors are arranged in a south-west-down
or ‘SWD’ configuration. We’ll explain
the significance of that later on.
Before we look at how the three
magneto-inductive sensors measure
surrounding magnetic fields, here’s
a rundown of the basic measurement
procedure, shown graphically in Fig.2.
Bear in mind that the ASIC can only
measure via one sensor at a time.
First, the controlling device drops
the voltage on the ASIC’s SS (slave
select) pin to indicate that a measurement is to start, then it sends a short
positive pulse (>100ns) to the RESET
pin. After that, it sends an 8-bit command via the MOSI pin, specifying the
sensor to be used (MS1, MS2 or MS3)
and the measurement period.
The measurement period specifies
how many oscillator cycles should
be used for the measurement, with
choices ranging from 32 to 4096 cycles.
The measurement resolution increases
with the number of cycles, but 2048
cycles is usually sufficient.
The next step involves the MCU
either waiting for the ASIC to pull up
the voltage on the DRDY (data ready)
pin, or just waiting long enough for
the ASIC to have made the measurement and have the data available. In
either case, the MCU must then send
out 16 clock pulses on the SCLK line,
to receive the 16-bit measurement data
via the MISO line.
Finally, the MCU raises the voltage
on the SS pin, to signal the end of that
measurement sequence.
Making measurements of the field
intensity in all three axes requires
three of these sequences to be completed, one for each axis.
Magnetic sensing
Now let’s look at how the magneto-
inductive sensors are used to make
the measurements. Each sensor consists of a solenoid coil wrapped
around a very high-permeability magnetic core.
As shown in Fig.1, each sensor coil
has four connections to the ASIC. So
the MS1 coil has direct connections to
the APXIN and ANXIN pins, plus connections to the APXDRV and ANXDRV
pins via the two 62W series resistors.
The other two sensor coils are connected to the corresponding pins for
the Y and Z axes.
Inside the ASIC, each sensor’s coil
is used in a simple L-R relaxation
oscillator, with its inductance determining the oscillation frequency. As
its inductance varies according to the
The MicroMag3 module shown at
twice actual size.
magnetic field passing through its
core, the external field can be measured by alternately driving a direct
‘bias’ current from one end of the
coil to the other and then back the
other way.
When there is no external magnetic
field, the sensor coil’s inductance will
be identical when the bias current
flows in either direction because the
inductance will be swinging symmetrically on either side of the core’s ‘zero
field’ peak. As a result, the oscillator
frequency will be the same in both
directions.
But when there is an external magnetic field, the inductance and frequency will differ depending on the
direction of bias current flow.
This allows the PNI 11096 chip to
measure the strength of the external
field by measuring the time taken to
complete a fixed number of oscillations in the ‘forward biased’ and
‘reverse biased’ directions, and
taking the difference between the
two. That is the principle of PNI’s
magneto-
i nductive sensing technology.
Fig.2: the microcontroller sends a command byte on the SPI bus, then waits a certain period before reading back 16
bits of measurement data.
siliconchip.com.au
Australia's electronics magazine
June 2024 65
If that explanation isn’t clear
enough, there is a PNI ‘white paper’
called Magneto-Inductive Technology Overview, written by Andrew
Leuzinger and Andrew Taylor, which
you can download as a PDF file from
several sources on the web. I found it
at siliconchip.au/link/abs5
Connecting it to an Arduino
Fig.3 shows how easily the module
can be connected to an Arduino Uno.
It should be just as straightforward
to connect it to any other versions of
the Arduino, including the new Uno
R4 Minima, or many other microcontrollers such as the Micromite or
Maximite.
All you need to do is connect the
module’s VDD and GND pins to the
+3.3V and GND pins of the MCU, then
connect its SCK, MISO and MOSI pins
to IO13, IO12 and IO11 of the MCU.
Those are the pins that the Arduino’s
SPI library expects you to use for SPI
communication.
The only other connections required
are those for the module’s SS, DRDY
and RESET lines, which, as shown in
Fig.3, connect to pins IO7, IO6 and
IO5, respectively.
Note, however, that if you use our
sketch to control and communicate
with the MicroMag3, you don’t need
to connect the module’s DRDY pin to
the Arduino’s IO6 pin. We found it
easier to rely on a time delay before
requesting the measurement data, as
should become clear shortly.
Software
We need a sketch to use the MicroMag3 module with an Arduino, so I
looked around the web to see if suitable sketches had already been written. I found a couple, but they both
used a ‘bit-banging’ approach, rather
than using the Arduino SPI library
and the microcontroller’s built-in SPI
peripheral. That seemed a bit clumsy,
so I decided to see if I could come up
with a more elegant solution.
Producing a working sketch turned
out to be more work than I anticipated.
The main hurdle I encountered was in
trying to use the module’s DRDY pin
to sense when the module had measurement data available. That is the
approach recommended in PNI’s data
sheet, by the way.
After many puzzling ‘hung sketch’
results, I tried analysing the module’s operation with a DSO. I discovered that the module’s DRDY did go
high after each measurement, but only
after about 36ms (milliseconds). That
seemed to be too long of a wait.
After discussing this with my Silicon Chip colleagues, Nicholas Vinen
and Tim Blythman, we concluded
that it would be better to forget about
using the DRDY line and simply wait a
little longer than the expected processing time before requesting the measurement data. Suddenly, the sketch
sprang to life!
The sketch then printed the field
measurements for the three axes via
the Arduino IDE’s Serial Monitor.
Encouraged by this success, I added
a section to work out the module’s
‘compass heading’ from the X-axis and
Y-axis readings.
It was clear that I would need an
arctangent function to work out the
compass heading from the X-axis
and Y-axis readings, yet there seemed
to be no such function listed in the
Arduino Language Reference. Thinking I might have to include a special
‘maths’ library to get one, I went onto
the Arduino forum to find the answer.
I discovered that you didn’t need
a special library because the existing
library includes two such functions,
even though they were not listed or
even referred to in the Language Reference. The functions are atan() and
atan2(), with the second able to work
out angles in all four quadrants.
Editor’s note – those are standard
C library functions from the “math.h”
include file, which might explain why
they are available but not listed in the
Arduino documentation. Arduino is
built on C++, which is built on C, so
you can access those underlying functions if necessary.
Fig.3: how to
connect the
MicroMag3 module
to an Arduino
Uno or similar
microcontroller.
Note that if you’re
using our example
sketch, then the
DRDY pin does
not need to be
connected.
Fig.4: this is the orientation
provided by our demo sketch. It
could be changed with some extra
calculations if required.
66
Silicon Chip
Australia's electronics magazine
siliconchip.com.au
Once I understood that, it wasn’t too
long before I could get the compass
heading part of the sketch working.
There was just one minor complication: the MicroMag3 module’s X
axis is aligned with the white line
with its arrowhead at upper right
on the module PCB, which suggests
that the sketch should read ‘true
north’ when the module is facing
north when pointed in the direction
of the arrow.
However, I could only get the heading function to work correctly once I
reversed the module orientation so
that the end of the PCB nearest the
MS1 sensor and the ASIC is used as
the ‘compass pointing’ end. I suspect
this is because of the way the MicroMag3 is set up with the “SWD” scheme
(south-west-down).
It would be possible to fix that by
adding 180° to the output of the arc
tangent function, modulus 360. Still,
I thought it was simple enough to
use the module’s rear as the compass
pointing end, as shown in Fig.4. Doing
that produces the expected bearings
without any additional mathematical steps.
The resulting sketch file is named
Screen 1: example sketch output
14:20:27.626 -> A sketch to communicate with the MicroMag3
14:20:29.781 -> X reading = 1112
14:20:29.781 -> Y reading = 17
14:20:29.781 -> Z reading = -1375
14:20:29.828 -> Heading = -0.02 radians or 0 in degrees
14:20:29.875 ->
14:20:40.045 -> X reading = 971
14:20:40.091 -> Y reading = -602
14:20:40.091 -> Z reading = -1472
14:20:40.138 -> Heading = 0.55 radians or 31 in degrees
14:20:40.138 ->
14:20:50.355 -> X reading = 826
14:20:50.355 -> Y reading = -764
14:20:50.401 -> Z reading = -1519
14:20:50.401 -> Heading = 0.76 radians or 42 in degrees
14:20:50.448 ->
14:21:05.820 -> X reading = 119
14:21:05.820 -> Y reading = 759
14:21:05.820 -> Z reading = -1576
14:21:05.867 -> Heading = -1.42 radians or -81 in degrees
14:21:05.913 ->
“Silicon_Chip_MicroMag3_control_
sketch_V2.ino” and you can download it from siliconchip.au/Shop/6/330
Screen 1 shows a screen grab of
the Serial Monitor listing when running my sketch, and first pointing
north, then towards north-east (+31°,
and +42°), and then towards the west
(-81°).
The sketch does not provide any
readout of the magnetic field’s inclination, just the Z-axis reading. I will
leave doing that as an exercise for our
SC
readers.
PIC Programming Adaptor
Our kit includes everything required to build the Programming Adaptor,
including the Raspberry Pi Pico. The parts for the optional USB power
supply are not included.
Use the Adaptor with an in-circuit programmer such as the Microchip
PICkit or Snap to directly program DIP microcontrollers.
Supports most newer 8-bit PICs and most 16-bit & 32-bit PICs with
8-40 pins.
Tested PICs include: 16F15213/4, 16F15323, 16F18146, 16F18857, 16F18877,
16(L)F1455, 16F1459, 16F1709, dsPIC33FJ256GP802, PIC24FJ256GA702,
PIC32MX170F256B and PIC32MX270F256B
Learn how to build it from the article in the September 2023 issue of
Silicon Chip (siliconchip.au/Article/15943). And see our article in the
October 2023 issue about different TFQP adaptors that can be used with
the Programmer (siliconchip.au/Article/15977).
Complete kit available from $55 + postage
siliconchip.com.au/Shop/20/6774 – Catalog SC6774
siliconchip.com.au
Australia's electronics magazine
June 2024 67
|