Voltage Divider

Using two resistors $R_{1}$ and $R_{2}$ an input voltage $V_{in}$ can be lowered to a resulting voltage $V_{out}$ according to the formula:

$$
\begin{eqnarray*}
V_{out} &=& \frac{V_{in} * R_{2}}{R_{1} + R_{2}}
\end{eqnarray*}
$$

using the following circuit diagram:

                                
      * -------*                
      |        |                
      |        *                
      |        \                
      |        / R1             
      |        \                
   +  *        *                
               |                
  Vin          *-------*        
               |       | +      
   -  *        *       *        
      |        /          Vout  
      |        \ R2    *        
      |        /       | -      
      *--------*-------*        
                                                         

The equation has four parameters $V_{in}$, $V_{out}$, $R_{1}$ and $R_{2}$ such that when three parameters are known, the fourth parameter can be obtained by solving the equation.

For ease-of-use, let $R_{1}$ be the resistance that you pick and let $R_{2}$ be the resistance you need to calculate after having picked the value for $R_{1}$. The following steps convert the formula in order to solve for $R_{2}$:

$$
\begin{eqnarray*}
V_{out} &=& \frac{V_{in} * R_{2}}{R_{1} + R_{2}} &\Leftrightarrow& \\
V_{out} ( R_{1} + R_{2} ) &=& V_{in} * R_{2} &\Leftrightarrow& \\
V_{out} R_{1} + V_{out} R_{2} &=& V_{in} * R_{2} &\Leftrightarrow& \\
\frac{V_{out} R_{1} + V_{out} R_{2}}{V_{in}} &=& R_{2} &\Leftrightarrow& \\
\frac{V_{out} R_{1}}{V_{in}} + \frac{V_{out} R_{2}}{V_{in}} &=& R_{2} &\Leftrightarrow& \\
\frac{V_{out} R_{2}}{V_{in}} &=& R_{2} - \frac{V_{out} R_{1}}{V_{in}} &\Leftrightarrow& \\
\frac{V_{out} R_{2}}{V_{in}} - R_{2} &=& - \frac{V_{out} R_{1}}{V_{in}} &\Leftrightarrow& \\
\frac{\frac{V_{out} R_{2}}{V_{in}} - R_{2}}{V_{in}} &=& \frac{- \frac{V_{out} R_{1}}{V_{in}}}{V_{in}}} &\Leftrightarrow& \\
\frac{\frac{V_{out} R_{2}}{V_{in}}}{V_{in}} - \frac{R_{2}}{V_{in}} &=& \frac{- \frac{V_{out} R_{1}}{V_{in}}}{V_{in}}} &\Leftrightarrow& \\
\frac{V_{out} R_{2}}{V_{in}^{2}}} - \frac{R_{2}V_{in}}{V_{in}^{2}} &=& \frac{- \frac{V_{out} R_{1}}{V_{in}}}{V_{in}}} &\Leftrightarrow& \\
R_{2}\frac{V_{out} - V_{in}}{V_{in}^{2}} &=& - \frac{V_{out} R_{1}}{V_{in}^{2}} &\Leftrightarrow& \\
R_{2}(V_{out} - V_{in}) &=& - V_{out} R_{1} &\Leftrightarrow& \\
R_{2} &=& - \frac{V_{out} R_{1}}{V_{out} - V_{in}} &\Leftrightarrow& \\
\end{eqnarray*}
$$

Counter-intuitively, the formula for $R_{2}$ appears to result in a negative value but one has to bear in mind that $V_{out}$ will always be smaller than $V_{in}$ such that the result will always be negative and suppress the negative sign in front of the right-hand side of the equation.

Autofire

Autofire is a game feature that allows the player to flick a hardware switch in order to make the game character shoot at the fastest possible rate thereby alleviating the player's need to mash the fire button repeatedly. Many (retro) consoles do not benefit from a built-in autofire switch. Alternative or addon controllers often had an autofire button.

On all consoles, the hardware buttons are no more than a momentary single press single throw (SPST) switch that closes a circuit and (usually) instructs the microprocessor to execute the corresponding action (ie: shoot).

As such, a circuit can be built using a NE555 timer that will rapidly make the connection between the two leads in parallel with the original hardware button.

