Wiki

This version (04 Sep 2019 20:32) was approved by dmercer.The Previously approved version (03 Jan 2018 19:44) is available.Diff

A Simple Magnetic Proximity Sensor

The Adobe Flash Plugin is needed to display this content.

Introduction

A simple proximity sensor senses how close one object is to another, and can used for many applications ranging from simple detection of open and closed doors and windows to sophisticated high-precision absolute position detectors. They can be designed in a number of ways, one of which involves sensing the magnetic field strength generated by a magnet (often a permanent magnet, but may also be an electromagnet) contained in one of the objects and placing a magnetic field sensor in the other object. The magnetic field sensor output can be linear in which its output voltage is linearly related to the magnetic field strength impinging on the detector, or binary in which the output is in one state when the measured magnetic field strength is greater than a particular threshold, and in the other state when the measured magnetic field strength is less than the threshold. Binary proximity sensors are often used to replace simple position-determining mechanical switches because they have no moving parts to wear or jam, and are therefore more reliable than their mechanical counterparts.

In this lab we generate the magnetic field using a ferrite-core solenoid. A solenoid is a coil of wire that is wrapped in a cylindrical fashion around a core, typically to fabricate an inductor with particular value of inductance, or an electromagnet. The coil can be wrapped around any type of core material, and the strength of the magnetic field generated inside the solenoid is proportional to the relative permeability of the core material. Magnetic field strength in the air surrounding the solenoid is less, since the relative permeability of air is approximately one. Magnetic materials such as iron, cobalt, and neodymium can have large relative permeabilities, and therefore can be used as core materials to develop large magnetic fields, and thereby realize large inductance values. Since the relative permeability of air is very close to one, air core inductors have much lower inductance values than their high-relative-permeability core counterparts. The 100 μH inductor contained in the ADALP2000 Analog Parts Kit can be used to generate a magnetic field that is strong enough to be detected by the AD22151 magnetic field sensor, also contained in the Parts Kit.

The AD22151 magnetic field sensor operation is based upon the Hall effect. The Hall effect is a phenomenon in which a voltage (the Hall voltage) is developed across a material when current flows through the material with a magnetic field present. The Hall voltage is due to the electric field produced by deflection of the moving charges by the magnetic field via the Lorentz force. With the magnetic field pointing vertically with respect to the current, the Hall voltage is perpendicular to the direction of current flow with the positive side to the left of the conventional current flow. (Note that conventional current flows in the opposite direction to that of electron flow.) The Hall effect can clearly be used to measure currents with frequencies down to DC (which is not possible with magnetic-flux-based transformer current sensors) by using a sensitive voltage detector to measure the voltage across the conductor as an indication of current flow. The Hall effect can also be used to measure magnetic fields by producing a constant current in the material and measuring the Hall voltage as a function of the magnetic field. We will use a Hall effect sensor to detect the presence of a magnetic field, as well as see how to deal with some of the non-ideal behaviors in the sensor.

Objective

To study magnetic field generation and detection. To use a solenoid shaped electromagnet to generate the magnetic field and the AD22151 linear Hall-effect-based magnetic field sensor to detect the magnetic field. To use the principles of magnetic field generation and detection to build a simple proximity detector and observe how the detector output voltage increases as the electromagnet moves closer to the sensor. To review bias current, offset voltage, and noise that are present in all electronic circuits. To use a comparator with hysteresis to turn the linear output of the sensor into a binary output, indicating whether or not the electromagnet has passes a particular position threshold, and illuminate a LED as an indication of the electromagnet passing through the threshold. Upon completion of this lab you should be able to describe magnetic field generation, give a basic description of the Hall effect and how it can be used to detect magnetic fields, describe bias current, input offset voltage, and noise in electronic circuits, have a basic understanding of hysteresis and at least one reason it is used, and explain the operation of a simple magnetic proximity detector.

