csci1600: embedded and real time software lecture 14: input/output ii steven reiss, fall 2015

26
CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015

Upload: derrick-fisher

Post on 19-Jan-2016

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015

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

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

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

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

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

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

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

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

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

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

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

Low Pass Filter

Page 13: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015

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

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

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

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

Analog to Digital

Page 18: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015

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

Input Array Issues

Page 20: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015

Input Array Issues

Page 21: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015

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

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

Output Array

Page 24: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015

Output Array Alternatives

Page 25: CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015

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

Homework (for Wednesday)

Read Chapters 8 and 9 Hardware issues are for your enlightenment

We will concentrate on the programming issues