For this mini-project, an astable circuit based on the NE555 timer is built:

                    Vcc
                     +
                     |
+--------------+-----+
|              |     |
R1         +---+-----+---+
|          |   4     8   |
+----------+ 7         3 +------+ Vout
|          |             |
R2         |    NE555    |
|          |             |
+----+-----+ 6         5 +------+
|    |     |   2     1   |      |
|    |     +---+-----+---+      |
C1   |         |     |          C2 = 10nF
|    +---------+     |          |
+--------------------+----------+
                     |
                    GND

where:

  • $R_{1}$ and $R_{2}$ are resistors,
  • $C_{1}$ and $C_{2}$ are capacitors where $C_{2}$ is fixed at $10 nF$,
  • $V_{cc}$ is the input voltage, and
  • $V_{out}$ is the output voltage that will fluctuate between high and low at the desired frequency,
  • $GND$ is ground.

The formula to calculate the frequency at which the output voltage switches between high and low is given by:

$$
f = \frac{1.44}{(R_{1} + 2 R_{2})C_{1}}
$$

The period $T$ is the time covered for one cycle, high and low:

           T
     |<--------->|
     |           |
     | T1    T0  |
     |<--->|<--->|
     |     |     |
     +-----+     +-----+
     |     |     |     |
     |     |     |     |
-----+     +-----+     +-----

where, $T_{1}$ (the time $V_{out}$ spends as high) is given by:

$$
T_{1} = 0.694 (R_{1} + R_{2}) C_{1}
$$

respectively $T_{2}$ (the time $V_{out}$ spends as low) is given by:

$$
T_{0} = 0.694 R_{2} C_{1}
$$

Empirically, a button press by a player on the hardware buttons has variable $T_{1}$ and $T_{2}$ and it does not matter whether the player spends more time with the button held down than with the button depressed when the player mashes the button.

Nevertheless, for simplicity, let us assume that the mark space ratio $M$, defined (as the ratio between the time that the button is being held down and the time that button is released):

$$
M = \frac{T_{1}}{T_{0}}
$$

is equal to $1$, meaning an equal time of the button being held down and released.

In this case, the mark space ratio will be $1$ such that we can write $T_{1} = T_{0}$ and substituting with the formulas for $T_{1}$ respectively $T_{0}$, we obtain:

$$
0.694 (R_{1} + R_{2}) C_{1} =  0.694 R_{2} C_{1} 
$$

Let $p=0.694$ for simplicity and solving:

\begin{eqnarray*}
p (R_{1} + R_{2}) C_{1} &\equiv& p R_{2} C_{1} \Rightarrow \\
R_{1} + R_{2} &\equiv& R_{2} \Rightarrow \\
R_{1} &\equiv& 0
\end{eqnarray*}

meaning that for a mark space ratio $M=1$, the value of the resistor $R_{1}$ must be $0$; in other words, the $R_{1}$ resistor is shorted (tersely, the wire itself will imply some resistance that will just be ignored).

Pedantically, the period $T$ should be equal to the CPU clock time because a higher frequency would simply not be perceived by the CPU however, the period $T$ could also be equal to the frames per second rating since a higher frequency could not be perceived on the screen.

In the end, various games accept different button mash speeds such that the period $T$ could be chosen as any value close to the FPS. In this case, let $T=0.02ms$ ($20ms$) and $M=1$ which would mean that the button will be pressed for $T_{1}=10ms$ and then depressed for $T_{0}=0.01s$ ($10ms$) and then pressed again, …

For $R_{1}=0$ both equations for $T_{1}$ and $T_{0}$ reduce to:

$$
0.01 &\equiv& 0.694 R_{2} C_{1} 
$$

and solving for $R_{2}$:

\begin{eqnarray*}
R_{2} &\equiv& \frac{0.01}{0.694 C_{1}}
\end{eqnarray*}

That is, taking values for the capacitor $C_{1}$ we can obtain the necessary value for the resistor $R_{2}$. For instance, taking a capacitor of $1 \mu F$ ($0.000001 F$), the value for $R_{2}$ is obtained:

\begin{eqnarray*}
R_{2} &\equiv& \frac{0.01}{0.694 0.000001} \\
&\approx& 11409.221892 \ldots \Omega
\end{eqnarray*}

