Digital Input Guide: Difference between revisions

From Phidgets Support
No edit summary
No edit summary
 
(29 intermediate revisions by 5 users not shown)
Line 1: Line 1:
[[Category: Primer]]
{{#seo:|description=A digital input is a device that can read the state of a digital signal. Digital signals are either high or low (1 or 0). Check out this guide for more information.}}
{{#seo:|keywords=digital input}}
[[Category:IntroGuide]]


==Introduction==
==Introduction==


Digital Inputs can be used to convey the state of various devices such as push buttons, limit switches, relays, or logic level outputs.
Digital Inputs can be used to convey the state of various devices such as push buttons, limit switches, relays, or logic level outputs.
They have two states: Low (or TRUE), and High (or FALSE).
Any signal that is expected to interact with more than just these 2 states is inappropriate for this type of input. 


Digital inputs are one of the easiest components to work with, since all that is required is a simple check to see which state they are in when an event triggers.
Digital Inputs are one of the easiest components to work with, since all that is required is a simple check to see which state they are in when an event triggers.


==Specifications==
If you think your project could benefit from the use of digital inputs, check out this list of {{CT|HasDI|Phidgets with Digital Inputs}}


===Digital Input Hardware Filter===
===Phidget Digital Input Types===
There is built-in filtering on the digital input, to eliminate false triggering from electrical noise.
The digital input is first RC filtered by a 15K/100nF node, which will reject noise of higher frequency than 1Khz.
This filter generally eliminates the need to shield the digital input from inductive and capacitive coupling likely to occur in wiring harnesses.
You can further reduce noise by externally filtering the input signal, but you will lose sensitivity in the process.


===Digital Input Hysteresis===
Phidgets Digital Inputs fall into one of two categories: '''Active Low''' and '''Active High'''.
The digital input has hysteresis - that is, it will hold it’s current state (false or true), unless a large change occurs. 
To guarantee FALSE, the digital input must be at least 3.75V, and to guarantee TRUE, the digital input must be less than 1.25V.


===Digital Input Sampling Characteristics===
'''Active Low''' digital inputs will most often be used to detect whether a switch between the input and ground has been closed. These inputs will report TRUE when the switch is ''closed'' and FALSE when the switch is ''open''.
The state of the digital inputs are reported back to the PC periodically. 
During this sampling period, if a digital input was true for greater than 4.0ms, the digital input is guaranteed to be reported as true in software. 
This makes the digital input much more sensitive to reporting TRUE state, and makes it useful to watch for short events. 
Any Digital Input True events of less than 1.5ms are never reported.


===Electrical Specifications===
More generally, '''Active Low''' digital inputs consider their state to be TRUE when the voltage is closer to 0V (''low''), and FALSE when closer to 5V (''high'').


[[Image:digital_input.jpg|right|thumb|Schematic for a Phidgets digital input.]]
'''Active High''' digital inputs are designed to detect the presence of an external voltage-based digital signal. These inputs will report TRUE when the voltage on the input is above a given threshold (''high''), and FALSE when the input voltage is close to 0V (''low'').


The digital inputs have a built in 15K pull-up resistor. 
See the specification table on your Phidget's product page to determine if your device has Active High or Active Low inputs and to see the exact voltage levels they switch at.
By connecting external circuitry, and forcing the input to Ground, the Digital Input in software will read as TRUE. 
The default state is FALSE - when you have nothing connected, or your circuitry (switch, etc) is not pulling the input to ground.


<br clear="all">
==Technical Details==
==Using the Digital Inputs==
Here are some circuit diagrams that illustrate how to connect various devices to the digital inputs on your Phidget.


===Wiring a switch to a Digital Input===
===Logic Levels===
[[Image:LogicLevel_visualization.jpg|link=|right|450px|thumb|This visualization shows how a digital signal would be interpreted on the digital inputs on the HUB0000. The black line shows the kind of pulse that would be made by a switch being pressed. Anything below 1V will be considered '''low''', anything above 1.8V is guaranteed to be '''high'''.]]
Digital Inputs have two states: Low and High. These states, called logic levels, refer to the voltage on the input being measured. If the voltage is above a given threshold, it is considered High, and if it is below a lower threshold it is considered Low.


[[Image:switch_digital_input.jpg|right|thumb|Schematic for connecting a switch to a digital input.]]
In simple terms, with a 5V Digital Input, it is guaranteed that 5V will be High, and 0V will be Low.


Closing the switch causes the digital input to report TRUE.
For a more specific example, on the [{{SERVER}}/products.php?product_id=HUB0000 HUB0000], the minimum voltage for a guaranteed High logic level to be detected is 1.8V DC, while the highest guaranteed Low voltage is 1V. The input signal should avoid staying at any voltage between these two values, as it will produce inconsistent results. You can find these thresholds on your Phidget's product page under the headings 'High Voltage Min' and 'Low Voltage Max'.


<br clear="all">
Any signal that is expected to interact with more than just these 2 states is inappropriate for this type of input.
===Monitoring the Position of a Relay===


[[Image:relay_position.jpg|right|thumb|Schematic for connecting to a relay.]]
===Ground Protection===
Ground terminals on many digital inputs share a common ground with with USB ground. 
If your digital input is not internally isolated, these terminals will expose the USB ground potential of the PC to which they are connected.
Be sure you are completely familiar with any circuit you intend to connect to the digital input before it is connected. 
If a reverse voltage or dangerously high voltage is applied to the input or output terminals, damage to the Phidget or the PC may result.


The relay contact can be treated as a switch, and wired up similarly. 
===Unknown State===
When the relay contact is closed, the Digital Input will report TRUE.
If you poll the state of the Digital Input too soon after it has attached, before the device has had a chance to send its state information, you will get an unknown state error. Be sure to check the error codes when getting the state to ensure it is valid.
 
<br clear="all">
===Detecting an External Voltage with an N-Channel MOSFET===
 
[[Image:external_voltage_mosfet.jpg|right|thumb|Schematic for detecting voltage with a NMOS transistor.]]
 
A MOSFET can be used to detect the presence of an external voltage. 
The external voltage will turn on the MOSFET, causing it to short the Digital Input to Ground. 
If the MOSFET is conducting > 270uA, the Digital Input is guaranteed to report TRUE.  
If the MOSFET is conducting < 67uA, the Digital Input is guaranteed to report FALSE.
The voltage level required to turn on the MOSFET depends on the make of of MOSFET you are using. Typical values are 2V-6V.
 
<br clear="all">
===Isolating a Digital Input with an Optocoupler===
 
[[Image:isolating_digital_input_optocoupler.jpg|right|thumb|Schematic showing isolation of a digital input with an optocoupler.]]
 
When driving current through the LED, the Digital Input will report TRUE. 
The amount of current required will depend on the optocoupler used. 
Design to sink at least 270uA to cause the digital input to report TRUE, and less than 67uA to report FALSE.
 
<br clear="all">
===Detecting an External Voltage with an NPN Transistor===
 
[[Image:external_voltage_npn.jpg|right|thumb|Schematic for detecting voltage with an NPN transistor.]]
 
This circuit can be used to measure if a battery is connected, or if 12V (for example) is on a wire.
By designing to have Collector-Emitter current > 270uA, the digital input will report TRUE.
 
<br clear="all">
===Using a Capacitive or Inductive Proximity Switch===
 
[[Image:proximity_switch.jpg|right|thumb|Schematic for connecting to a proximity switch.]]
 
Capacitive proximity switches can detect the presence of nearby non-metallic objects, whereas inductive proximity switches can detect only the presence of metallic objects. 
To properly interface one of these proximity switches to the digital inputs, a 3-wire proximity switch is required, as well as an external power supply.
We have checked the following switch from Automation Direct to verify that it works with the Digital Inputs. 
Similar capacitive or inductive proximity switches from other manufacturers should work just as well.
 
{|border=1
|+'''Switches'''
|-
! Manufacturer
! Web Page
! Capacitive Part No.
! Inductive Part No.
|-
| Automation Direct
| www.automationdirect.com
| CT1 Series
| AM1 Series
|}
 
<br clear="all">
===Using an FSR or Variable Resistor as a Switch===
 
[[Image:fsr_switch.jpg|right|thumb|Schematic for using an FSR as a switch.]]
 
The digital inputs can be easily wired to use many variable resistors as switches.
If the resistance falls below 3.75k Ohms, the Digital Input will go TRUE.
If the resistance rises above 75k Ohms, the Digital Input will go FALSE.
 
<br clear="all">
 
==Glossary==
===Update Rate===
*125 samples/sec is for each individual channel, not split between all channels.
*You can't "turn off" unused channels to improve update rate on the active channels.
*This value is already close to the spec for our USB processor, so there isn't much room for users to tinker with this spec.

Latest revision as of 20:09, 26 June 2023


Introduction

Digital Inputs can be used to convey the state of various devices such as push buttons, limit switches, relays, or logic level outputs.

Digital Inputs are one of the easiest components to work with, since all that is required is a simple check to see which state they are in when an event triggers.

If you think your project could benefit from the use of digital inputs, check out this list of Phidgets with Digital Inputs

Phidget Digital Input Types

Phidgets Digital Inputs fall into one of two categories: Active Low and Active High.

Active Low digital inputs will most often be used to detect whether a switch between the input and ground has been closed. These inputs will report TRUE when the switch is closed and FALSE when the switch is open.

More generally, Active Low digital inputs consider their state to be TRUE when the voltage is closer to 0V (low), and FALSE when closer to 5V (high).

Active High digital inputs are designed to detect the presence of an external voltage-based digital signal. These inputs will report TRUE when the voltage on the input is above a given threshold (high), and FALSE when the input voltage is close to 0V (low).

See the specification table on your Phidget's product page to determine if your device has Active High or Active Low inputs and to see the exact voltage levels they switch at.

Technical Details

Logic Levels

This visualization shows how a digital signal would be interpreted on the digital inputs on the HUB0000. The black line shows the kind of pulse that would be made by a switch being pressed. Anything below 1V will be considered low, anything above 1.8V is guaranteed to be high.

Digital Inputs have two states: Low and High. These states, called logic levels, refer to the voltage on the input being measured. If the voltage is above a given threshold, it is considered High, and if it is below a lower threshold it is considered Low.

In simple terms, with a 5V Digital Input, it is guaranteed that 5V will be High, and 0V will be Low.

For a more specific example, on the HUB0000, the minimum voltage for a guaranteed High logic level to be detected is 1.8V DC, while the highest guaranteed Low voltage is 1V. The input signal should avoid staying at any voltage between these two values, as it will produce inconsistent results. You can find these thresholds on your Phidget's product page under the headings 'High Voltage Min' and 'Low Voltage Max'.

Any signal that is expected to interact with more than just these 2 states is inappropriate for this type of input.

Ground Protection

Ground terminals on many digital inputs share a common ground with with USB ground. If your digital input is not internally isolated, these terminals will expose the USB ground potential of the PC to which they are connected. Be sure you are completely familiar with any circuit you intend to connect to the digital input before it is connected. If a reverse voltage or dangerously high voltage is applied to the input or output terminals, damage to the Phidget or the PC may result.

Unknown State

If you poll the state of the Digital Input too soon after it has attached, before the device has had a chance to send its state information, you will get an unknown state error. Be sure to check the error codes when getting the state to ensure it is valid.