Difference between revisions of "Electronics notes/Knobs and dials"

From Helpful
Jump to: navigation, search
m (Debouncing)
m (Debouncing)
Line 183: Line 183:
  
  
Since most buttons are pulled down or up, this means fast switching in the electrical sense as well: a very quick alternation between contact and no contact.
+
This means fast switching in the electrical sense as well: a very quick alternation between contact and no contact.
  
 
In buttons that you have to hold down, noisy variation may also happen on movement, as the contacts scrape over each other.
 
In buttons that you have to hold down, noisy variation may also happen on movement, as the contacts scrape over each other.
Line 195: Line 195:
 
: Say, if you're switching on an IC, it may ''really'' dislike bounce on its Vcc, or some of its inputs.
 
: Say, if you're switching on an IC, it may ''really'' dislike bounce on its Vcc, or some of its inputs.
  
* Fast sensing, such as those from an IC or microcontroller, may be fast enough to sense all those changes and react to all very quickly
+
* Fast sensing, such as those from an IC or microcontroller, may be fast enough to sense all those changes and react to all very quickly (this is low-impedance sampling, and there are typically pullup/pulldown resistors to avoid floating)
 
: You may not want that to happen
 
: You may not want that to happen
  

Revision as of 17:06, 21 May 2022

This is for beginners and very much by a beginner / hobbyist.

It's intended to get an intuitive overview for hobbyist needs. It may get you started, but to be able to do anything remotely clever, follow a proper course or read a good book.


Some basics and reference: Volts, amps, energy, power · batteries · resistors · transistors · fuses · diodes · capacitors · inductors · ground

Slightly less basic: amplifier notes · varistors · changing voltage · transformers · baluns · frequency generation · Transmission lines · skin effect


And some more applied stuff:

IO: Input and output pins · wired local IO · wired local-ish IO · ·  Various wireless · 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

Noise stuff: Stray signals and noise · sound-related noise names · electronic non-coupled noise names · electronic coupled noise · ground loop · strategies to avoid coupled noise · Sampling, reproduction, and transmission distortions

Audio notes: See avnotes


Platform specific

Arduino and AVR notes · (Ethernet)
Microcontroller and computer platforms ·
ESP series notes
STM32 series notes


Less sorted: Ground · device voltage and impedance, audio and otherwise · electricity and humans · power supply considerations · Common terms, useful basics, soldering · PLL · pulse modulation · signal reflection · resource metering · SDR · Project boxes · vacuum tubes · Unsorted stuff

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

See also Category:Electronics.


Potmeters

Variable resistors (see potmeters), many of the ones with a knob are single-turn, meaning they go though their resistance range in ≤ 360 degrees.


Hacking servos

Servos use a potmeter as a sensor, so you could solder wires to that potmeter.

Mostly makes sense to do to continuous-rotation servos (or servos you've hacked that way), and/or when you also want to still use the servo (because otherwise it's just a pricier pot)

(...but manually turning the servo is likely to damage said gears, particularly for higher torque gearboxes, particulary for cheap plastic ones, so in general this is not very useful).


So possibly consider continuous pots, even if they're not necessarily cheaper.

Rotary/linear encoders

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)

Incremental encoders, a.k.a. Relative encoders (only) report/detect change in position, from which you can calculate direction and speed. ...assuming you're sampling fast enough to not miss transitions.

quadrature encoding in a disc

The idea behind incremental encoders is roughly that they're seeing two things 90 degrees out of phase


One way is to use a a quadrature encoding disc, read out with two sensors at the same angle.

An optical relative encoder can do much the same another way (e.g. many mouse scrollwheels, and also opto-mechanical ball mice) are often a single disc with slits, and it's not the disc but the positioning of the sensor that puts one half such a distance ahead of the other, which lets you one signal is ahead of the other, and you can additionally detect direction (verify)

The two are effectively the same in terms of what you do with the output.

The rate of changes is the speed, and you can tell direction by which leads the other. This video is a decent indication of what happens on these two outputs.

As-is, relative encoders are useful for things like menu navigation, where only movement matters in the first place, and when sensing speeds.



absolute encoider disc

Absolute encoders report their actual position, from which you can then calculate direction and speed.

You could intuit these as encoding their position as an integer, but they're actually Gray code, more useful in this context because it lets you detect and potentially correct successive values that don't make sense.



Virtual absolute encoder (TODO)


Readout



In terms of electronics or code



Resolver

https://en.wikipedia.org/wiki/Resolver_(electrical)

Switches

When using switches as input