And, as it always is the case with engineering, nobody is going to produce a $11409.221892 \ldots \Omega$ resistor, just for you. One can plot $C_{1}$ vs $R_{2}$ and select points on the curve in order to hopefully obtain practical values for $C_{1}$ and $R_{2}$:

So, let's see: when $C_{1} \approx 8 \mu F$ then $R_{2} \approx 2k \Omega$. Of course, were the values $C_{1}=8*10^{-6}$ and $R_{2}=2000$ to be substituted in the original formulas, $T = T_{1} + T_{0} \approx 11.10ms$ which is not exactly the initial goal of $10ms$ - but good enough to simulate a repeated button press!

Consoles will definitely not mind variations of the order of milliseconds when it comes to button mashing however, if leeway is to be given, then $R_{2}$ could perhaps be substituted by a variable resistor such that the period $T$ could become adjustable.

Transistor as a Switch

A 2N3904 BJT (base-junction transmitor) transistor can be used as a low-voltage switch in a circuit instead of a relay. The schematic is built around $3.3V$ which is the standard voltage used by most IoT devices.

The value of the base resistor $R_{b}$ that must be used in order to run the transistor at saturation can be calculating. Let the following circuit be a guide for the calculations:

                                    
                                    +--------+ Vcc
                                    /
+------------------+                \
^       ^          |                /
|       |          \                |  | Ic
|    Vb = Ib * Rb  / Rb             |  v
|       |          \        Ib      C
|       |          |        ->    |/
Vi      v          +---+---------B|\  hFE
|                      ^            E
|                      | Vbe        |
|                      v            |
+-----------------------------------+
                                    |
                                    - GND

We have an input voltage $V_{i}$ such as the $3.3V$ from a GPIO pin equal to the sum of the base-emitter voltage of the NPN transistor $V_{be}$ and the base voltage $V_{b}$:

$$
\begin{eqnarray*}
V_{i} &=& V_{b} + V_{be}
\end{eqnarray*}
$$

using Ohm's law, it is known that:

$$
\begin{eqnarray*}
V_{b} &=& I_{b} * R_{b}
\end{eqnarray*}
$$

Substituting, the following relation is obtained:

$$
\begin{eqnarray*}
R_{b} &=& \frac{V_{i} - V_{be}}{I_{b}}
\end{eqnarray*}
$$

In order to guarantee that the transistor operates in the saturation region, the base current is multipled by a factor of $3$, such that:

$$
\begin{eqnarray*}
R_{b} &=& \frac{V_{i} - V_{be}}{3 * I_{b}}
\end{eqnarray*}
$$

Also, knowing that BJT behave typically as a forward-biased diode with an approximate voltage drop of $\approx 0.6V$, it is obtained that $V_{i} - V_{be} \approx 0.6V$. Now, since the base-emitter voltage $V_{be}$ is usually negligible by comparison to the input voltage $V_{i}$, the formula reduces to:

$$
\begin{eqnarray*}
R_{b} &=& \frac{V_{i}}{3 * I_{b}}
\end{eqnarray*}
$$

Finally, to determine $I_{b}$, the following relation is given:

$$
\begin{eqnarray*}
$I_{b}$ &=& \frac{I_{c}}{hFE}
\end{eqnarray*}
$$

where $hFE$ is the DC gain of the transistor and $I_{c}$ is the current flowing through the collector.

Substituting for $R_{b}$ the following formula is obtained:

$$
\begin{eqnarray*}
R_{b} &=& \frac{V_{i} * hFE}{3 * I_{c}}
\end{eqnarray*}
$$

from where the value of the base resistor can be determined as a relation between the input voltage $V_{i}$, the DC gain of the transistor ($hFE$) and the collector current $I_{c}$ (also the load current).

As an example, let us assume that the device to be powered requires the load current $I_{c} \approx 100mA = 0.1A$, that the device should be toggled from a GPIO pin capable of supplying $3.3V$ and that the DC gain of the transistor $hFE = \beta = 100$.

In that case the value of the base resistor $R_{b}$ is:

$$
\begin{eqnarray*}
R_{b} &=& \frac{3.3V * 100}{3 * 0.1A} \\
&=& \frac{3300}{0.3} \\
&=& 11000 \Ohm
\end{eqnarray*}
$$

