Memo: Schmitt trigger

Hysteresis definition is as follow:

the phenomenon in which the value of a physical property lags behind changes in the effect causing it, as for instance when magnetic induction lags behind the magnetizing force.

The horizontal and vertical axes are input voltage and output voltage, respectively. T and −T are the switching thresholds, and and −M are the output voltage levels.

In unbalanced bipolar power supply (such as those created by elevating a virtual ground from unipolar power source), the hysteresis can be skewed along the horizontal axis of the above transfer function.

Schmitt triggers vs. Closed-loop amplifiers

It is easy to convert a closed-loop amplifier into Schmitt trigger by swapping the input terminals. Standard closed-loop amplifiers have negative feedbacks while Schmitt triggers have positive feedbacks as defined by Wikipedia:

In electronics, a Schmitt trigger is a comparator circuit with hysteresis implemented by applying positive feedback to the noninverting input of a comparator or differential amplifier.

One important note when converting negative feedback comparators into Schmitt triggers is the direction of the output. As seen below, non-inverting amplifiers will yield inverting Schmitt triggers when the input terminals are swapped, and vice versa.

Non-inverting amplifier (negative feedback)
Inverting Schmitt trigger (positive feedback)

Fortunately, changing the output direction of a comparator circuit (any feedback) is quite simple. Swapping Vin and GND terminals inverses the output direction of the circuit.

Non-inverting Schmitt trigger, practically identical layout with the inverting counterpart except Vin and GND positions
Schmitt trigger’s characteristics

Schmitt triggers are commonly used for switch debouncing and noise filtering for digital signals. In digital circuits, noisy signals are often fed to a low-pass filter to create a smoother signal before passing through a Schmitt trigger to recreate the sharp digital signal. Despite its importance in digital circuitry, the trigger itself is an analog component and is sometimes omitted in digital circuit simulation libraries.

Due to open-loop nature of the circuit, the gain of Schmitt trigger is infinity. Impedance values follow normal op-amp characteristics.

The regenerative feedback refers to the portion coming out of the voltage divider and into the non-inverting input. It’s denoted with beta symbol and defined as follow:

B = R1 / (R1 + R2)

The switching thresholds are calculated as the regenerative feedback times the positive or negative supply rail voltage Vs as seen below

V_\mathrm{+} = \frac{R_1}{R_1+R_2} \cdot V_\mathrm{s}

Please note that despite the formula, in reality, the Vs value in this calculation experiences some voltage drops (around 15%) due to internal impedance; hence the switching thresholds might be lower than calculated.

Astable multivibrator (Relaxation oscillator)

With a few extra components (a capacitor and a resistor), a Schmitt trigger can be adapted into an astable multivibrator. From inverting Schmitt trigger, add an additional negative feedback using a resistor, a capacitor and ground to create the astable multivibrator.

Astable multivibrator adapted from inverting Schmitt trigger circuit

The multivibrator does not take in any input signal. When powered up, it creates a full-range square waveform across the op-amp’s output and a half-range waveform across the non-inverting input (some documents denote this waveform as reference voltage). At the same time, it creates a half-range ramp waveform across the capacitor.

Transient analysis of a comparator-based relaxation oscillator.

The time period of the multivibrator is given by

T = 2 RC ln[(1+B)/(1-B)]

with B is the regenerative feedback, R and C are the value of the resistor and the value of the capacitor across the negative feedback respectively.

The amplitudes of half-range voltages are calculated using the same formula as the switching thresholds of normal Schmitt triggers.

When using an unbalanced bipolar supply, the switching thresholds of the multivibrator will be skewed and it will produce waveform of adjustable duty cycles. The duty cycle is dependent on the offset; left offset produces shorter duty cycle and right offset produces longer duty cycle. However, the device can only accept so much power supply offsetting before it cannot operate (under load) or overloaded.

Read more

https://en.wikipedia.org/wiki/Schmitt_trigger

https://en.wikipedia.org/wiki/Switch#Contact_bounce

https://en.wikipedia.org/wiki/Relaxation_oscillator

https://en.wikipedia.org/wiki/Multivibrator

https://www.allaboutcircuits.com/textbook/semiconductors/chpt-8/positive-feedback/

 

Advertisements

Memo: Op-amp’s gain factor and noise problems

First, here’s a quick cheatsheet on closed-loop gain factor for inverting and non-inverting amplifiers. The gain of inverting amplifier is given by the resistance R2 across the feedback loop divided by the resistance R1 across the forward input.