On floating inputs

Consider that switches often either connect or disconnect an input, meaning one state is a broken circuit.


This means there is nothing to pull it to a stable state, and EM from nearby ICs or the environment can be the strongest effect, particularly if the traces are longer.

When this is sensed, particularly by high impedance inputs, this gives fairly unpredictable behaviour.


The most basic solution is a pullup/pulldown resistor.

Things like schmitt triggers may also help.


On internal pullups

A lot of platforms, DIY or not, you can enable an internal pullups via code, which means you don't need to add a resistor to such a circuit.


Note that these internal pullups tend to be high-valued (e.g. order of 50K), and when

traces are long,
you have no shielding,
you work with high-EM environments, and/or
you are working with SoCs designed to live in shielded traces with short traces (e.g. RPi's SoC)

...then that may not be enough to pull down enough to quiet down all EM noise, you you can get spurious interrupts, and want to add your own resistors, maybe on the order of 5-10k.

Debouncing

Oscilloscope sampling a button when it's starting to be pressed, showing mechanical contact bounce

The mechanics in almost all switches means their contacts will physically bounce a few times before settling, called contact bounce.

You may like to see what that looks like when sampled


This means fast switching in the electrical sense as well: a very quick alternation between contact and no contact.

In buttons that you have to hold down, noisy variation may also happen on movement, as the contacts scrape over each other.


Possible problems

  • If it's driving a load directly: most loads don't care so much, so this is often fine
  • Some electrical components that don't like switching that fast
Say, if you're switching on an IC, it may really dislike bounce on its Vcc, or some of its inputs.
  • Fast sensing, such as those from an IC or microcontroller, may be fast enough to sense all those changes and react to all very quickly (this is low-impedance sampling, and there are typically pullup/pulldown resistors to avoid floating)
You may not want that to happen
  • If sensing from a microcontroller, and sampling a button only occasionally,
you may accidentally find in the state it mostly isn't in and do something unexpected.


Possible solutions

  • in digital sensing, there are various solutions in code
many are variations on the idea that it should be in actuated state most of the time
and before you start storing a history, note that a simpler way is to count up or down depending on the last sensed value.
this will react more slowly - but for most human-operated switches, few-millisecond reaction is enough
  • In the case of double throw switches, you actually deal with three states - connected to one, connected to the other, or inbetween.
and there is sometimes some latching solution you can get from logic. This will have basically no latency, but take a few more components.
  • In analog circuits, one way to debounce is a filter
for example, and RC circuit
the idea being is that if it must charge to the pressed state, it only matters that it's mostly being pressed
this will react more slowly - but for most human-operated switches, few-millisecond reaction is enough
note, however, that this only lessens the problem, it doesn't fix it entirely, because there is no hysteresis or latching in there, so there will still be a threshold around which it'll flip-flop (depending on the exact circuit)

TODO: write up a fuller explanation, including common avoidable mistakes



There are further considerations:

  • if what you control is safer (or less annoying) in one state, then you may want to bias your logic to be in that state if there is any doubt.
e.g. consider a pushbutton off until it's fairly consistently on
but beware of variants of that code that will effectively debounce in one direction but not in the other.
  • you sometimes care about latency of switching on, so act faster on rising edge than falling edge
particularly if you act only on the rising edge
  • if your load doesn't like fast switching, consider a counter that prevents acting too quickly after the most recent switch

Switches, buttons, toggles, and such

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)

Encompasses combinations of:

  • Multiple positions,
  • a mechanical tendency to go to one position
toggle/flip, or momentary
  • multiple electronic states,
  • and other electronic properties


Bistability refers to switches that will rest in both states.

It could be both a mechanical and electronic descriptor, though on the mechanical side it's often called latching, or some such term, whereas a monostable would refer to what most relays do (the term "monostable switch" would be rare because we have words like "momentary" and "pushbutton").


...so the terms monostable and bistability are usually about electronic switching, e.g. to pointing out e.g. that

digital circuits can be made to sustain their current state.
thyristors will stay in their current state, while transistors are not
...often then mentioning a simple bistable multivibrator circuit, a.k.a. flipflop), or contrasted with a monostable multivibrator


See also



Types

The distinction between buttons and switches is not more pragmatic than it is hard/strict. Can be a pain in webshopping :)


