Difference between revisions of "Electronics notes/General sensor notes, voltage and current sensing"

From Helpful
Jump to: navigation, search
m (Notes on ADCs)
m (Some typology)
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
 
'''Floating inputs''' refer to sensing from wires that are not connected to anything.
 
'''Floating inputs''' refer to sensing from wires that are not connected to anything.
  
The way most ways of sensing work (transistors, op amps, comparators, ADCs), they may end up measuring (and effectively amplifying) a tiny electromagnetic effect nearby, such as static electricity, your presence, e.g. your hand (works better in low humidity), induced signals such as mains hum, components near the sensing circuitry, and sometimes the behaviour of the sensing circuitry itself.
 
  
 +
Since most sensing (transistors, op amps, comparators, ADCs) is high impedance, they are easily influenced by the tiniest electromagnetic effect nearby, such as static electricity, your presence, e.g. your hand, induced signals such as mains hum, components near the sensing circuitry, and sometimes the behaviour of the sensing circuitry itself.
  
The voltage '''level of floating inputs is unpredictable''' and may vary/oscillate wildly (sometimes fairly smoothly).
 
The behaviour depends on too many factors to predict outside of a very controlled setting.
 
Sometimes [[mains hum]] is the largest recognizable influence, sometimes not.
 
  
If the result of this sensing is tied to some output, it may cause some very interesting things.
+
The voltage '''level of floating inputs is unpredictable''' and may vary/oscillate wildly (sometimes fairly smoothly).
  
<!--
+
The behaviour depends on too many factors to predict outside of a very controlled setting,
: '''Power draw'''
+
so also not very easy to detect (unless you're specifically designed for that).
  
Depending on the exact design, and on the state of the pin (and its potential difference with ground or Vcc), a floating pin may cause draw of perhaps half a milliamp, where it could be a few microamps.
 
  
  
  
: '''Damage'''
+
Issues:
  
In a few cases, the voltage fluctiatins may be high enough to cause high-frequency switching.
+
* Usually the largest issue is unpredictable behaviour.
A few components may not like this.
+
: If the result of this unpredictable input goes to some output, it may cause some very interesting things to happen.
Apparently CMOS is more sensitive to this, and may be weird even for inputs you don't use.{{verify}}
+
  
 +
* if it involves pins like reset or enable, leaving them unconnected can crash things
 +
 +
* if it senses oscillation
 +
: if there's a registered ISR, it could lead to freezes
 +
: there may be some low level thing drawing a little more power (e.g. CMOS draws a little power when switching states), like half a mA per pin, where when pulled up/down that might be microamps
 +
: it may cause some high-frequency switching
 +
:: which, if it goes to some output, can damage components that don't like that
 +
 +
<!--
 
-->
 
-->
  
Line 33: Line 37:
  
 
: Solutions
 
: Solutions
 +
 +
Many microcontrollers have internal pullup(/pulldown) resistors.
 +
If so, enabling them should avoid this completely.
 +
 +
 +
If you don't have pullups, but it's still a GPIO pin, configure it as an output{{verify}}.
  
  
 
The simplest solution is to always have something wired up, so that the voltage will always
 
The simplest solution is to always have something wired up, so that the voltage will always
 
settle on something stable because of the output behaviour of whatever is connected.
 
settle on something stable because of the output behaviour of whatever is connected.
 +
An external pullup or pulldown resistor (to Vcc or ground) is one workaround.
  
  
In various cases it is unavoidable that an input is sometimes unconnected,  
+
In various cases it is unavoidable that an input is sometimes unconnected,
 
or you simply want to allow for it without circuitry doing weird things.
 
or you simply want to allow for it without circuitry doing weird things.
 
Say, an audio input plug.
 
Say, an audio input plug.
Line 75: Line 86:
  
 
There are also '''floating ''outputs'' ''', but they are not usually a problem.
 
There are also '''floating ''outputs'' ''', but they are not usually a problem.
 +
 +
 +
 +
 +
https://electronics.stackexchange.com/questions/7179/is-it-really-a-bad-idea-to-leave-an-mcu-input-pin-floating
  
 
-->
 
-->
Line 365: Line 381:
  
 
* '''(Fully-)Differential'''
 
* '''(Fully-)Differential'''
: measures the difference between two pins
+
: measures the difference between two pins (i.e. no ground)
 
: '''Floating-differential''' and '''pseudo-Differential''' relate to voltage ranges and noise {{verify}}
 
: '''Floating-differential''' and '''pseudo-Differential''' relate to voltage ranges and noise {{verify}}
  

Latest revision as of 18:37, 10 November 2019

This is for beginners and very much by a beginner. It's meant to try to cover hobbyist needs, and as a starting point to find out which may be the relevant details for you, not for definitive information.

Some basics and reference: Volts, amps, energy, power · Ground · batteries · resistors · changing voltage · transistors · fuses · diodes · varistors · capacitors · inductors · transformers · baluns · amplifier notes · frequency generation · skin effect


And some more applied stuff:

IO: wired local IO wired local-ish IO · · · · Shorter-range wireless (IR, ISM RF, RFID) · bluetooth · 802.15 (including zigbee) · 802.11 (WiFi) · cell phone


Sensors: General sensor notes, voltage and current sensing · Knobs and dials · Pressure sensing · Temperature sensing · humidity sensing · Light sensing · Movement sensing · Capacitive sensing · Touch screen notes

Actuators: General actuator notes, circuit protection · Motors and servos · Solenoids

Some stuff I've messed with: Avrusb500v2 · GPS · Hilo GPRS · JY-MCU · DMX · Thermal printer

Audio notes: basic audio hacks · microphones · amps and speakers · device voltage and impedance, audio and otherwise ·

Less sorted: Common terms, useful basics, soldering · Microcontroller and computer platforms · Arduino and AVR notes · ESP series notes · Electronics notes/Phase Locked Loop notes · mounts, chip carriers, packages, connectors · signal reflection · pulse modulation · electricity and humans · Unsorted stuff


See also Category:Electronics.

On floating inputs

This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)

