CMP502 - Embedded Systems CMP502 – Embedded Systems Models of Computation.
55:036 Embedded Systems and Systems...
Transcript of 55:036 Embedded Systems and Systems...
Hardware Considerations Slide 1 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Embedded Systems and Software
Lecture 12 Some Hardware Considerations
Hardware Considerations Slide 2 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Logic States
Digital signals may be in one of three states
State 1: High, or “1”. Using positive logic polarity, this corresponds to a voltage level closer to the power supply than to ground.
In negative logic polarity, voltages levels closes to the supply than to ground are “0”, and voltage levels closer to ground than to the power supply are “1”. This is used in some serial communication protocols.
Example. For an ATmega88PA and Vcc = 5 V, the data sheet indicates that an input voltage larger than 0.6×Vcc = 3 V is considered high, or logic “1”.
Example. For an ATmega88PA and Vcc = 5 V, the data sheet indicates that an input less than 0.3×Vcc = 1.5 V is treated as a logic low or “0”
State 2: Low, or “0”. Using positive logic polarity, this corresponds to a voltage level closer to ground than to the power supply. For example, for an ATmega88PA and Vcc = 5 V, the data sheet indicates that an input voltage larger than 0.6 Vcc = 3 V is considered logic high, or “1”.
State 3: Tristate or high-Z, or simply Z. In this case the digital line is in a high-impedance state or “floating” . External components, often a pull-up resistor can pull the bus high or low.
Hardware Considerations Slide 3 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Driving an LED
Vcc = 5 V AV
R PB2
𝑅𝑅𝑙𝑙𝑙𝑙𝑙𝑙𝑙𝑙𝑙𝑙
Use the LED’s V-I characteristics from its datasheet to determine the forward voltage for a given current. Then apply Ohm’s Law to determine 𝑅𝑅𝑙𝑙𝑙𝑙𝑙𝑙𝑙𝑙𝑙𝑙
Hardware Considerations Slide 4 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Driving a High Power Load
Solid State Relay (SSR)
Cost ~ $14
• SIP SSR • Ratings of 5A @ 660 VAC • SCR output for heavy industrial loads • AC or DC control • Zero-crossing (resistive loads) or random-fire (inductive loads) output
Control
Load
Hardware Considerations Slide 5 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Driving a High-Power External Load
Vcc = 5 V AV
R
PB2
SSR Control 5-14 V
@ 15 mA
Opt
o-is
olat
ed
Solid
Sta
te R
elay
220 V, 5 A Load
300 Ω
Rlimit
Depending on the SSR, one may need an external resistor here to limit current out of microcontroller port
Hardware Considerations Slide 6 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Driving a High-Power External Load
Vcc = 5 V AV
R
PB2
Opt
o-is
olat
ed
Solid
Sta
te R
elay
220 V, 5 A Load
V on =
1.2
V @
10
mA Rlimit
Example: The absolute max rating for I/O current is 40 mA, and the SSR has Von = 1.2 V @ 10 mA. Determine Rlimit
Hardware Considerations Slide 7 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Well-defined Reset Pin
It is important that the RESET pin has a well-defined voltage in normal operation, otherwise it may randomly reset. Also, if a mechnical switch is used for reset, consider contact bounce
As a minimum, pull the line high and add a capacitor to filter out any glitches that may get to the RESET line
Hardware Considerations Slide 8 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Well-defined Reset Pin
This supervisor chip makes sure the MCUs RESET line is well-behaved when the RST button is pushed and released
Reset circuitry for 28-pin development board
Hardware Considerations Slide 9 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
Bridge Rectifier
Voltage Regulator
Hardware Considerations Slide 10 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
Power supply section from 28-pin development board
Bridge rectifier converts ac to dc. Also allows us to use dc.
Hardware Considerations Slide 11 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
Power supply section from 28-pin development board
Smoothing Capacitor
Hardware Considerations Slide 12 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
Power supply section from 28-pin development board
Three Terminal Regulator
Hardware Considerations Slide 13 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
Power supply section from 28-pin development board
Sets Output Voltage
Hardware Considerations Slide 14 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
Power supply section from 28-pin development board
Jump for 3.3V
Hardware Considerations Slide 15 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
Power supply section from 28-pin development board
Needed for Stability
Hardware Considerations Slide 16 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
Reverse-Polarity Protection
Diodes should be Schottky rather than regular Si diodes. Why?
Bridge provides reverse-polarity protection
What voltage is supplied to embedded system if the input voltage is 5 V? Assume Si diodes.
Hardware Considerations Slide 17 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
Linear Three-Terminal Regulator
Constant voltage: 3 V, 5 V, etc.
Varying input voltage, say 7-14 V. Must be larger than output voltage + some headroom, typically 1-2 V
Note that linear regulators cannot step up a voltage, but regulate down.
Hardware Considerations Slide 18 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
Linear Three-Terminal Regulator
LM78XX Three-terminal regulator pinout in TO220 package
Heat sink to cool down regulator
Hardware Considerations Slide 19 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
Linear Three-Terminal Regulator
These capacitors are easily-overlooked but a crucial for proper operation
Hardware Considerations Slide 20 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
Linear Three-Terminal Regulator
Quiescent current for LM78xx regulators are large, and can waste lots of energy not suitable for battery-operated equipment.
Hardware Considerations Slide 21 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
MAX604 Linear Regulator
Quiescent current for MAX604 a few micro-amps, thus much more suitable for battery-operated equipment.
Hardware Considerations Slide 22 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supplies
MAX724 DC/DC switching Regulator
Very wide input range, efficient conversion to output voltage
Note that switching regulator can step up voltages
Hardware Considerations Slide 23 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Decoupling Capacitors Consider a microntroller that runs on a 10 MHz clock. This means the clock period is 100 ns. The rise and fall time of the clock is thus on the order of 10 ns or shorter.
The microcontroller’s internal electronics (logic gates) create significant switching noise that appears on the power supply lines.
The current is drawn in very short spikes on the clock edges, and if I/O lines are switching, the spikes will be even higher.
This kind of current spike cannot be delivered over long power supply lines; the main source is (or should be) the decoupling capacitor.
Decoupling capacitor ~ 0.1 μF
The decoupling capacitor’s (local) energy provides local storage to supply to switching circuits.
Used properly, a decoupling capacitor can greatly reduces switching noise.
Sometimes called a bypass capacitor
Hardware Considerations Slide 24 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supply Decoupling
Wrong way to decouple power supply
Decoupling capacitor is ~ 0.1 μF
Note: high loop current flows through the ground and can contaminate other circuits
Hardware Considerations Slide 25 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Power Supply Decoupling
Better way to decouple power supply
Decoupling capacitor is very close to the controller, across its GND and Vcc pins. Large current spikes never flow through the circuit ground.
Inductor blocks residual current spikes from entering power supply. Typical value is 47 nH.
Hardware Considerations Slide 26 Embedded Systems and Software, 55:036. The University of Iowa, 2013
External Clock Sources
For crystals with frequencies larger than 400 kHz
For crystals with frequencies less than 400 kHz, typically 32.768kHz watch crystal. Not supported on all AVRs
Hardware Considerations Slide 27 Embedded Systems and Software, 55:036. The University of Iowa, 2013
External Clock Sources
For simplicity, the oscillator capacitors are not always indicated, but they are crucial for proper operation, and in most cases the oscillator will not oscillate without these capacitors
Capacitor values are ~ 20 pF, which are small.
Crystals
Hardware Considerations Slide 28 Embedded Systems and Software, 55:036. The University of Iowa, 2013
External Clock Sources
10 MHz ceramic resonator. Cost ~ $0.25
Ceramic Resonators
Lower Q than crystals. This means less stable, but also faster start-up time
Are available with built-in capacitors
Equivalent circuit
Connect to uController
Hardware Considerations Slide 29 Embedded Systems and Software, 55:036. The University of Iowa, 2013
External Clock Sources
Cost ~ $0.25 Cost ~ $0.75
Question: What does “ppm” mean?
Answer: Parts per million
To convert from ppm to %, divide the number by 10,000.
To convert from % to ppm, multiply by 10,000
Hardware Considerations Slide 30 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Board Layout
Hardware Considerations Slide 31 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Question: what type of diodes should D1, D2, be, and why?
Answer: Schottky diodes, because they have lower turn-on voltages than Si diodes. Thus, these diodes dissipate less power.
In normal operation, the 5 V linear regulator provides clean 5 V. D1 drops VD(on) . This is greater than (3 V + VD(on) ), so D2 is reverse-biased and open. Without main power, D2 is forward biased turn on, and powers the controller.
Hardware Considerations Slide 32 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Recall Earlier Slide
sbi DDRB,1 ; PB1 is now output sbi DDRB,2 ; PB2 is now output
Example. Turning LEDs on and off
Connecting LEDs
sbi PORTB,1 ; LED at PB1 off
Configuring port pins for output
Turn LED at PB1 OFF
Turn LED at PB1 ON cbi PORTB,2 ; LED at PB2 on
Note LEDs will light up when ports pins
are pulled LOW
Data Direction Register
Hardware Considerations Slide 33 Embedded Systems and Software, 55:036. The University of Iowa, 2013
DDRB, PORTB, PINB,…
Simplified I/O equivalent schematic
I/O ports on ATmege88P: PORTB, PORTC, and PORTD
Individual pins of the ports are PB1, PD4, etc.
Complex circuitry sits behind each port pin.
Pins can be digital input, digital output, and analog Input
Three registers located in I/O space
DDRB – Data Direction Register for PORTB
PORTB– Digital Output Register for PORTB
PINB– Input Register for PORTB
Hardware Considerations Slide 34 Embedded Systems and Software, 55:036. The University of Iowa, 2013
DDRB, PORTB, PINB,…
Protection Diodes
All I/O pins have protection diodes to both VCC and Ground
All AVR ports have true Read-Modify-Write functionality when used as general digital I/O ports. This means that the direction of one port pin can be changed without unintentionally changing the direction of any other pin with the SBI and CBI instructions.
The same applies when changing drive value (if configured as output) or enabling/disabling of pull-up resistors (if configured as input). Each output buffer has symmetrical drive characteristics with both high sink and source capability.
The pin driver is strong enough to drive LED displays directly. All port pins have individually selectable pull-up resistors with a supply-voltage invariant resistance.
Pull-up resistor ensures that is at expected logic levels if external devices are disconnected. The idea is that is that it weakly "pulls" the pin to Vcc. The resistor is high-resistance enough that, if something else strongly pulls the wire toward 0V, the pin will go to 0V.
Hardware Considerations Slide 35 Embedded Systems and Software, 55:036. The University of Iowa, 2013
DDRB, PORTB, PINB,…
Configuring a PIN
DDRB – Data Direction Register for PORTB
PORTB– Digital Output Register for PORTB
PINB– Input Register for PORTB
Hardware Considerations Slide 36 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Unconnected Pins
The simplest method to ensure a defined level of an unused pin, is to enable the internal pull-up.
If some pins are unused, it is recommended to ensure that these pins have a defined level. Even though most of the digital inputs are disabled in the deep sleep modes as described above, floating inputs should be avoided to reduce current consumption in all other modes where the digital inputs are enabled (Reset, Active mode and Idle mode).
In this case, the pull-up will be disabled during reset. If low power consumption during reset is important, it is recommended to use an external pull-up or pull-down
Connecting unused pins directly to VCC or GND is not recommended, since this may cause excessive currents if the pin is accidentally configured as an output.
Hardware Considerations Slide 37 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Example. Consider the table below, extracted from the “DC Characteristics” section of the ATtiny45/V microcontroller. Assume the power supply voltage is 2 V, and that PB0 is configured as digital input. Determine the threshold voltages for logic 1 and 0 on input.
Solution. PB0 is not XTAL or RESET, so VIL and VIH apply.
VI0 = 0.2Vcc = 0.2×2 = 0.4 V, and VI1 = 0.7Vcc = 0.7×2 = 1.4 V
Hardware Considerations Slide 38 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Pull-Ups Revisited
The Pull-up Disable – PUD bit in MCUCR disables the pull-up function for all pins in all ports when set.
If PORTxn is written logic one when the pin is configured as an input pin, the pull-up resistor is activated.
To switch the pull-up resistor off, PORTxn has to be written logic zero or the pin has to be configured as an output pin.
Self-Study
Give a code snippet to configure PB1 on the ATmega88PA as an input with the internal pull-up resistor activated. Comment your code.
Hardware Considerations Slide 39 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Pull-Ups Revisited
Pull-up resistors can have a significant spread between parts, and even individual pins on a port, so beware…
Hardware Considerations Slide 40 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Microcontroller Fuses
• Except for GND and VCC all other pins can perform at least 4 functions • PB5 can be hardware RESET or an ADC input • PB3 & PB4 can be ADC inputs or where crystal for external oscillator
goes • How does one configure controller for the external environment?
AVR ATtiny45 ® 8-Pin Microcontroller
Hardware Considerations Slide 41 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Electrical Connections
Pullup resistors
Low-pass filter Low-pass filter
Test circuit, from the data sheet
Remember contact bounce?
Hardware Considerations Slide 42 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Switch Bounce and Debouncing
Bounce
Hardware Considerations Slide 43 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Switch Bounce and Debouncing
t
Volta
ge Question: what is the fall time?
Make sure you can calculate this.
When the switch closes, the capacitor discharger through Rb
Hardware Considerations Slide 44 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Wired-Or Application: Bus
Bus is normally high
Any microcontroller can pull the bus low
Internal Pull-up Resistor OFF
Internal Pull-up Resistor OFF
Hardware Considerations Slide 45 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Reading a Simple (3×4) Keypad
Note the weak pull-ups on PDB-PD7. These must be enabled in software
Hardware Considerations Slide 46 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Reading a Simple (3×4) Keypad
Step 1: Detecting a key press a) Drive PC4, PC5, PC6 low. b) READ Port D and look for zero on any of PD4-PD7 c) If so, a key has been pressed 0
0
0
Hardware Considerations Slide 47 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Reading a Simple (3×4) Keypad
Step 2: Debounce. Wait an appropriate period for the key switch to stabilize (10 ms is probably a good waiting time)
Hardware Considerations Slide 48 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Reading a Simple (3×4) Keypad
0
1
1
Step 3: Search for the pressed key a) Drive PC4 Low, PC5,PC6 High b) Read Port D PD4 = 0 “1” pressed PD5 = 0 “4” pressed PD6 = 0 “7” pressed PD7 = 0 “*” pressed c) If pressed key is not found in column 1, repeat the process as necessary for the other two columns
Hardware Considerations Slide 49 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Reading a Simple (3×4) Keypad
1
0
1
Step 4: Search for the pressed key a) Drive PC5 Low, PC4,PC6 High b) Read Port D PD4 = 0 “2” pressed PD5 = 0 “5” pressed PD6 = 0 “8” pressed PD7 = 0 “0” pressed c) If pressed key is not found in column 2, repeat the process as necessary for the other two columns
Hardware Considerations Slide 50 Embedded Systems and Software, 55:036. The University of Iowa, 2013
Reading a Simple (3×4) Keypad
1
1
0
Step 5: Search for the pressed key a) Drive PC6 Low, PC4,PC5 High b) Read Port D PD4 = 0 “3” pressed PD5 = 0 “6” pressed PD6 = 0 “9” pressed PD7 = 0 “#” pressed
Hardware Considerations Slide 51 Embedded Systems and Software, 55:036. The University of Iowa, 2013