or $R_{b} = 11k\Ohm$.

The value for the load $I_{c}$ can be determined using the same schematic:

                                    
                                    +--------+ Vcc
                                    |   Ql   ^
                                    /        |
+------------------+                \ Rl   Vcc-Vce
^       ^          |                /        |
|       |          |           | Ic |        |
|       |          |           v    |        v
|       |          \                +--------+ 
|    Vb = Ib * Rb  / Rb             |        ^
|       |          \        Ib      C        |
|       |          |        ->    |/         |
Vi      v          +---+---------B|\  hFE   Vce
|                      ^            E        |
|                      | Vbe        |        |
|                      v            |        v
+-----------------------------------+--------+
                                    |
                                    - GND

where:

  • $Vbe$, $hFE = \beta$ and $Vce$ are all parameters that are given by the transistor specifications.

Knowing that every load has an internal resistance $R_{l}$ and applying Ohm's law in quadrant $Q_{l}$, the load current $I_{c}$ can be determined as:

$$
\begin{eqnarray*}
I_{c} &=& \frac{V_{cc} - V_{ce}}{R_{l}}
\end{eqnarray*}
$$

Example

Assume the following circuit:

          
 +--------- S2 +----------+
 |         3.3V           |
 - GND                    |
                          C
                        |/
 +--- S1 +----+/\/+----B|  2N3904
 |    0V     460kOhm    |\
 |                        E
 - GND                    |
                          |
                          + + (a) 864.7uV

                          + - (b)
                          |
                          - GND

When the GPIO ($S_{1}$) pin is pulled low, for instance, programatically by controlling the GPIO pin through software, the current flowing between the collector and emitter of the 2N3904 NPN BJT transistor is as low as $864.7\muV$ which is insufficient to power a device (connected to pins $a$ and $b$).

          
 +--------- S2 +----------+
 |         3.3V           |
 - GND                    |
                          C
                        |/
 +--- S1 +----+/\/+----B|  2N3904
 |   3.3V  Rb=460kOhm   |\
 |                        E
 - GND                    |
                          |
                          + + (a) 2.966V

                          + - (b)
                          |
                          - GND

When the GPIO ($S_{1}$) is pulled high, the BJT transistor will allow up to $2.966V$ to flow from $S_{2}$ through the collector and to the emitter thereby powering a device (connected to pins $a$ and $b$).

PCB Design

Given the required components consisting in just a resistor and a transistors, various PCB designs can made. Small modules can be created by using a 2N3904 transistor and an surface-mounted resistor using a dual-layer PCB. Larger modules would use a standard long resistor on the base but are still sufficiently small to serve most applications.

Shortcomings

The problem with the transistor switch is that the 2N3904 transistor will not allow a high amperage to flow through the junction such that the switch is best used to trigger digital buttons rather than act as a relay. Under no circumstance should a transistor switch be used to operate mains voltages ($220-110V$) and apparatus that might require entire amperes of power. For the latter case, a reed relay such as the R1 series from Rayex Electronics should be used instead of a transistor switch.

RC Delay Circuit

An RC circuit delays the voltage between the two poles of the resistor.

Schematic:

(a)             (b)
+----+/\/\/\+----+
         R       |
                 |
                 +
               -----
               ----- C
                 +
                 |
                 |
                 +
                 GND

After a given time $\tau$ the voltage $V_{in}$ applied at pole (a) will be forwarded to point (b) as $V_{out}$ where $V_{out} \approx 63.2\% * V_{in}$. The time $\tau$ is computed as $\tau \equals R \times C$ where $R$ is the value (in Ohms) of the resistor and $C$ is the value (in Farrads) of the capacitor.

Example

The circuit will be:

(a)             (b)
+----+/\/\/\+----+
      R=10kΩ     |
                 |
                 +
               -----
               ----- C=100nF
                 +
                 |
                 |
                 +
                 GND

Assuming:

\begin{eqnarray*}
R &=& 10k\Ohm \\
C &=& 100n F
\end{eqnarray*}

and applying $V_{in} \equals 3.3V$ to the input pin (a), the time it will take for the voltage to propagate from (a) to (b) will be:

