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