Figure 2.8-5. Passive Hardware Debounce
Figure 2.8-5 shows one possible configuration for passive hardware debounce. First, consider the case where the 1 kΩ resistor is
replaced by a short circuit. When the switch closes it immediately charges the capacitor and the digital input sees logic low, but
when the switch opens the capacitor slowly discharges through the 22 kΩ resistor with a time constant of 22 ms. By the time the
capacitor has discharged enough for the digital input to see logic high, the mechanical bouncing is done. The main purpose of the
1 kΩ resistor is to limit the current surge when the switch is closed. 1 kΩ limits the maximum current to about 5 mA, but better
results might be obtained with smaller resistor values.
2.8.1.4 - Output: Controlling Relays
All the digital I/O lines have series resistance that restricts the amount of current they can sink or source, but solid-state relays
(SSRs) can usually be controlled directly by the digital I/O. The SSR is connected as shown in the following diagram, where VS (~5
volts) connects to the positive control input and the digital I/O line connects to the negative control input (sinking configuration).
Figure 2.8-6. Relay Connections (Sinking Control, High-Side Load Switching)
When the digital line is set to output-low, control current flows and the relay turns on. When the digital line is set to input, control
current does not flow and the relay turns off. When the digital line is set to output-high, some current flows, but whether the relay is
on or off depends on the specifications of a particular relay. It is recommended to only use output-low and input.
For example, the Series 1 (D12/D24) or Series T (TD12/TD24) relays from Crydom specify a max turn-on of 3.0 volts, a min turn-
off of 1.0 volts, and a nominal input impedance of 1500 Ω.
When the digital line is set to output-low, it is the equivalent of a ground connection with 180 Ω (EIO/CIO) or 550 Ω (FIO) in
series. When using an EIO/CIO line, the resulting voltage across the control inputs of the relay will be about
5*1500/(1500+180) = 4.5 volts (the other 0.5 volts is dropped across the internal resistance of the EIO/CIO line). With an FIO
line the voltage across the inputs of the relay will be about 5*1500/(1500+550) = 3.7 volts (the other 1.3 volts are dropped
across the internal resistance of the FIO line). Both of these are well above the 3.0 volt threshold for the relay, so it will turn on.
When the digital line is set to input, it is the equivalent of a 3.3 volt connection with 100 kΩ in series. The resulting voltage
across the control inputs of the relay will be close to zero, as virtually all of the 1.7 volt difference (between VS and 3.3) is
dropped across the internal 100 kΩ resistance. This is well below the 1.0 volt threshold for the relay, so it will turn off.
When the digital line is set to output-high, it is the equivalent of a 3.3 volt connection with 180 Ω (EIO/CIO) or 550 Ω (FIO) in
series. When using an EIO/CIO line, the resulting voltage across the control inputs of the relay will be about
1.7*1500/(1500+180) = 1.5 volts. With an FIO line the voltage across the inputs of the relay will be about
1.7*1500/(1500+550) = 1.2 volts. Both of these in the 1.0-3.0 volt region that is not defined for these example relays, so the
resulting state is unknown.
Note that sinking excessive current into digital outputs can cause noticeable shifts in analog input readings. For example, the FIO
sinking configuration above sinks about 2.4 mA into the digital output to turn the SSR on, which could cause a shift of roughly 1 mV
to analog input readings.
Mechanical relays require more control current than SSRs, and cannot be controlled directly by the digital I/O on the U3. To control
higher currents with the digital I/O, some sort of buffer is used. Some options are a discrete transistor (e.g. 2N2222), a specific
chip (e.g. ULN2003), or an op-amp.
Note that the U3 DACs can source enough current to control almost any SSR and even some mechanical relays, and thus can be
a convenient way to control 1 or 2 relays. With the DACs you would typically use a sourcing configuration (DAC/GND) rather than
sinking (VS/DAC).
The RB12 relay board is a useful accessory available from LabJack. This board connects to the DB15 connector on the U3 and
accepts up to 12 industry standard I/O modules (designed for Opto22 G4 modules and similar).
Another accessory available from LabJack is the LJTick-RelayDriver. This is a two channel module that plugs into the U3 screw-
terminals, and allows two digital lines to each hold off up to 50 volts and sink up to 200 mA. This allows control of virtually any solid-
state or mechanical relay.
2.9 - Timers/Counters
The U3 has 2 timers (Timer0-Timer1) and 2 counters (Counter0-Counter1). When any of these timers or counters are enabled, they
take over an FIO/EIO line in sequence (Timer0, Timer1, Counter0, then Counter1), starting with FIO0+TimerCounterPinOffset.
Some examples:
1 Timer enabled, Counter0 disabled, Counter1 disabled, and TimerCounterPinOffset=4:
FIO4=Timer0
15