Lecture 11 - Sensors Flashcards
What are the general understandings of sensors?
- There are millions of different sensor types
- You have to select the right one for your application and budget and read the specs
- Some sensors require also input from CPU E.g. activation/deactiv., triggering data transfer, …
- Our scope here is more on interfacing sensors than on understanding the sensors themselves
What are some typical sensor outputs?
Typical Sensor Outputs
* Binary signal (0 or 1) -> Tactile sensor
* Analog signal (e.g. 0..5V) -> Inclinometer
* Timing signal (e.g. PWM) -> Gyroscope
* Serial link (RS232 or USB) -> GPS Module
* Parallel link -> Digital Camera
What are binary sensors?
Tactile sensor / switch
* Easy to be interfaced
* Use a resistor and link to digital input of CPU or latch
Refer to slides
What is the contact bounce effect?
Problem:
* When activating switch, contact moves up and down several times (“contact bounce” or “switch bounce”)
* Bad when counting pulses or in user menus → incorrect results !
Refer to slides
What is the solution to the contact bounce effect?
Solutions:
* Hardware:
Analog: resistor-capacitor circuit
Digital: flip-flop with single-pole/double-throw switch
* Software:
Wait certain delay time before allowing next change (Refer to slides for code)
What is an encoder - specifically a shaft encoder?
Shaft encoder
* incremental or absolute position (refer to slides)
What is an encoder - specifically an incremental encoder?
- Usually requires 2 sensors to determine speed and direction
- See motor control
The technology necessary - Magnet + hall sensors (incremental)
- Optical sensors with black/white segments
(incremental)
What is the general understanding of an encoder?
- Encoder signal (2 lines) are connected to microcontroller like 2 binary sensors (2 digital input lines)
- Microcontrollers usually have special internal registers for pulse counting
This is done in parallel to normal calculations
Does not slow down the CPU
General data input - A data transfer can be?
A data transfer can be
1. CPU-initiated (“polling”)
2. Device-initiated (“interrupt”)
What is polling?
Read device input without interrupt
Refer to slides (NEED TO KNOW CODE)
- CPU-initiation → Polling
– CPU initiates read/write with IN/OUT instruction
– Timing relies only on CPU
– May have to do this in loop in case device is not ready
→ “busy-wait loop” → loss of CPU time → inefficient
What is a quadrature encoder?
A quadrature encoder is like a car’s odometer, but can run forwards or backwards
What are encoder counting methods?
- Counting in the “foreground” program wastes compute time that may be required for other tasks
- Counting in “foreground” may take too long, so it misses counts for faster signals (e.g. wheel spinning faster).
→ Solution: Interrupts
What are interupts?
Read device data with interrupt
Refer to slides
- Device-initiated → Interrupts
– Device signals CPU that it is ready via special interrupt line
– CPU interrupts whatever it was doing and calls special “interrupt service routine” (ISR)
– CPU returns to previous task after finishing ISR (like subroutine)
Define interupts
- Execution of one program (user) is temporarily suspended for another program with higher priority (somewhat like a unscheduled subroutine call)
- Sometimes also called exception
- Interrupts can be raised either by software (special CPU command) or by hardware (external signals linked to CPU interrupt lines)
- Many embedded systems have interrupts that occur at regular time intervals (e.g. every 0.01s)
timer interrupts
Refer to slides
What are digital sensors?
Digital sensors are
* usually more complex than analog sensors
* often more accurate than analog sensors
* sometimes analog sensors with built-in A/D converters
Refer to slides
How can you interface digital sensors?
How to interface this sensor to a controller?
* Hardware
* Software
Refer to slides (NEED TO KNOW CODE)
What are Analog Sensors and A/D Converter?
A number of sensors have analog output signal rather than digital signals
A/D converter is required to connect to CPU
Examples:
* Microphone
* Analog infrared distance sensor
* Analog compass
* Barometer sensor
What do A/D Converters do?
- Transform analog signal into a sequence of numbers
- Sampling rate and conversion number range will determine digitizing quality (how accurately the signal will be digitized)
- There will be some information loss
- Signal has to be provided at correct level, e.g. between 0 .. 5V
What are the three versions of A/D Converters?
Version 1: Parallel (e.g. 8 bit, direct connection to data bus)
Version 2: Serially digital, Provide clock signal to converter to read bit by bit
Version 3: Serially digital with multiple inputs, Requires an analog multiplexer
Refer to slides
What are PWM sensors?
We have already seen PWM for:
* Velocity control for DC motors
* Position specification for servos
Now we see PWM for:
* Sensor data
* Examples:
– Accelerometer
– Gyroscope
– Inclinometer
What is elaspsed time?
Elapsed time (e.g. in ms) will then be the digital sensor value
What is sensor calibration?
Sensor output may be linear or nonlinear to measured dimension:
* Before a (digitized) sensor value can be used in an embedded system, its data has to be calibrated
* Linear relationship: a few initial measurements are sufficient
* Non-linear measurements: complete measurement table is required
* During runtime us: formula for simple relationships lookup table for arbitrary relationships use interpolation for values between entries (simple and efficient)