Materials and Apparatus

  • Data sheet handout for the AD22151 magnetic field sensor
  • Data sheet handout for AD8561 voltage comparator
  • Computer running PixelPulse software
  • Analog Devices ADALM1000 (M1K)
  • Solderless breadboard and jumper wires from the ADALP2000 Analog Parts Kit
  • (1) AD22151 from the ADALP2000 Analog Parts Kit
  • (1) AD8561 from the ADALP2000 Analog Parts Kit
  • (1) Green LED from the ADALP2000 Analog Parts Kit
  • (4) 100 Ω resistor from the ADALP2000 Analog Parts Kit
  • (2) 470 Ω resistor from the ADALP2000 Analog Parts Kit
  • (1) 2.2 KΩ resistor from the ADALP2000 Analog Parts Kit
  • (1) 4.7 KΩ resistor from the ADALP2000 Analog Parts Kit
  • (1) 6.8 KΩ resistor from the ADALP2000 Analog Parts Kit
  • (1) 100 KΩ resistor from the ADALP2000 Analog Parts Kit
  • (1) Offset injection resistor from the ADALP2000 Analog Parts Kit -- value determined in experiment
  • (1) 0.1 μF capacitor (marked “104”) from the ADALP2000 Analog Parts Kit
  • (1) 10 μF capacitor from the ADALP2000 Analog Parts Kit
  • (1) inductor from the ADALP2000 Analog Parts Kit, either 100uH (marked 101), 1mH (102), 10mH (103)

Procedure

  1. Construct the following electromagnet circuit on the solderless breadboard
  2. Note that the 100 Ω resistors get very hot due to Joule heating, so avoid coming in contact with them Using 1mH or 10mH inductor will draw less current and make stronger magnetic field.
  3. Refer to the illustration below for one way to install the components in the solderless breadboard
  4. Add the following Hall effect sensor circuit to the solderless breadboard
  5. Refer to the illustration below for one way to install the Hall effect sensor components in the solderless breadboard
  6. Run PixelPulse on the computer and plug in the M1K using the supplied USB cable
  7. Update M1K firmware, if necessary
  8. Connect the M1K to the circuit as indicated in the schematic
  9. Set up PixelPulse to measure voltage on Channel A
  10. Observe and record the DC voltage on Channel A with the electromagnet far from the sensor chip and define this as VOUT,Z
  11. This voltage is ideally mid-supply, which is 2.5V on a 5.0 V supply, but it will differ from mid-supply due to DC offsets in the sensor and op-amp that get multiplied by the op-amp closed-loop gain; the output offset voltage may be changed by adding a resistor R4 between the 5.0 V supply and the op-amp summing node on Pin 6.
  12. Refer to the following schematic for the placement of R4, but do not install any resistor here at this time
  13. Calculate the op-amp closed-loop gain
  14. Our objective is to place the sensor output voltage with no applied magnetic field as close as possible to the lower end of its linear range, which is 0.5 V. We calculate the value of R4 in the next few steps. It's important to note that the 5.0 V supply will actually be at about 4.8 V to 4.9 V due to the IR drop (internal to the M1K) that is produced by the 150 mA current that drives the electromagnet and that the resistor values are limited and have +/-5% tolerances, so the final voltage will not be perfect. We will designate VSUPPLY as the supply voltage and VMID as the mid-supply voltage.
  15. Measure and record VSUPPLY using the M1K
  16. In order to calculate R4 it is necessary to know the currents flowing in and out of the op-amp summing node. The current through R2 is defined as IR2. Under ideal conditions this current would be zero since the voltage on each side of it would be VMID, but there is a small offset voltage between the internal Hall effect sensor output voltage with zero field and the internally buffered VREF. For small gains this voltage can in many instances be ignored, but it must be considered in high-gain circuits such as this one.
  17. Use the M1K to measure and record the voltage at Pin 7 and define it as VREF
  18. Use the M1K to measure and record the voltage at Pin 6 and define it as VCM; this is the common-mode voltage at the op-amp input, and is driven to be very close to the output of the internal Hall effect sensor by negative feedback
  19. Calculate the voltage across R2, VR2, as VR2 = VREF - VCM.
  20. Calculate the current through R2 as IR2 = VR2/235 Ω
  21. Calculate the current through the feedback resistor R3, IR3, as IR3 = (VCM - VOUT,Z)/100 KΩ
  22. Note that these two currents are not exactly equal; can you explain why?
  23. Calculate the amount of voltage shift, VSHIFT, necessary to move VOUT,Z from its current level down to 0.5 V as VSHIFT = 0.5 V - VOUT,Z; note the VSHIFT is a negative quantity
  24. Calculate the amount of additional current, ISHIFT, required through the feedback resistor R3 to shift VOUT,Z to 0.5 V as ISHIFT = VSHIFT/100 KΩ; note that this is a negative quantity because VSHIFT is negative
  25. The current flowing into the summing node through R4, IR4, that is used to create the desired offset is in the opposite direction to that of ISHIFT, so we can write IR4 = -ISHIFT, which is a positive quantity
  26. Calculate the value of R4 by noting that the voltage across R4 is the difference between VSUPPLY and VCM, as R4 = (VSUPPLY - VCM)/IR4
  27. Select a resistor from the kit that is closest to this value for R4; unless the calculated value is very close to a value available in the kit, round up in order to make any error result in a higher output voltage
  28. Place R4 in the circuit as shown in the schematic above
  29. Refer to the illustration below for one way to install R4 in the solderless breadboard
  30. Verify that VOUT,Z has shifted down to approximately 0.5 V, and that there is some error in this due to supply voltage uncertainties, imperfect R4 value, and resistor tolerances
  31. Remove the 0.1 μF capacitor and observe the increase in noise on VOUT,Z; can you explain why this happens?
  32. Replace the 0.1 μF capacitor and observe the reduction in noise on the output voltage
  33. Slowly move the electromagnet close to the top of the sensor chip until the top of the inductor touches the top of the chip
  34. Observe the direction of the change in voltage
  35. Change the orientation of current flow in the inductor if necessary in order to cause the sensor output voltage to increase as the electromagnet moves closer to the sensor (Explain what is happening here.)
  36. Move the electromagnet again such that the top side of the inductor is touching the top if the AD22151 chip and maneuver it to obtain the highest output voltage reading and record this as VOUT,MAX
  37. Take the average of the VOUT,Z and VOUT,MAX readings and record this as VOUT,AVG
  38. Add the following comparator circuit to the solderless breadboard
  39. Refer to the illustration below for one way to install the comparator circuit
  40. Slowly move the electromagnet toward the top of AD22151 sensor and observe position where the LED turns on
  41. Slowly move the electromagnet away from the AD22151 sensor and observe the position where the LED turns off
  42. Notice that the LED turn and turn off behaviors are very abrupt and there is no intermediate state in which the LED appears to be partially on
  43. Monitor the comparator threshold voltage on Pin 3 of the AD8561 on Channel A while moving the electromagnet
  44. Carefully observe and record the threshold voltage at which the LED turns on
  45. Carefully observe and record the threshold voltage at which the LED turns off
  46. Can you explain why there are two different threshold voltages and how having two threshold voltages provides an advantage in this binary proximity detector?