A = R2/R1

Meanwhile, the gain of non-inverting amplifier is given by

A = 1 + R2/R1

as calculated in the previous note. Kirchhoff’s current law is applied.

Gain factor and cut-off frequency relationship

Cut-off frequency is not only affected by the properties of a given component but it is also dependent on the gain factor of the amplifier circuit. Higher gain amplifiers have lower cut-off frequencies and this can be charted as an exponential decay function.

To easier express this function in linear terms, the relationship is converted to logarithmic terms:

20 log(0.5) = -6.02 [dB]

with 0.5 is the approximated V/Vref value from experimentation.

On a side note, below are two commonly seen decibel functions in electronics for power and voltage respectively.

{\displaystyle G_{\mathrm {dB} }=10\log _{10}\left({\frac {1000~\mathrm {W} }{1~\mathrm {W} }}\right)=30.}

{\displaystyle G_{\mathrm {dB} }=20\log _{10}\left({\frac {31.62~\mathrm {V} }{1~\mathrm {V} }}\right)=30.}

Naturally, the gain factor for op-amps is expressed in terms of voltages (the second formula).

Differential amplifier

A useful circuit using op-amps to amplify and de-noise a weak signal is differential amplifier. The basic circuit uses one op-amp in the arrangement below:

V1 and V2 inputs are the same signal, one of which is inverted. This can be done using an inverting amplifier with gain factor of 1 (inverting unity gain amplifier) but this arrangement is subjected to high-frequency quirks as stated in the previous memo, especially phase shifting property.

If the inputs are identical and not phase-inverted, the output will be zero.

The output of this particular circuit is an amplified signal with transmission line noise suppressed. Note that the transmission line noise being suppressed is the one common on both inputs after the inversion. Noises occurred before inversion cannot be suppressed this way.

Instrumental amplifier (three op-amps)

Normally, to ensure proper signal flow, the inputs are tunneled through two additional voltage followers (two more op-amps) in order to reduce the impedance. The full circuit (called “instrumentation amplifier) would then look like the following:

with all R values are the same except for Rgain.

Rgain can be of any value. It serves as a “common ground” connector and it also tweaks the voltage gain of the full circuit. Increasing the value of Rgain decreases the gain of the differential amplifier.

In reality, the gain of the above circuit can be tweaked further, following this function

{\frac {V_{\mathrm {out} }}{V_{2}-V_{1}}}=\left(1+{2R_{1} \over R_{\mathrm {gain} }}\right){R_{3} \over R_{2}}

Instrumental amplifier (two op-amps)

An alternative instrumental amplifier design using two op-amps can be seen below:

Though this setup saves on component costs, it does have a few disadvantages, notably, the lack of support for unity gain (not a problem for most scenarios but can be if the instrumental amplifier is used solely for noise canceling).

Furthermore, the circuit is unbalanced. The leftmost amplifier increases the input slightly and introduces some signal delay. This unbalance leads to reduced noise canceling capability. The output can saturate if the common-mode noise of the input signal here is too high and race condition can lead to a much lower cut-off frequency (compared to three op-amps version).

The gain factor here is controlled by RG in the same manner as Rgain in the other circuit.

G = 1 + R2/R1 + (2*R2)/RG

Bonus: Choosing the base resistance

When calculating the resistance of an analog system, the first resistor (base resistor) is chosen as a compromise between power consumption and noise tolerance. Low resistance (or impedance for AC systems) allows more current draw. This is welcome when loads are concerned but it is a waste of energy when sensors are concerned. The higher the base resistance, the lower the power consumption will be.

On the other hand, high resistance circuits are more susceptible to noise. The relationship between resistance and noise is given by Johnson-Nyquist noise voltage function

{\overline {v_{n}^{2}}}=4k_{\text{B}}TR

where kB is Boltzmann constant 1.38 x 10^-23 [J/K], T is the absolute temperature in Kelvin [K], and R is the system’s resistance. In other words, a small increase in resistance increases in Johnson noise voltage by the power of two.

TL;DR:

Increase R, increase noise, decrease current consumption

Decrease R, decrease noise, increase current consumption

Choose the right compromise for the application.

Bonus: Using op-amp with a unipolar power source

Unipolar or single-rail power sources that only have GND and VCC terminals need to offset the ground terminal to create a -VCC source. This offset can be done using a voltage divider circuit in conjunction with a voltage follower. Be mindful that the with only half of the voltage range, the op-amp might experience unexpected floating values.

