Electronics notes / Inputs and outputs
High side versus low side switching / driving / sensing
Some limits and choices
High versus low side sensing
Buffers
Transistor output stages
Open-drain / open-collector
Common collector / Common drain
Totem-pole, push-pull
Other details
Transient voltage and ESD protection, snubbers
Protection diodes (inputs and output pins)
TVS diodes
Snapback
RC and RCD snubbers
Crowbars
Gas Discharge Tubes
MOVs
Trisil
Unsorted
See also (transients)
Microcontroller GPIO
On ADCs and DACs
ADC
An Analog-Digital Converter (ADC) takes a voltage signal, and turns it into numbers to be consumed digitally.
Well, most ADCs do voltage sensing. A few 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.
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)
On quantization
When sampled ADC values fluctuate
On nonlinear quantization
Some typology
You may only care about a few of these terms, but they'll be useful.
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)
- 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:
- http://www.maximintegrated.com/app-notes/index.mvp/id/1108
- http://www.hardwaresecrets.com/printpage/How-Analog-to-Digital-Converter-ADC-Works/317
DAC
A Digital-Analog Converter (DAC) takes numbers and turn them into voltages.
What do DACs speak
That varies.
It's often one of
- a little more fiddly to use for sound because the timing is either separately set, or not really defined (so not strictly regular)
- but perfectly good for "set voltage level on output"
- I2S - good at sound
- note that there are technically some dialects
- something specific
- e.g. OPL style FM (e.g. YM3812, YMF262) want a specific style of DAC (e.g. YAC512), which sends floating-point-like values
- TI DSPs often speak speak TI's McBSP, and so various of their ADC/DACs
Consider also:
- Pulse Density Modulation in general
- Abusing a serial port at a high rate, see e.g. Mozzi's PDM_VIA_SERIAL
- imperfect, but the serial hardware does the timing
- Mozzi's PDM_VIA_I2S
Multiplying DAC (type)
Oversampling / upsampling DACs
On the cheap: Resistor ladder
Basic idea: If you can change many digital pins at exactly the same time (e.g. often 8 on many microcontrollers, or a classic parallel port), then putting a resistor ladder on it means each contributes a different voltage level.
Laid out in R-2R a.k.a. R2R style (there are other configurations), you can can make 2amt equal voltage levels (256 for 8 pins), in a way that makes 256 equally spaced levels.
This is a crude 8-bit DAC.
E.g. the Covox Speech Thing was basically just a bunch of resistors on a parallel port, the Disney Sound Source a data-buffered variant.
Especially the speech thing was adopted by some games and music trackers.
Limitations:
- you still need to write out new data with strict regularity
- which is what interrupts are good at, but this will occupy a bunch of CPU power
- The Disney Sound Source solved this by being buffered (but fixed the output rate to a relatively poor 7kHz)
- the resistors' voltage contribution won't be perfect to contribute exactly what they should.
- making equal steps (to produce undistorted signals) takes either precision resistors or a bunch of measuring and matching beforehand.
- the more bits you have, the harder it gets - 8 is quite doable, but it starts getting impractical around 12 bits
- more than 8 bits of concurrent output is rare in this approach, in part because digital output channels are oftencontrollable 8 at a time
- may be acceptable at lower frequencies, but faster is harder to get right
Example:
On the cheap (if your IC happens to have it): Oversampling fast PWM
So, PWM at the signal rate is poor.
But what if we can PWM much faster than the signal's rate, and lowpass the result to the signal's rate? After the lowpass you're looking at something is mostly its average.
Oversampling PWM makes its output more linear and reduces some noise sources (lessening requirement to any filtering), and preferably we want two orders of magnitude faster, order of ~1MHz for a 20kHz signal.
That speed basically requires dedicated PWM circuitry in the IC.
Limitations:
- if you don't have very fast PWM, the net result is high noise
- the lowpass is probably fixed
- so it has a range where it works best, which is part of your design
- which is why this can't be a more general-purpose DDS
- without dedicated PWM circuitry the timing issues would make this impossible for audio rate, particularly if you also want to do anything else in the microcontroller
- even if the PWM output is regular due to dedicated hardware, we also need to update the sample to put out with strict regularity
- this is what interrupts are good at. It just occupies the CPU.
- you'ld really prefer a small buffer, so that you don't need interrupts to be at at audio rate (if it is, expect everything else to be secondary to this). At this point, you're starting to describe a dedicated DAC
- multiple channels may be possible, but how easy this is varies with IC
- this might actually help you e.g. produce different types of wave at the same rate
Example:
- Raspberry Pi's onboard sound is actually dedicated PWM pins, at 50MHz(verify), plus a filter and buffer (exact details vary)
DAC practicalities
Some simple ADCs and DACs for DIY
CODECs
A codec (short for coder/decoder[1]) is mostly just an ADC + DAC with some shared hardware.
This can be cheaper, smaller, fewer wires, yet functionally be much like separate parts.
The two are often synchronized, i.e. sharing the same clock,
which can help reduce drift issues and latency between them,
but that also depends on further details (and whether you care about this at all also varies).
It may sometimes mean a little less work to manage both,
but this gets into engineering choices, and there are no
hard conclusions about what it means to the end user.
Most codecs are designed for audio uses,
because there aren't a lot of signal uses that need this.
oversampling / supersampling
See Oversampling