Theory

Most magnetic-field-based proximity sensors use strong permanent magnets to generate the magnetic fields that are sensed, and therefore the sensors only require modest gains in order to output a reasonable voltage. In this lab we generate a relatively weak magnetic field using an electromagnet carrying about 150 mA, and thus require a fairly large gain in the op-amp contained in the Hall effect sensor. Having large op-amp gain introduces a few practical problems. One problem is that the output noise is large. This happens because the noise at the input to the op-amp gets multiplied along with the desired signal in the op-amp and appears at the op-amp output. Another similar problem is DC offset, in which a small offset at the input to the op-amp gets multiplied by the op-amp and appears as a DC offset in the output voltage. The op-amp has an input offset voltage, and imperfectly matched input bias currents that get converted to voltages, and these are reflected by the op-amp gain to the op-amp output voltage. Additionally, the internal Hall effect sensor output offset and internally generated and buffered reference voltage, REF, are not exactly the same. These all contribute to the output offset voltage, and are the reasons why the output voltage is not exactly at mid-supply when no magnetic field is present. We can compensate for these offsets, and even shift the output offset voltage wherever we need to (within the limits of the part) by summing in an offset voltage at the op-amp's summing node.

The summing node of the op-amp contained in the AD22151 is made available on Pin 6, and the non-inverting op-amp input is internally biased at approximately +2.5 V, so it is possible to inject positive or negative current into the summing node in order to shift the output offset level. In this case we desire to shift the output offset down, which requires an injection of current into the summing node. This can also be viewed as summing a positive voltage into an inverting op-amp summing amplifier configuration. With zero magnetic field applied, the voltage across the op-amp gain resistor R2 is ideally zero since the reference voltage VREF and the output of the Hall effect sensor would be the same -- note that the voltage on the op-amp inverting input is driven to be essentially the same as the voltage no the non-inverting input by negative feedback, so the voltage on the inverting input can be viewed as essentially the same as that of the Hall effect sensor output, neglecting the op-amp input offset voltage. The voltage that is essentially common to both op-amp inputs is referred to as the “input common-mode voltage.” There is, however, a small voltage across R2 due to the mismatch between VREF and the op-amp input common-mode voltage. Even though this is a small voltage, it is applied across a small resistance and produces an appreciable current that flows through a large-valued feedback resistor to produce an appreciable shift in output voltage. This is how op-amps work to amplify signal voltages, and why the inverting gain of an op-amp is proportional to the feedback resistance and inversely proportional to the gain resistance. We can determine the current flowing though R2 by measuring the voltage across it and dividing by its value. Most of this current flows through the feedback resistor R3, but a small amount flows into the op-amp inverting input; this small current is the input bias current, and is the reason why the current through R2 is not exactly equal to the current through R3.