The voltage follower (or unity gain amplifier) must be connected in series to the middle point of the voltage divider in order to create a new, offset virtual ground. This eliminates the added impedance from the voltage divider, ensuring sufficient current draw power devices using the virtual ground.

For example, such a system of voltage divider and voltage follower can be employed to create +2.5V and -2.5V bi-polar supply from Arduino’s 5V and 0V unipolar supply. In this case, the op-amp will produce 5V (relative to the Arduino’s true ground) as HIGH signal and 0V as LOW signal. Inversely, it will see 0V from the Arduino as -2.5V (relative to the virtual ground) and 5V as +2.5V.

The previous section on choosing base resistance also applies here, and even more so with the halved voltage range doubling susceptibility to signal distortion.

Read more

https://en.wikipedia.org/wiki/Exponential_decay

https://en.wikipedia.org/wiki/Decibel#Examples

http://www.electronics-tutorials.ws/opamp/opamp_5.html

https://en.wikipedia.org/wiki/Instrumentation_amplifier

http://www.electronicdesign.com/power/what-s-difference-between-operational-amplifiers-and-instrumentation-amplifiers

https://en.wikipedia.org/wiki/Johnson%E2%80%93Nyquist_noise

http://www.talkingelectronics.com/projects/OP-AMP/OP-AMP-1.html

Memo: Op-amp’s analog characteristics

Operational amplifier (op-amp) possesses an open-loop gain factor A0 and a close-circuit gain factor A.

The negative terminal of the op-amp is called “inverting” terminal and the positive terminal is called “non-inverting”. In addition to two input terminals, there are two power terminal V+vcc and V-vcc.

The output Vout is calculated as

Vout = A * (V+in – V-in).

Ideal op-amp has the following characteristics:

Input impedance rin approaches infinity.

Meanwhile, output rout impedance approaches zero.

Unity gain amplifier

These characteristics see applications in voltage follower (also known as unity gain amplifier), which produces an output voltage equal to input voltage but with much lower impedance. Low impedance circuits allows more current draw than high impedance ones.

Voltage follower setup: a simple negative feedback loop without any resistance

This unity gain is possible because the gain factor used here is open loop

Vout / Vin = A/ (1+A0)

as Aapproaches infinity

Vout / Vin = 1

Gain of closed-loop amplifiers

In other cases, the gain is determined by the values of the voltage divider overlaying the feedback loop. For example

A non-inverting amplifier: negative feedback with voltage divider setup

In this case, the gain is determined using Kirchhoff’s law. Since Kirchhoff’s current law states that the same current must leave a node as enter it, and since the impedance into the (−) pin is near infinity, we can assume practically all of the same current i flows through Rf, creating an output voltage

{\displaystyle V_{\text{out}}=V_{\text{in}}+i\times R_{f}=V_{\text{in}}+\left({\frac {V_{\text{in}}}{R_{g}}}\times R_{f}\right)=V_{\text{in}}+{\frac {V_{\text{in}}\times R_{f}}{R_{g}}}=V_{\text{in}}\left(1+{\frac {R_{f}}{R_{g}}}\right).}

Finally, we have the following closed-loop gain (applicable only to the above circuit)

{\displaystyle A_{\text{CL}}={\frac {V_{\text{out}}}{V_{\text{in}}}}=1+{\frac {R_{f}}{R_{g}}}.}

High frequency characteristics

The gains and formulas above are only applicable for low frequency circuits. In high frequencies, the following will happen:

Above certain frequencies, voltage gain and current gain factors become diminished in inverse proportion to frequency increase.

The output signal becomes lagged behind the input signal (phase shifting) as the op-amp cannot react fast enough to the frequency changes.

Very high input amplitude (peak-to-peak voltage swing of electrical signal) causes distortions and the higher the frequency, the lower this upper amplitude threshold is (distortion appears at lower amplitudes at high frequencies).

Cut-off frequency is the frequency at which the voltage gain is 1/sqrt(2) of the low frequency gain, meaning, the power at the output is effectively halved in voltage follower setup. The cut-off frequency is unique to each op-amp component. It can be easier determined using an oscilloscope as the frequency at which the phase shift is 180o.

Textbook definition:

The frequency where the voltage falls to 0.707 of its intended value is the cutoff or -3 dB frequency, fc. (Gain in decibels = 20∙log(0.707) = -3dB.)

