Download - CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015
![Page 1: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/1.jpg)
CSCI1600: Embedded and Real Time SoftwareLecture 14: Input/Output II
Steven Reiss, Fall 2015
![Page 2: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/2.jpg)
Input Management
We can attach inputs to the Arduino Directly or indirectly
What are the problems Sampling
Latency
Conditioning
Range, sensitivity, noise
![Page 3: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/3.jpg)
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
![Page 4: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/4.jpg)
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
![Page 5: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/5.jpg)
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
![Page 6: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/6.jpg)
Input Issues
Pull-Up Set Arduino switch mode
![Page 7: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/7.jpg)
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
![Page 8: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/8.jpg)
Response Curves Different devices react
differently Can be linear, log, …
Can saturate
![Page 9: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/9.jpg)
Response Curves
May be other Specific to the device
![Page 10: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/10.jpg)
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?
![Page 11: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/11.jpg)
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)
![Page 12: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/12.jpg)
Low Pass Filter
![Page 13: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/13.jpg)
Analog Signals
Include Noise Need to know S/N ratio
Input should take this into account
![Page 14: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/14.jpg)
Input Issues: Analog to Digital
Analog signals are continuous, digital discrete
Digital signal Set of bits (8, 12, …)
Binary value represents the voltage level
![Page 15: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/15.jpg)
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
![Page 16: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/16.jpg)
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
![Page 17: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/17.jpg)
Analog to Digital
![Page 18: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/18.jpg)
Input Arrays
Does this work? What can go wrong
![Page 19: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/19.jpg)
Input Array Issues
![Page 20: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/20.jpg)
Input Array Issues
![Page 21: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/21.jpg)
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
![Page 22: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/22.jpg)
Acceptable Latency
Reaction should be << 100 ms 100 ms is noticable
How is latency affected by conditioning How does this affect the sampling rate
![Page 23: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/23.jpg)
Output Array
![Page 24: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/24.jpg)
Output Array Alternatives
![Page 25: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/25.jpg)
Output Issues: Glitches
Intermediate values Output glitches
Arduino library minimizes these
![Page 26: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015](https://reader036.vdocument.in/reader036/viewer/2022062519/5697c01f1a28abf838cd1acf/html5/thumbnails/26.jpg)
Homework (for Wednesday)
Read Chapters 8 and 9 Hardware issues are for your enlightenment
We will concentrate on the programming issues