Additional current can be added through the feedback resistor in order to shift the output voltage down to the lower end of its linear range of 0.5 V. The amount of current necessary for this can be calculated by taking the difference between the existing output voltage and the desired output voltage and dividing by the feedback resistance. This value of current is then injected into the op-amp summing node through an offset injection resistor R4. The value of R4 is calculated as the difference between the voltage on the input side of R4 (VSUPPLY) and the op-amp input common-mode voltage, divided by the required injection current.

The op-amp is set up as a non-inverting amplifier to the voltage that is output from the Hall effect sensor element. The gain of a non-inverting op-amp, AV,NI, is the ratio of the feedback resistance to the gain resistance plus one. In terms of the reference designators used in the lab, this is AV,NI = 1 + R3/R2. Note that VREF is also summed in an inverting fashion in order to place the output nominally at mid-supply (it is close to mid-supply for the typical small gains that are used when permanent magnets are used as the sources of the magnetic fields). The gain of an inverting op-amp, AV,I, is the negative of the ratio of the feedback resistance to the gain resistance, or AV,I = -R3/R2. The output level with no magnetic field present has been defined by the gain, circuit offsets, VREF, and the offset injection circuitry. The AD22151 output voltage, VO, due to the Hall effect sensor element output voltage, VH, is therefore simply

V_O = V_H(1 + {R3/R2})

The gain from VH to VO is 1 + R3/R2, and in this lab is approximately equal to 427. This is a relatively high gain, which amplifies the noise from the Hall effect sensor element to a level that is visible on the PixelPulse voltage display. Placing the 0.1 μF capacitor across the feedback resistor reduces the non-inverting gain as frequency increases because the reactance of the capacitor decreases with frequency, thereby reducing the overall feedback impedance as frequency increases (the general gain formula for a non-inverting op-amp is AV,NI = 1 + ZF/ZG where ZF and ZG are the feedback and gain impedances, respectively). The feedback impedance can only approach a minimum of zero, and therefore the minimum gain of a non-inverting op-amp is equal to 1 + 0 = 1. This means that the noise from the Hall effect sensor element cannot be attenuated in the non-inverting amplifier. An inverting amplifier, on the other hand, can attenuate signals applied to its input, and is therefore a better configuration to be used in filtering applications. The capacitor across the feedback resistor therefore does help somewhat to reduce noise, but cannot reduce the op-amp gain below one. Removing the feedback capacitor eliminates the high frequency gain reduction, and allows us to see the unfiltered noise on the PixelPulse display.

Now that we have designed and built a proximity detector with a continuously variable output, we can proceed to add a one-bit quantizer, also known as a comparator, to its output to produce a binary proximity detector (the comparator was introduced in the Introduction to Filters lab). The binary proximity detector has two states -- near and not near. The demarcation point between these two states is defined by the threshold(s) used in the comparator design. A comparator is a high gain differential-input amplifier that is designed to be run open-loop, and has an output that is compatible with a particular logic family. Some comparators have single-ended outputs and some have differential outputs. We will use the AD8561 from the parts kit that has a differential output. The differential output is most often used to interface with differential logic, but in this lab we will use it to drive a LED with one output and use the other to implement hysteresis, which will be described later. Note that the LED is being driven by sourcing current in the high output state rather than sinking current in the low state, which is often more advantageous. The AD8561 outputs can source current in the high state as well as they can sink current in the low state, so this configuration was used in order to simplify the hysteresis design outlined below.