A few more specific buttons/switches:

  • rocker switch
    • states: often two or three. Usually toggled, sometimes momentary
    • rocker switch
  • push-button
    • states: two. often momentary, sometimes toggled
    • push-button
  • microswitch
    • mainly a small momentary push-button
    • states: Two. Momentary.
    • microswitch
  • Mercury switch
    • states: Two. Depends on orientation (because gravity).
    • no contact bounce
    • mercury switch
  • Reed switch
    • states: Two.
    • Mechanical, closed by nearby magnet
    • reed switch
  • knife switch
    • The circuit breaker of old
    • states: Two. toggled
    • knife+switch


Uses:

  • end switch
    • a switch positioned at the end of a mechanical range, often to detect when actuation should go no further
    • often a microswitch with some sort of lever, wheel, etc. for durability.\
    • end+switch

Contact bounce (behaviour)

Contact bounce indicates the time in which an arriving contact mechanically settles and in which the connection is not yet stable. See some images. This bounce is often tiny, both in movement and time.

This bounce is rarely important when driving resistive loads, but in anything more complex there the reaction to the bounce itself can matter.

For example, a digital system observing/sampling it may see very fast switching back and forth.

Some components, such as ICs, also don't deal too well with bounce on their Vcc. A bypass capacitor helps here, and is nice for its power stability anyway.


Arcs (behaviour)

Default switch state (design)

Switches that are typically in one state (in the case of buttons will probably return there, rather than be toggled) can be referred to as Normally Open (NO) and Normally Closed (NC)


If it has contacts for more than one state (which, when one state is most natural, can be termed NO and NC contacts), the switch is termed Changeover (CO) (also Double-Throw, implying a typical two-state switch, Triple-Throw, etc.).

Changeover switches can be:

  • break before make, meaning there is some time in which neither side makes contact. This may cause temporary high impedance long enough to cause some unpredictable behaviour
  • make before break, meaning there is some time in which both sides make contact. This may easily cause temporary shorts.


Poles and throwing (design)

Depending on what exactly you want to do, poles and throws can matter when buying a switch.

Amount of poles matters to whether you want to do something with one state (e.g. powered or not) or with both.

Amount of throws matters when you want to control things independently from the same mechanical switch (without digital logic doing it for you). Consider that a car's emergency light switch turns on both turn signals without tying them together electrically.

In some constructions, both matter. Consider multiway switching.


SPST (symbolic)
  • SPST (Single Pole, Single Throw)
    • open or closed



DPST (symbolic)
  • DPST (Double Pole, Single Throw)
    • two separate SPST-style switches controlled by the same mechanics



SPDT (symbolic)
  • SPDT (Single Pole, Double Throw)



DPDT (symbolic)
  • DPDT (Double Pole, Double Throw)
    • two separate SPDT-style switches controlled by the same mechanics



There are further variants of design.

Triple pole and similar also exist, for example triple pole single throw mechanical knife switch circuit breakers.



Relays

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)

A relay is an electronically controlled switch.

Relays switching an electronically separated circuit can be useful when they deal with different voltages and/or different orders of current.

Relays are also make sense around more modular systems, like process control, because it's easier to separate control signals from drive currents, e.g. via connectors following some convention.


Electromechanical relays are the classical variant, specifically a solenoid that pushes/pulls a contact closed. They are often called just relays, or EMR in contexts where SSRs are also relevant (like here).


Solid state relays (SSR) are a relatively new development, and are becoming more common.

SSRs seem to often be either

  • for switching AC or DC loads: a SCR or TRIAC with the appropiate control circuitry to make them work basically like relays (and may be isolated too)
  • for switching only DC loads: a MOSFET

...plus heatsinking, optical coupling for isolation, and some other considerations.


There are also Reed relays, which can switch faster than EMRs, but have a current limit that is often on the order of half an amp tops. They are mostly associated with some oldschool analog electronics.


In general, your choice is between EMR and SSR. There is more comparison below, but in general, EMRs ar chunkier but wear over time, while SSRs take a bunch more design care but can then be more flexible.



Circuit considerations - control side

EMRs may need need on the order of 20mA-50mA to be held consistently. More when switched from lower voltages, less from higher voltages.

Because EMRs are coils, they are inductive elements that present flyback to the circuit that drives them, so you may want to sink that flyback spike elsewhere, particularly if controlled from ICs.

Circuits with ICs driving them

typically something (probably a diode) for flyback protection of that transistor/optocoupler.
regularly use a transistor (sometimes an optocoupler) to drive ~50mA even when the control



SSRs use less control current(verify), but run hotter overall due to their semiconductor nature, so

you may need a heatsink or risk thermal runaway (read: smoky melty problems), particularly in already-warm conditions
for safety's sake assume approx 1W of heat per 1A drawn, though usually it's noticably less