As a result of these special high frequency characteristics, op-amps can be unsuitable for high frequency applications.

Read more

https://en.wikipedia.org/wiki/Operational_amplifier

http://www.learningaboutelectronics.com/Articles/Voltage-follower

http://www.ecircuitcenter.com/Circuits/op_bandwidth1/op_bandwidth1.htm

https://www.researchgate.net/post/Please_tell_me_Why_the_cutoff_frequency_is_taken_for_3dB_and_not_other_values_like_1_or_2_db

DIY Memo: ESP8266 v7 hookup

Same story as the last time, but with ESP8266 v7 this time.

This is the hook-up instruction for ESP-07 and how to capitalize on its GPIO pins.

8_LEDs_light_up_in_sequence

Things to know:

– 3.3V power source

– Default baud rate: 115200 (programmable at 9600)

– R1, R2, R3, R4 are all 10K

– C1 is 0.1 uF (ceramic capacitor 104)

– The solder pads are slightly smaller than the standard Arduino pin’s dimension. Use a small drill, purchase specialized pins or solder wires directly.

– GPIO2 -> HIGH during startup

– GPIO0 -> HIGH (standard) or GPIO0 -> LOW (flash) during startup

– GPIO15 -> LOW (standard) or GPIO15 -> HIGH (boot from SD card) during startup

– RXD is GPIO3 and can only be used as input. Similarly, TXD is GPIO1 and can only be used as output

– Deep sleep requires connecting GPIO16 -> RST to wake up.

– A diode from RST -> GPIO16 is necessary to use wake up and reset switch at the same time. The cause is GPIO16 producing HIGH current in deep sleep and it prevents reset switch from working. A diode blocking this current solves the issue.

– ADC is the only analog pin available. It is GPIO6 or A0 (alias) in Arduino language.

ESP8266 pin I/O support
GPIO0 INPUT with pull-up, jumper and delayed hook-up via a sacrificial GPIO pin which is only grounded after boot
OUTPUT with external device between VCC and GPIO0 (GPIO0 -> HIGH, device -> LOW)
GPIO1 (TXD) OUTPUT only
GPIO2 INPUT with pull-up and delayed hook-up via the same sacrificial GPIO pin as GPIO0
OUTPUT with external device between VCC and GPIO2 (GPIO2 -> HIGH, device -> LOW)
GPIO3 (RXD) INPUT only
GPIO4 INPUT and OUTPUT
GPIO5
GPIO12
GPIO13
GPIO14
GPIO15 OUTPUT with external device between GND and GPIO15 (GPIO0 -> HIGH, device -> HIGH)
GPIO16 (XPD) INPUT and OUTPUT
RST or DTR to wake up from Deep Sleep mode. Include a diode from RST -> GPIO16 if reset switch is used
GPIO6 (ADC, A0) Analog INPUT

Read more:

http://ediy.com.my/blog/item/133-upload-sketch-to-the-esp8266-esp-07-esp-12-using-arduino-ide

http://www.forward.com.au/pfod/ESP8266/GPIOpins/ESP8266_01_pin_magic.html

http://www.esp8266.com/viewtopic.php?f=13&t=13341

http://www.instructables.com/id/ESP8266-Using-GPIO0-GPIO2-as-inputs/step2/GPIO0-GPIO2-and-GPIO15-pins/

http://randomnerdtutorials.com/esp8266-adc-reading-analog-values-with-nodemcu/

http://internetofhomethings.com/homethings/?p=530

https://hackaday.io/project/8435-2-analog-inputs-for-esp8266-without-multiplexer

DIY Memo: ESP8266 v1 hookup

Tonight marks the third time I forgot how to hook up this wifi module already, I might as well leave a memo here for my forgetful future self.

This is the hookup instruction for ESP8266 v1 using CP2012 and Tera Term software

fn30hcfi3thpc9w-large

Things to know:

  • 3.3 VDC source
  • RX and TX can accept 5V logic level without problems (so far).
  • 5V output of an Arduino Uno (externally sourced) through AMS1117 provides enough current for ESP8266 boot up.
  • Default: 115200 baud rate
  • Tera Term > Setup > Terminal > New-line transmission mode: CR+RF
  • Flash mode: GPIO 0 + RESET -> GND then RESET -> float and finally GPIO 0 -> float
ESP8266 CP2012 / Source
VCC VCC
GND GND (common to CP2012)
RX TXD
TX RXD
GPIO 0 VCC
CH_PD
RESET