\begin{eqnarray*}
\tau &=& R \times C \\
&=& 10000 * 0.000000001 \\
&=& 0.00001 \\
&=& 10^{-5}s
\end{eqnarray*}

and the voltage obtained at $V_{out}$ will be:

\begin{eqnarray*}
V_{out} &=& 63\% * V_{in} \\
&=& 63\% * 3.3V \\
&=& 2.08V
\end{eqnarray*}

Incidentally, this is the circuit required (page 17, ESP32 Hardware Design Guidelines V1.9) to boot an Espressif ESP32 SoC where point (a) represents the 3.3V pin, point (b) represents the CHIP_PU (or EN, enable) pin and the ground can be leveraged from any pin on the ESP32 board.

Logic Level MOSFETs

MOSFETs are a type of transistors that are capable of switching a high amount of current with a relatively small switching current provided to the base of the transistor. Logic level MOSFETs commonly have an L in their description (ex: IRLZ44) indicating that the voltage provided to the base in order to switch the current between the emitter and collector is commonly between $0$ and $3.3V$.

In order to make sure that a transistor is a logic level transistor the RDS(on) ("Static Drain-to-Source On-Resistance") and the VGS(th) (Gate Threshold Voltage) values can be inspected on the datasheet.

Typically, logic level MOSFETs will have an RDS(on) value about $5V$ and lower and the VGS(th) value is usually also very small (ie: between $1V$ and $2V$). Regular MOSFETs on the other hand will have much higher thresholds.

Logic level MOSFETs also dissipate much less heat: knowing the voltage applied to the base as well as the expected switching current:

\begin{eqnarray*}
P &=& I^{2} * \textt{RDS(on)}
\end{eqnarray*}

If the power in Watts is less than a quarter Watt, then more than likely a heatsink is not required.

Mono to Stero Converter

An interesting mono-to-stereo converter based on two LM1458 amplifiers.

Estimating the Runtime of Equipment on Batteries

Using the formula:

\begin{eqnarray*}
Wh &=& Ah * V
\end{eqnarray*}

where:

  • $Wh$ stands for Watt-Hour,
  • $Ah$ stands for Amperes-Hour and
  • $V$ for voltage

given a battery with a given $Ah$ rating and a given voltage $V$ one can determine the Watt-Hours ($Wh$) that the battery can provide. Dividing the Watt-Hours by the rating of the equipment in Watts ($W_{e}$) leads to an approximation of time (measured in hours) that the battery will be able to run the equipment for.

In other words:

\begin{eqnarray*}
t_{h} &=& \frac{Wh}{W_{e}}
\end{eqnarray*}

where:

  • $t$ is the time measured in hours,
  • $W_{e}$ is the Watt rating of the equipment

The formulas can then be combined conveniently by substituting and then solving for $t_{h}$:

\begin{eqnarray*}
Wh &=& Ah * V \\
W_{e}*t_{h} &=& Ah * V \\
t_{h} &=& \frac{Ah * V}{W_{e}}
\end{eqnarray*}

resulting in the final formula:

\begin{eqnarray*}
t_{h} &=& \frac{Ah * V}{W_{e}}
\end{eqnarray*}

where:

  • t_{h} is the time in hours that the battery will be able to run the equipment connected to the battery for,
  • $Ah$ is the Amperes-Hours rating of the battery,
  • $V$ is the Voltage rating of the battery (and the equipment),
  • $W_{e}$ is the Watt rating of the equipment

Note that many times the voltage has to be stepped or even direct current must be converted to alternative current such that in such cases the formulas would only apply at no-loss efficiency which is impossible. For instance, an inverter, a device that converts direct current to alternative current has a typical loss of $15\%$ such that the loss has to be deducted from the result.

For a lead-acid car battery, if one would calculate that some equipment could be sustained for, say, $t'$ amount of hours, discharging a lead-acid car battery beyond $50\%$ of its total charge would effectively mean killing the battery, such that a more realistic run time for the equipment would be half the calculated time, or, in other words $t_{total}=\frac{t'}{2}$, after which the battery should be disconnected. In some sense, only half a lead-acid car battery calculated watt hours are useful, whilst the other half is necessary to keep the battery itself alive. This is much different with deep-discharge batteries such as LiFePO4 batteries that an be discharged to the full of their Watt-Hour capacity.

