Understanding the hall sensor input matrix

 We're using "multiplexing" to read our grid of 16 hall effect sensors.

This means we don't need to use 16 individual input pins for reading inputs (which would just about max out an Arduino, and would be too many pins for a NodeMCU ESP8266 type microcontroller).

Instead, we split our grid into "rows" and "columns".

Then we activate each row, and read the values from each column. This means we need four i/o pins for the rows (outputs) and four i/o pins for the columns (inputs). Let's look a little closer....



Each hall sensor needs power (3.3v-5v supply) a ground connection and has a "floating" signal pin.
When a magnet is presented to the sensor, the signal pin is forced "low" (to ground).
When the magnet is removed, the signal pin is left floating (note, it is not driven "high" but allowed to "float" to whichever default value we want it to take - the technical term is "open drain" but we don't need to worry about that right now).

Because the signal is "open drain" and isn't driven both high and low, it means we can connect multiple signal lines together without fear of damaging any of the sensors if there is a "clash" (if driven both high and low, and one sensor was driven high and another low, this could cause damage to the hardware - by driving them low and then allowing them to float, we may get corrupted data if we read the devices incorrectly, but we won't damage the hardware).



In this layout, we've created a criss-cross of copper tape, separated by bands of masking tape (to act as an insulator between layers). You can see that all the signal pins for sensors 1-4, sensors 5-8, sensors 9-12 and 13-16 are all connected together.
Now, if all sensors were powered at the same time, and we got a "low" signal on the first (yellow) row, we couldn't tell which sensor had activated - yes, at least one of 1, 2, 3 or 4 (possibly more than one at the same time) but it would be impossible to tell which sensor had activated.

So instead, we power each column, one at a time.
So let's say we put power on just the first column (closest to the left). If we get a low signal on the first row, it can only be sensor number one that generated the signal (the signal pins on sensors 2, 3 and 4 would be "floating"). The only active sensor on the top row is sensor number one; so if there's a signal on top row, it ca only have been generated by sensor number one.

Similarly, if we get a low signal on the second row (from the top) then this must have come from sensor number five. A low on row three means sensor number 9 activated, and a low on the bottom row means sensor 13 was triggered.

Next, we remove the power from the first column (allowing the signal pins on all these sensors to float) and apply power only to the second column. Reading the state of the signal lines (low or floating) for each row will give us the state of each of the sensors 2, 6, 10 and 14.

Repeat for the third column, and we get the state of sensors 3, 7, 11 and 15.
Lastly power the fourth and final column and we know the state of sensors 4, 8, 12 and 16.

By rotating power through each column quickly, we can read the entire grid of sensors in a few tens of milliseconds (allowing around 10ms between powering each column, to allow things to stabilise so we get more accurate readings from each sensor).

This is how we are able to read a grid of 16 sensors using just 8 i/o pins (four pins to power each column, four pins to read each row).

Comments

Popular posts from this blog

The ESP8266

Creating our first light-up 4x4 panel