Floating inputs refer to sensing from wires that are not connected to anything.


Since most sensing (transistors, op amps, comparators, ADCs) is high impedance, they are easily influenced by the tiniest electromagnetic effect nearby, such as static electricity, your presence, e.g. your hand, induced signals such as mains hum, components near the sensing circuitry, and sometimes the behaviour of the sensing circuitry itself.


The voltage level of floating inputs is unpredictable and may vary/oscillate wildly (sometimes fairly smoothly).

The behaviour depends on too many factors to predict outside of a very controlled setting, so also not very easy to detect (unless you're specifically designed for that).



Issues:

  • Usually the largest issue is unpredictable behaviour.
If the result of this unpredictable input goes to some output, it may cause some very interesting things to happen.
  • if it involves pins like reset or enable, leaving them unconnected can crash things
  • if it senses oscillation
if there's a registered ISR, it could lead to freezes
there may be some low level thing drawing a little more power (e.g. CMOS draws a little power when switching states), like half a mA per pin, where when pulled up/down that might be microamps
it may cause some high-frequency switching
which, if it goes to some output, can damage components that don't like that


Current loops

This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)

Current loops are those that signal using either presence of current (on/off) or degree of current, rather than voltage.

Which itself is a very general concept, and most uses are specced more specifically.


For example, MIDI communicates as a unidirectional serial port, and electrically each interconnection is its own 5mA current loop -- because it's driving an optocouple.

(In practice, RS-485 often replaced such use, for practical reasons)


But often, current loops refer specifically to the 4-20mA variant (see below).

This because it's easier to communicate stable current than stable voltage in the presence of interference, so in e.g. industrial settings it's worth the extra conversions that are often involved.


4-20mA current loops

The use of 4-20mA signmalling of sensors first were a de facto standard, then got described in ISA-S50.1 (ANSI/ISA-S50.1-1975, -1982, -1992).


The point is using a current range to represent a value range.


Yes, voltage output is often a more natural choice given the output of most sensors, but voltage drops over long lines, and interference presents mostly as voltage.

So while voltage is fine within most devices, due to short distances and ability to control shielding, So current loops communicate more stably and are less noisy and make a lot of sense in e.g. industrial settings.


Upsides

Currents are by definition the same everywhere in their path, so are not bothered by such voltage drops.

...as long as the loop can maintain that current -- which is true until the voltage drops over the cable and components is larger than the power supply voltage. The supply voltage is DC and often 24V, and devices are often lenient (Voltages like 12V, 15V, 36V, and others are also seen)

A voltage signal's meaning is directly and proportionally affected by interference on the line.

Current signals are not immune, but are less affected.

Being zeroed at 4mA rather than 0mA, while makes ratiometric use harder, also makes it easy to sense a disconnected port / broken wire