Circuit considerations - load side



Relay ratings

Not all relays are created equal.

The physical design will vary with the voltages they are intended to switch.

Most are designed for at most mains voltage, because arcing is harder to design away at kilovolts.
Relays designed for at most dozens of volts can switch faster because they barely have to think about arcing as an .


Relatedly, when switching significantly capacitive/inductive effects, you will briefly see larger currents and voltages (the inrush current of the load).

This is one reason a relay's maximum rated inductive load is much lower, often well under half the rated maximum resistive load.
For example, the one I'm holding right now is rated for 10A (at 125VAC and 240VAC) for resistive loads, and for 3A for inductive loads.
This too depends somewhat on the voltage.
Specifying these differences is called 'derating


There is also a difference between whether it's switching AC or DC.

Because DC can sustain an arc longer, DC is derated more(verify).
Check the datasheet, the ratings printed on the relay may be correct but less complete.


Hot switching refers to switching a relay while voltage is applied, which matters mostly to mechanical relays in that it produces arcing and wear.


Cold switching refers to applying voltage only after a relay switch.

Cold switching is possible to design into some test equipment, and sometimes useful to concentrate the wear in a predictable place, but in general many uses of relays will be hot switching.



Note that while it may seem that using a relay for much less current than it is designed for should avoid all wear issues (no arcing), it seems this actually can make them get dirty instead (?oxidation?(verify)), meaning they will fail to work reliably.



Comparison between SSRs and EMRs

  • switching speed
SSRs can switch at perhaps 20usec..10msec. That said, ones that have zero cross switching are by definition slower.
EMRs at order of 50ms and wear faster in the process
  • SSRs can switch much larger currents without much higher drive currents
  • SSRs that do zero point switching means no sudden current change
so they don't pollute the waveform as much(verify)


  • EMRs have contact bounce
and, when hot-switching, arcing, welding, and shortened contact lifespan
this is worse on inductive loads
  • EMRs are more susceptible to shock, and orientation matters


  • SSRs are preferable around strong vibration (to avoid intermittent contacts, amplifying bounce)
  • SSRs are preferable when they have to be close to magnetic sensors, temperature sensors
  • SSRs can be preferable in humid and dusty environments (but you may want to protect the entire PCB with an enclosure, so this often matters less)



  • current draw
larger EMRs have to push larger contacts
SSRs are higher resistance by nature, so use a few times more hold current


Safety-wise

  • EMRs arc internally so unless they are entirely sealed (various are not), SSRs will be less risky around combustibles/explosives
  • SSRs have different failure modes than EMRs, which can matter
in particular, SSRs are more likely than EMRs to fail closed, which can matter


Protecting relays from capacitive/inductive effects

  • if it's DC, you could use a chunky diode on the output end
  • if it's AC,


Failure/Reliability-wise,

  • Failure state
EMRs can weld shut so fail in conductive state, but more usually have their coil fail so fail open
SSRs usually fail in conductive state
In some situations the latter is a much worse idea, both because they may melt or blow, and because the machine is probably not in a safe state before they break (and leaving e.g. a motor actuated might break it).
In situations that require fast switching as well (e.g. industrial control), you can opt for SSR for everyday operation and an EMR as a safety interlock controlled from some sensing.
  • EMRs can have intermittent connections due to poor contact surface (and spot welds over time)
  • EMRs should probably not be switched overly quickly, and because they are physically slowish they often won't even manage
  • SSRs have no clear primary wear-out mechanism so should last quite long in gentle conditions,
yet there are conditions that kill SSRs faster than EMRs.
  • SSRs are less resistant to heat (see thermal runaway), and at the same time are warmer than EMRs for the same current.
so cooling them can matter
  • EMRs are often derated for varying cases, SSRs somewhat less so(verify).


Voltage surges, momentary shorts, inrush, and (for some) the polarity of what it's switching matters. Which means that EMRs can be preferable for components (motors, transformers) with high inrush current(verify).

Inductive can still create high enough voltage spikes to damage SSR's output transistors


You can generally assume EMRs have on the order of 100K switches in them, varying with quality, how near their current rating they are being used (you might get a spec that says 1M at negligible current, and 10K under significant load).

So assuming a few to a few dozen switches or so per day, they should last years to decades, though in some certain fast-switching uses (e.g. industrial machine control) that might reduce to months so you might want SSRs (with the exception that SSRs may fail on, so which you may want to back up with an EMR for safety and other such interesting implications)






Unsorted:


Contactors