tkt-3500 microcontroller systems 8 – external modules and sensors for mcu applications ... 1 2 3...
TRANSCRIPT
TKT-3500
Microcontroller
systems
Lec 8 – External Modules and Sensors
for MCU applications
Teemu Laukkarinen
Department of Computer Systems
Tampere University of Technology
Fall 2011
Copyright Tampere University of Technology Department of Computer Systems
#2/67
Contents
What sort of components exist and can be
used with a MCU
Through serial interfaces, buses, or GPIO
Sensors, flash-memories, ethernet/usb
connectivity, displays, user interfaces
Copyright Tampere University of Technology Department of Computer Systems
#3/67
Introduction
MCU itself is useless in any embedded system
In many applications MCUs use sensors to
inspect physical world
MCUs interact with physical world through
actuators
Many embedded systems have user interfaces
Displays, buttons, detectors etc.
In modern world, many applications require
communication from the MCU: so called M2M
Ethernet, wireless, USB, BT
Copyright Tampere University of Technology Department of Computer Systems
#4/67
Basic paradigm for (MCU) applications
Copyright Tampere University of Technology Department of Computer Systems
INPUT OUTPUT TEMPUT
”BACKPUT” (Feedback)
Disclaimer: Vuoden 2011 paras
luentokalvo –
palkintokandidaatti
Sensors
User inputs
Other machines
Actuators: motors,
relays, switches
Displays
Other machines
MCU with macig software
#5/67
EXAMPLE SENSORS
Copyright Tampere University of Technology Department of Computer Systems
#6/67
Temperature Sensor Maxim DS620
Operating voltage: 1.7 – 3.5 V
Communication: I2C
Selectable resolution:
LSB 0.5°C, 0.25°C, 0.125°C or 0.0625°C
Conversion time depends on accuracy
10 bit 25 ms, 13 bit 200 ms
Continuos conversion and one shot modes
Image: www.maxim-ic.com
Copyright Tampere University of Technology Department of Computer Systems
#7/67
Humidity: Sensirion SHT1x
Humidity AND temperature sensor
Operating voltage: 2.4 – 5.5 V
Communication: ”almost I2C” Not compatible with standard I2C interface
Conversion times: 11 ms (8 bit)
210 ms (14 bit)
Accuracy: Humidity 2 %, temperature 0.3 °K
Current consumption: Sleep 0,3 uA, measuring 550 uA
Copyright Tampere University of Technology Department of Computer Systems
#8/67
Accelerometer: VTI SCA3000
3D accelerometer
Operating voltage: 2.35 – 3.6 V
Communication: SPI
Modes:
Free fall detection
Motion detection
Normal mode
Current consumption 120 uA in active mode
Image: www.vti.fi
Copyright Tampere University of Technology Department of Computer Systems
#9/67
Compass: Hitachi HM55B
Operating voltage: 4.8 – 5.2 V
Communication: SPI
Transmission length 4 bits (normal SPI 8 bits)
Current consumption: Sleep 1 uA, Measuring
9 mA
Measuring time 30 ms
Resolution: 11 bits
Measures magnetic field strength
Min. value -180 uT max. 180 uT
Image: www.parallax.com
Copyright Tampere University of Technology Department of Computer Systems
#10/67
Luminance: Agilent APDS-9002
Photosensor: Luminance is relative to current
Operating voltage: 2.4 – 5.5 V
Connected to uC’s analog-to-digital converter
Resolution equals AD-converter’s resolution
10 bit in PIC18LF8722
Sample rate = ADC’s sample rate
In PIC user selectable, but depends on clock
frequency. About 1 Mhz is theoretical maximum
PIC’s AD-converter operates also in idle
mode
Completion of conversion can cause an interrupt
Image: www.farnell.com
Copyright Tampere University of Technology Department of Computer Systems
#11/67
PIR MS300
PIR = Passive Infra Red
Connected to uC’s I/O, but needs an operating
voltage
Used as motion detector
Operating voltage: 2.6 V – 5.5 V
Current consumption: ~35 uA
Copyright Tampere University of Technology Department of Computer Systems
#12/67
VGA C328
Max. 640x480 pixels, 16 bit
Frames/s depends on image quality
JPEG still picture with best quality 0.75 fps
Camera + compression module + EEPROM
No extra components needed
Connection: RS-232
JPEG picture format
Operating voltage: 3.0 – 3.6 V
Operation current: 60 mA
Suspend current: 100 uA
Image: www.electronics123.net
Copyright Tampere University of Technology Department of Computer Systems
#13/67
GPS: iTrax03-s+GeoHelix–S
Fasttrax iTrax03-s
Includes lots of functionality: only few
extra components needed
Communication: USART with NMEA
(National Marine Electronics Association)
messages
Operating voltage: 2.7 – 3.3 V
Max power dissipation 500 mW
Sarantel GeoHelix-S
Active GPS antenna
Operating voltage: 2-3.5 V
Typical current 15 mA Copyright Tampere University of Technology Department of Computer Systems
#14/67
Microphone AOM-6746P-R
Capacitor microphone
Omnidirectional
Picks up sound evenly from all directions
Connection: ADC
PIC18LF8722 has 16 ADC channels, but one converter
Nyqvist frequency: to record 20kHz frequency, sampling
must be done at 40kHz rate
Image: www.farnell.com
Image: www.farnell.com Copyright Tampere University of Technology Department of Computer Systems
#15/67
Capacitive sensor
Measures capacitance between two inputs
Outputs raw values through a serial interface
(typically I2C)
or interrupts via output pins
Can be used for user interfaces, detect changes in
near by environment (e.g. something is removed or
brought near by)
In my experience, both conductors and insulators can be
detected (but cannot be necessarily classified)
Copyright Tampere University of Technology Department of Computer Systems
#16/67
Capacitive sensor - Application
Everyone knows the iPod click wheel?
Wheel is an X input capacitive sensor
The user input direction can be figured out by following
the interrupts associated with the X inputs of the sensor
Example: 2 pieces of Analog Devices AD7156
Copyright Tampere University of Technology Department of Computer Systems
MCU
Sensor
Interrupts
1
2 3
#17/67
More..
1-wire sensors
Acoustic proximity sensors
Gases
HALL –sensor
Pressure
More?
Copyright Tampere University of Technology Department of Computer Systems
#18/67
ACTUATORS
Copyright Tampere University of Technology Department of Computer Systems
#19/67
Motors (1)
MCUs control motors in many applications
Robotics, CNC machinery, air conditioning, cars…
Two types: ”fixed” position motors and speed
controlled motors
Fixed position motors can be instructed to stay standstill
in one position
Step motors, servo motors, linear actuators
Speed controlled continue rotating at some speed
Copyright Tampere University of Technology Department of Computer Systems
#20/67
Motors (2) - Common problems/challenges
Motors require more current than MCU can provide -> an
external motor controller is needed, which can drive high
current to the motor according to the MCU’s commands
Motors have limited torque
If load is constant, some motors require more power to get
moving from standstill than when running
This requires actions in certain applications (more info on coming
slides)
Variable load can cause trouble, thus limit switches are
needed
calibration must be done, if limit is not reached when supposed to,
or if limit is reached unexpectedly
Copyright Tampere University of Technology Department of Computer Systems
#21/67
Step motors (1)
Constant power, torque decreases when speed increases
are moved in steps, eg. 360 steps per round
A controller is needed
when step motor is kept standstill, it basically is a short circuit and
draws all the current it can (holding torque)
MCU can command motor to go one step (or half-step) through the
controller
A phase is associated to running/rotating motor (self-study more)
Calibrate motor to a position with a switch or a potentiometer,
then calculate steps and motor position is known relatively to
the calibration point
E.g. CNC machines use this method (Google DIY CNC machine)
Beware of skipping steps, thus always use limit switches or
potentiometers
Copyright Tampere University of Technology Department of Computer Systems
#22/67
Step motors (2)
Can skip steps, if the load is too high (or resonance)
More torque is needed to move one step from standstill
than many steps on a running motor
There are maximum start and stop frequencies
Step motors have resonance frequency, where the
motor will loose its torque and might stall
You must know this resonance frequency and avoid it!
Google for more information, it is important to
acknowledge these hazards, thus, they are mentioned
on this course
http://www.sapiensman.com/step_motor/stepping%20motors.
htm
Copyright Tampere University of Technology Department of Computer Systems
#23/67
(”RC”) Servo motors (1)
are controlled with PWM, the length of the pulse
decides the position of the motor
NOTE: a DC –motor with a potentiometer is considered
as a servo: motor can be driven to a position by
measuring the resistance of the potentiometer. These
use some encoder/controller to drive the motor. Also,
these can be used to determine the speed of the DC
motor
Once again, calibrate starting position and then
relative position is known
Copyright Tampere University of Technology Department of Computer Systems
#24/67
(”RC”) Servo motors (2)
If the motor is not powerful enough for the load, MCU might
have to cheat to get precise position change of the servo on
short distances
1. Instruct motor to go beyond desired position
2. the controller might push more power to the servo, since the
distance to move is longer
3. Then, change the position to the desired before servo reaches it.
Controller will be able to stop it precisely where it should be
This is a hack and requires sometimes trial&error –method.. Not all
servos and applications require such actions and there can be
servos, which do not push more power for longer distance
Protip: by a stronger servo
Copyright Tampere University of Technology Department of Computer Systems
#25/67
#26/67
RC Servo motor
A RC servo motor does revolve freely but
between two extreme positions
Here they are marked as
CW - clock-wise
CCW -counter clk-wise mid
CW CCW
#27/67
clock-wise
counter-
clock-
wise
#28/67
Motors (4)
Typical AC/DC –motors
Run on variable speed to a direction
A speed controller is used with MCUs
Add potentiometer and you have a servo motor
Linear actuators
Construct of a motor and a screw (other methods exist
also)
The screw creates linear motion of the rotary motion of
the motor
Typically an extending/retracting shaft
Controlling is similar to servo motors
Copyright Tampere University of Technology Department of Computer Systems
#29/67
Relays, switches, pneumatics,
hydraulics..
skip
Copyright Tampere University of Technology Department of Computer Systems
#30/67
MCP41xxx digital potentiometer
Potentiometer provides variable resistance
Controlled via parallel or serial interface Analog potentiometer is wiped mechanically
Three terminals full resistance between PA0 and PB0
variable resistance from wiper, PW0-PA0 and PW0-PB0
PIC is the
master
#31/67
PID Controller
Proportional Integral Derivative Controller
Control loop feedback
Tries to minimize error between measured and ”asked” setpoint
value
Kx are tuning parameters, which are used to find best behavior for
the controller
Affect on rise time, overshoot, settling time, steady-state error and stability
Copyright Tampere University of Technology Department of Computer Systems
#32/67
DISPLAYS
Copyright Tampere University of Technology Department of Computer Systems
#33/67
LCD displays
2x16, 2x32, 2x64, 4x16, 4x32 etc. ASCII character matrixes Typically 4-8bit parallel bus, R/W, Cmd/DATA lines
Commands like clear screen, cursor position controlling (home, shift), program own characters..
”Real” LCD/OLED displays E.g. those in mobile phones
Controlled via serial bus, very similar to SPI or I2C, in addition of Cmd/DATA line
Use some standard graphic controllers such as PHILIPS PCF8833
Copyright Tampere University of Technology Department of Computer Systems
#34/67 Copyright Tampere University of Technology Department of Computer Systems
#35/67
Flash memories
Typically SPI or I2C interface SD memory card supports SPI directly (and one-bit
SD bus)
Typically^2 only transition from ’1’ -> ’0’ possible Memory block can be written once, then it must be
erased back to the ’1’s for another write You cannot write again before erasing
Typically^4 flash memories have page / block structure Random access may be possible, but not over page /
block border
Erasing can be done only per page / block (or whole memory) You cannot erase one single byte
Copyright Tampere University of Technology Department of Computer Systems
#36/67
COMMUNICATION MODULES
Copyright Tampere University of Technology Department of Computer Systems
#37/67
Machine-to-machine – M2M
Machines communicate with each other more
and more every day
M2M used to mean ”large” machines
communication over GSM/SMS/GPRS
Communication may take place over
Wired bus (e.g. CAN)
Wireless ”Personal” Area Network
802.14.5, RFID etc.
Over internet (ethernet, WLAN, 3G/GPRS..)
Copyright Tampere University of Technology Department of Computer Systems
#38/67
Radio: nRF24L01
Operating voltage: 1.9 – 3.6 V
Frequency: 2.400 – 2.4835GHz
Communication: SPI
Fully automated packet handling
Current consumption:
Power down 900 nA
Standby 22 uA or 320 uA (Two standby modes)
Transmission < 11.3 mA, Reception < 12.3 mA
Range about 15-30 meters indoors
Antenna dependable
Image: www.nordicsemi.com
Copyright Tampere University of Technology Department of Computer Systems
#39/67
Communications – RS-232 / 485 / 422
etc.
Maxim MAX220 – MAX249 drivers an example
With RS-232 pretty much works as voltage
converter
RS-485 for example requires differential
signaling, thus chips change serial data format to
the differential signal (longer wires possible)
Similar for CAN bus for example
Copyright Tampere University of Technology Department of Computer Systems
#40/67
Communications - USB
Small MCUs typically connect through USB-to-serial
adapter to a computer
These adapters appear as an RS-232 interface in
PC/Mac with standard drivers
SPI or UART used to connect adapter to the MCU
Some MCUs provide USB connectivity
The MCU can implement one of the standard USB
communication payloads, such as HID, audio device, etc.
Or the MCU can use proprietary USB communication
packet payload definition
Then, for sure, a driver is needed to the host device
Copyright Tampere University of Technology Department of Computer Systems
#41/67
Communications – Internet –
Ethernet/WLAN/3G/GPRS
There are UART or SPI connected modules for basic
internet communication
Ethernet, WLAN, 3G/GPRS
These are either totally autonomous (e.g. the user must
configure Internet connection parameters) or controlled from
the MCU
Typically AT command specification is used to set configuration
Some controllers have a built in Ethernet connectivity HW
Then, the TCP/UDP, IP and so on protocol stack must be
implemented on the MCU
Luckily there are plenty of either free or open source stacks
Google: uIP, IwIP, Microchip provides one for their own ethernet
capable MCUs
Copyright Tampere University of Technology Department of Computer Systems
#42/67
Ethernet and 3G examples
Ethernet: Lantronix XPORT Uart-to-ethernet ”bridge”
Up to 921kbps
AES-256 encryption
Configurable to establish TCP/IP connection with server
WLAN model exist also
Microchip ENC624J600 implement SPI to Ethernet
Microchip provides a TCP/IP stack for their Ethernet capable MCUs
With others you may use uIP
Copyright Tampere University of Technology Department of Computer Systems
3G
Either modules (SPI/UART) or RS-232-to-3G modems
May be programmable some how
E.g. Telit
#43/67
Communications - BT
Similar to Ethernet / WLAN / 3G adapters, SPI and
UART conneted BT modules exist
AT commands are used to establish connection
between BT module and BT devices
Must be configured from the MCU
Similar to USB-to-serial –modules, BT has the same
functionality, however, the configuration and
connection establisment must be made from the
MCU
External RS232-to-BT adapters do exist, which can be
configured from the adapter itself
Copyright Tampere University of Technology Department of Computer Systems
#44/67
BT example
http://www.sparkfun.co
m/categories/16
Serial over BT
Human Interface
Devices (BT dongle
provides interface to
directly mimic HID, e.g.
mouse/joystick/keyboa
rbd)
Copyright Tampere University of Technology Department of Computer Systems
#45/67
Communications – wireless - ZigBee /
Zwave
External modules, which form a ZigBee (or similar)
network and provide easy wireless communication
between devices
Typically connected through serial interface
(I2C/SPI)
May require some configuration from the MCU
The network is autonomously kept alive by the
modules
Applications: wireless remote controls, wireless
sensor networks
Copyright Tampere University of Technology Department of Computer Systems
#46/67
801.15.4 / ZigBee example
Implements 802.15.4
protocol stack
Add ZigBee routing etc.
and you have a ZigBee
Understanding stacks is
out of scope
Simple star and peer-to-
peer networks between
machines (MCUs, or
MCU <-> Computer etc.)
Copyright Tampere University of Technology Department of Computer Systems
#47/67
RFID
RFID uses active
reader device
and passive
RFID tag
The tag receives
power over
induction when
brought close
proximity
Applications in
logistics,
security, key
cards, time cards
Copyright Tampere University of Technology Department of Computer Systems
#48/67
More and conclusion
There is plenty of small cheap IC’s which can be
used with MCUs
Sensors, displays, communication units
Typically UART, SPI, I2C or parallel connection
Motors need some external circuitry since MCU do
not provide enough power
Different motors require different ICs
Explore more:
Google sensors, drivers, chips etc.
Exploring SparkFun gives a good idea what sort of things
you can do with ICs http://www.sparkfun.com/
Copyright Tampere University of Technology Department of Computer Systems