CSCI1600: Embedded and Real Time SoftwareLecture 14: Input/Output II
Steven Reiss, Fall 2015
Input Management
We can attach inputs to the Arduino Directly or indirectly
What are the problems Sampling
Latency
Conditioning
Range, sensitivity, noise
A simple switch
You want to read the switch Can’t do it continually – you need to sample
How fast should you sample?
What does this depend upon? Minimum On time
Minimum Off time
Bouncing
Switch Input
Ideal Switch Assume min on-time is 2 units
Assume min off-time is 1 units
What is the minimum sampling rate
What is a safe sampling rate
Minimum inter-event sampling time
Might need to compute these values
Switch Input
Real switches bounce Input takes some time to stablize
Possibly 10-20 ms
What happens if you sample faster than that
Debouncing Sample > 50 ms
Condition the inputs
Check it is on/off for at least k samples
Input Issues
Pull-Up Set Arduino switch mode
Sampling Actual Signals
Actual signals are continuous Digital inputs are discrete
Certain number of values
This determines the accuracy of your input
Sensors have different response curves
Response Curves Different devices react
differently Can be linear, log, …
Can saturate
Response Curves
May be other Specific to the device
Sampling Changing Inputs
Suppose we sample audio How fast should we sample?
Need to avoid aliasing Need to be > 2 times the maximum
input frequency
What is audio range?
Aliasing
Suppose there is a high-frequency component to the input What would this show up as in low-frequency sampling?
Need for a low-pass (anti-aliasing) filter Can be done in software (if you sample fast enough)
Very easy to do in hardware (capacitor and resistor)
Low Pass Filter
Analog Signals
Include Noise Need to know S/N ratio
Input should take this into account
Input Issues: Analog to Digital
Analog signals are continuous, digital discrete
Digital signal Set of bits (8, 12, …)
Binary value represents the voltage level
Analog-Digital Conversion
Range Highest and lowest possible values (0 ..5, -2 .. 2)
Precision Number of bits (0..255, 0..1023, …)
This is all you can tell apart
Sampling Rate How fast the ADC can sample (its not immediate)
Samples per second
How a ADC works
Successive approximation Controller guesses next value
DAC converts guess to analog value
Comparator sees compares input and reference value
Controller takes result and makes next guess
Analog to Digital
Input Arrays
Does this work? What can go wrong
Input Array Issues
Input Array Issues
Latency
Difference in time between input and corresponding output What if user pushes switch for his TTT move
The machine does computation to determine its move
Then it turns on both lights
Would this work?
Difference between setting output and actual output Motor won’t react immediately
Acceptable Latency
Reaction should be << 100 ms 100 ms is noticable
How is latency affected by conditioning How does this affect the sampling rate
Output Array
Output Array Alternatives
Output Issues: Glitches
Intermediate values Output glitches
Arduino library minimizes these
Homework (for Wednesday)
Read Chapters 8 and 9 Hardware issues are for your enlightenment
We will concentrate on the programming issues