Flyback Diode for Relays

The following circuit can often been found in many cases where "relay modules" are sold:

Vcc


+-----------------+
a                 |     +----------+ load
                  |     |
        +---------+     |
        |         |     |
        |     +---|-----|---+ rl
        |     |   3     |   |
        |     |   3     +   |
        ^     |   3 L    /  |
    D1 ---    |   3     +   |
        |     |   3     |   |
        |     +---|-----|---+
        |         |     |
        +---------+     +----------+
                  |
                  |
                 -+- b
                 /// 

The purpose of the D1 diode is to provide a flyback circuit such that when a potential is established and then broken between the points $a$ and $b$, the negative current created by inductor $L$ will not backflow and destroy any circuitry on the path between $a$ and $b$.

Transforming a Non-Latching Relay into a Latching Relay

The following sketch:

a
+-----------------+-----+
Vcc               |     |
                  |     |
             SWt \      |
                  +     |
                  |     |
        +---------+     |
        |         |     |
        |     +---|-----|---+ RLY
        |     |   3     |   |
        |     |   3     +   |
        |     |   3 L    /  |
        |     |   3     +   |
        |     |   3     |   |
        |     +---|-----|---+
        |         |     |
        +---------------+-------+
                  |      x      |
                  |             | |
                  +             | | load
             SWr |              | v 
                  +             |
                  |             |
                  |             |
                 -+- b         -+- c
                 ///           ///

illustrates a circuit containing a non-latching relay $RLY$ that has been transformed into a latching relay by connecting the relay inductor $L$ to the line that is supposed to carry the voltage load $V_{cc}$. One limitation of this circuit is that the coil voltage must equal the load voltage (which can be rare).

The switches $SW_{t}$ and $SW_{r}$ represent the trigger, respectively the reset switches that carry the functions of engaging the relay, when the trigger switch ($SW_{t}$) is engaged, respectively breaking the circuit when the reset switch ($SW_{r}$) switch is pressed.

In order to understand the circuit, the load line is followed, between $V_{cc}$ and $c$ whilst paying attention to the state of the switches $SW_{t}$ and $SW_{r}$.

The following table will summarize the states of the switches, relative to the state of the switches but with the mention that the table should be read linearly as a sequence of states, from top to bottom, rather than an instantaneous display of states.

$SW_{t}$ $SW_{r}$ Outcome
depressed depressed With both switches depressed, the coil voltage is zero $V_{L} = 0$, the load voltage is zero $V_{load}= 0$ such that the circuit is off and cannot bear a load.
depressed pressed With $SW_{t}$ depressed and $SW_{r}$ pressed, the coil voltage is zero ($V_{L} = 0$) due to current not being able to flow neither between $a$ and $b$ nor between $a$ and $c$ such that the circuit is off and cannot bear a load.
pressed pressed With $SW_{r}$ held down and $SW_{t}$ pressed, the coil voltage will be equal to $V_{cc}$ ($V_{L} = V_{cc}$) with current flowing between $a$ and $b$, the relay $RLY$ will be engaged and current will flow between $a$ and $c$ such that the circuit will be on and capable of bearing a load.
depressed pressed With $SW_{r}$ held down and now the switch $SW_{t}$ released, a circuit is still formed between $a$, $b$ and $c$ (via junction $x$) such that the circuit is on and can still bear a load.
depressed depressed Now, when $SW_{r}$ is released, the coil circuit between $a$ and $b$ is broken, such that the relay $RLY$ decouples, and with the relay decoupled, the load circuit between $a$ and $b$ is also broken, such that the circuit turns off and no load can be powered.

The following video is a simulation using the circuit simulator at https://www.falstad.com/circuit/ of the latching relay circuit that follows the state changes described in the table and illustrates the latching functionality (the voltmeter is replaced by a LED):

Even though the theory (and even the simulation) are abstractions, it must be noted that in practice, the trigger switch $SW_{t}$ does not consist of a typical mechanical switch but more than likely be a mini-circuit itself (and perhaps even similar to the transistor switch), such that the "latching behaviour" that this circuit exhibits becomes more apparent and useful.


fuss/physics/electronics.txt · Last modified: 2024/04/04 17:30 by office

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.