where voltage input would float and just become more environment-sensitive and behave randomly

Two wires can be used for both signal and power

...though not all sensors can be loop-powered


Downsides

Only one parameter per loop (for complex setups this can be a lot of wiring)

Nontrivial component-wise

Not too particularly complex, but e.g. for complex setups there may be better alternatives
e.g. if your measurements are digital already, it's often easier to use digital communication, e.g. use RS-485 if you have to go longer distances (can be used as a shared bus)

Not immune to ground loops (but they may be easier to solve).

(e.g. a local sensor display may have its own ground)


Where the power is
How
Extensions
See also

Notes on ADCs

An Analog-Digital Converter (ADC) takes a (voltage) signal and turns it into numbers to be digitally consumed.


Most ADCs do voltage sensing.

Some have extra circuitry to be current-input ADCs (which mostly just means a resistor setup, but probably better specced than you can easily make), many of them for specific applications.



On quantization

On nonlinear quantization

Impedance and buffering

ADC operation works with current, so they have relatively low-impedance inputs. As such, they may interact with the source circuit (consider e.g. SAR ADCs, which are also a non-linear load on the source circuit).

Impedance also easily varies with (sampling) frequency. This seems particularly true of high-performance ADCs.


If you want to minimize the interaction with the circuit you can use a buffer, such as an op amp, which presents a high-impedance load to your circuit and a lowish-impedance output to the ADC. (Assuming you were not already using an op amp construction (e.g an instrumentation amp) anyway, you can e.g. make it a fairly-simple voltage-following unity-gain amp)


Some typology

This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)


Input structure

  • Single-Ended
measures the difference between one pin and ground
  • (Fully-)Differential
measures the difference between two pins (i.e. no ground)
Floating-differential and pseudo-Differential relate to voltage ranges and noise (verify)



Getting the value

Resolution and speed depends entirely on application. Imaging and such needs to be both, movement needs speed more than accuracy, while temperature and such can be slow if that means it's more accurate, or just cheaper.



  • Ramp Counter (a.k.a. digital ramp)
https://www.analog.com/media/en/training-seminars/tutorials/MT-026.pdf


  • Delta-sigma - refers to a way of dealing with noise, used by both ADCs and DACs
medium speed, high resolution
https://en.wikipedia.org/wiki/Delta-sigma_modulation
http://www.ti.com/lit/an/slyt423/slyt423.pdf
http://www.allaboutcircuits.com/vol_4/chpt_13/9.html
  • Single-slope
  • Dual-slope
slow speed, good resolution


  • Successive Approximation Register (SAR)
medium speed, high res
most common, because of the above and low cost


  • Flash
high speed, medium resolution
https://en.wikipedia.org/wiki/Flash_ADC
  • Pipelined
effectively multiple flash type, better resolution


See also:

oversampling / supersampling

See Oversampling

Amplifying and otherwise massaging voltage

Certain sensors are by nature low-voltage. You'll regularly use op amps to (offset and) amplify that voltage to a range your ADC likes.


Voltage sensing

Signal conditioning

Lowpass

See Low-pass filter.

You may want to consider doing the low-pass calculations in in floating point (or fixed point) even if you return (truncated) ints (with pure-integer solution, small alphas can lead to problems related to truncation within each step. You can hack around this, but only really if you understand the problem, so using floats is usually simpler).


If you're doing an occasional sample of a sensor and want the return a filtered value for stability, there are a few things to keep in mind, particularly when your code has other things to do, and you only occasionally call this lowpassed-sampling function.

  • the question of whether the value can adapt quickly enough to the changes in the sensor value that may happen in the time between such calls. (When there's nothing time-critical about the sampling this can be fairly easily solved by doing a couple hundred samples each call (well, depending on the alpha) to let it adapt)
  • In a 'take x samples, lowpass the series, give last output', the first value has a relatively strong influence on the output in that if relatively few samples follow it may not adapt well enough. This means that if the high-frequency fluctuations that you want to filter out make it into the first value, the result can be less stable than you might think. To avoid this you may want (an option) to use the most frequent output as the first value. (Note this does influence the question of whether the value will adapt quickly enough within each sampling call, if the value can change significantly between calls.)

Analysis

Spectrum analyser ICs (per-band information)

  • for some example uses, see e.g. NJU7505A, MSGEQ7



Current sensing

Resistive sensors

Creative repurposing

  • stepper motor as a rotary encoder


See also