A comparator can be viewed as a one-bit analog-to-digital converter that produces one binary state on its output when its input voltage is above a particular threshold and the other state on its output when its input is below the threshold. Simple comparator designs operate by applying a fixed voltage threshold to one of the comparator inputs and applying the input signal to the other. For simplicity, we'll place the threshold on the inverting input. When the input voltage that is applied to the non-inverting input exceeds the threshold voltage on the inverting input by a small amount, the output voltage quickly moves to the high logic state. This happens because the comparator has very high gain and it does not take much voltage across its inputs (often called overdrive) to move the output voltage to either of its limits. As a simple example, applying a sine wave to a comparator with its threshold set exactly at the baseline of the sine wave produces a square wave at the comparator output. Though it may seem that a conventional op-amp could be used as a comparator, this is not recommended for a number of reasons including the fact that op-amp designs include internal compensation that is optimized for closed-loop operation, and that op-amps do not produce standard logic levels on their outputs.

When the comparator input signal is moving very slowly, noisy, or both, the output can chatter between logic levels as the input bounces above and below the threshold. This is an undesirable situation, and can be avoided using hysteresis. Hysteresis is a technique that uses two thresholds instead of one. One threshold is for an increasing input signal and the other is for a decreasing signal. When an increasing signal crosses through its threshold, the threshold immediately changes to a lower threshold, preventing the input signal from re-crossing the threshold due to noise or other fluctuations as long as the difference between the two thresholds is larger than the input fluctuations. Similarly, when a decreasing signal crosses through its threshold, the threshold immediately changes to a higher threshold. The difference between the two thresholds is defined as the hysteresis voltage. The combination of the change in comparator output state used to change the thresholds with the connection between the output and one of the inputs constitutes a form of positive feedback. The thresholds are derived from a voltage divider that is placed between the comparator output and a reference voltage. Often the reference voltage must be derived using an available supply and Thevenin equivalent voltage divider network.

Referring to the comparator circuit above, the reference voltage is generated by the Thevenin equivalent circuit comprised of the 2.5 V supply and the 2.2 KΩ and 4.7 KΩ resistors. The Thevenin equivalent of this circuit is a Thevenin voltage source of approximately 1.7 V in series with a Thevenin resistance of approximately 1.5 KΩ. We can replace the voltage divider with the Thevenin equivalent as shown

The two thresholds can be determined by calculating the voltage on Pin 3 for each of the comparator output states. We will use 3.5 V for the high output state and 0.2 V for the low output state. Using the voltage divider rule, the high threshold is approximately 2.0 V and the low threshold is approximately 1.4 V, giving about 600 mV of hysteresis.

When moving the electromagnet close to the sensor, the LED should abruptly turn on with no chatter, and abruptly turn off when the electromagnet is moved away from the sensor. The comparator output on Pin 8 can be monitored with the M1K to verify this. The thresholds can also be experimentally verified by observing the voltage on Pin 3 while moving the electromagnet close to the sensor and away from the sensor. As would be expected, the actual thresholds will deviate somewhat from the calculated values due to uncertainties in the comparator output voltages and resistor values.

Observations and Conclusions

  • A magnetic field can be generated using a solenoid as an electromagnet
  • The Hall effect is a phenomenon in which a current passing through a material in the presence of a magnetic field generates a voltage that is transverse to the direction of the current
  • Magnetic fields can be sensed using a Hall effect sensor
  • A magnetic-field-based proximity sensor can be designed using a magnetic field source and magnetic field detector
  • A high gain is required in the Hall effect sensor to sense weak magnetic fields
  • High gains can introduce undesirable effects such as high noise and DC offsets
  • Op-amps have imperfectly matched input bias currents, input offset voltage, and input noise
  • DC offsets can be compensated for by summing an external offset voltage
  • Filtering can be used to reduce noise
  • A comparator is a high-gain amplifier that is often used to provide a binary output indicating whether an input signal is above or below a predetermined threshold
  • A comparator can be used to convert a continuously variable signal to a binary signal
  • Operational amplifiers should not be used as comparators
  • Hysteresis can be added to a comparator to prevent chattering that occurs with noisy slow-moving input signals

Return to Engineering Discovery Index

university/courses/engineering_discovery/lab_6.txt · Last modified: 04 Sep 2019 20:32 by dmercer