Upload
joao-moreira
View
108
Download
4
Tags:
Embed Size (px)
Citation preview
RMR©2012
Maths is not everything
Embedded Systems4 - Hardware Architecture
CPUInput/Output mechanisms
Memory Buses and Aux I/O
Input/Output interfacesPower Management
RMR©2012
Maths is not everything
CPU Buses
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
CPU bus
Connects CPU to:memory;
devices.
Protocol controls communication between entities.
3
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Bus protocol
Determines who gets to use the bus at any particular time.Governs length, style of communication.
4
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Four-cycle handshake
Basis of many bus protocols.Uses two wires:
enq (enquiry);
ack (acknowledgment).
dev1 dev2
enq
ack
data
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Four-cycle example
time
enq
ack
data
1
2
3
4
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Typical bus signals
Clock.R/W’: true when bus is reading.Address: a-bit bundle.Data: n-bit bundle.Data ready’.
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Timing diagrams
time
A
B
C
zero
one
rising falling
stable
changing
10 ns
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Typical bus timing for read
CPU:set R/W’=1;
asserts address, address enable.
Memory:asserts data;
asserts data ready’.
CPU:deasserts address, address enable.
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Bus read state diagram
Getdata Done
Adrs
Wait
See ack
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Transaction types
Wait state:state in a bus transaction to wait for acknowledgment.
Disconnected transfer:bus is freed during wait state.
Burst:multiple transfers.
RMR©2012
Maths is not everything
Auxiliary MechanismsTimers
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Timers and counters
Very similar:a timer is incremented by a periodic signal;
a counter is incremented by an asynchronous, occasional signal.
Rollover causes interrupt.
RMR©2012
Maths is not everything
Timers
The main applications of timers are to:generate events of fixed time-period
allow periodic wakeup from sleep of the device
count transitional signal edges
replace delay loops allowing the CPU to sleep between operations, consuming less power
maintain synchronization clocks
14
RMR©2012
Maths is not everything
Timers (MSP430)
System timing is fundamental for real-time applicationsThe MSP430F2274 has 2 timers, namely Timer_A and Timer_BThe timers may be triggered by internal or external clocksTimer_A and Timer_B also include multiple independent capture/compare blocks that are used for applications such as timed events and Pulse Width Modulation (PWM)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
(Used by Timer_B) TxSSELx IDx MCx - TxCLR TxIE TxIFG
Bit Description 9-8 TxSSELx Timer_x clock source: 0 0 ⇒ TxCLK
0 1 ⇒ ACLK 1 0 ⇒ SMCLK 1 1 ⇒ INCLK
7-6 IDx Clock signal divider: 0 0 ⇒ / 1 0 1 ⇒ / 2 1 0 ⇒ / 4 1 1 ⇒ / 8
5-4 MCx Clock timer operating mode: 0 0 ⇒ Stop mode 0 1 ⇒ Up mode 1 0 ⇒ Continuous mode 1 1 ⇒ Up/down mode
2 TxCLR Timer_x clear when TxCLR = 1
1 TxIE Timer_x interrupt enable when TxIE = 1
0 TxIFG Timer_x interrupt pending when TxIFG = 1
RMR©2012
Maths is not everything
Timers (MSP430) - TxCTL Control Register
MCx Mode Description 0 0 Stop The timer is halted. 0 1 Up The timer repeatedly counts from 0x0000 to
the value in the TxCCR0 register. 1 0 Continuous The timer repeatedly counts from 0x0000 to
0xFFFF. 1 1 Up/down The timer repeatedly counts from 0x0000 to
the value in the TxCCR0 register and back down to zero.
RMR©2012
Maths is not everything
Timers (MSP430) - 4 Modes of Operation
Timer reset by writing a 0 to TxRClock timer operating modes:
RMR©2012
Maths is not everything
Timers (MSP430) - Timer Modes
Up Mode
C o n t i n u o u s Mode
Up/Down Mode
RMR©2012
Maths is not everything
Timers (MSP430): Timer_A Example
Use Timer A to interrupt every 1 msSMCLK .set 1200000 ; 1200000 clocks / secondTIME_1MS .set 1000 ; 1 ms = 1/1000 s
TA_CTL .set TASSEL_2+ID_0+MC_1+TAIE ; SMCLK, /1, UP, IETA_FREQ .set SMCLK/TIME_1MS ; clocks / 1 ms
clr.w &TAR ; reset timerA mov.w #TA_CTL,&TACTL ; set timerA control reg mov.w #TA_FREQ,&TACCR0 ; set interval (frequency) bis.w #LPM0+GIE,SR ; enter LPM0 w/interrupts jmp $ ; will never get here!
TA_isr: ; timer A ISR bic.w #TAIFG,&TACTL ; acknowledge interrupt; <<add interrupt code here>> reti
.sect ".int08" ; timer A section .word TA_isr ; timer A isr
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Watchdog timer
Watchdog timer is periodically reset by system timer.If watchdog is not reset, it generates an interrupt to reset the host.
host CPU watchdogtimer
interrupt
reset
RMR©2012
Maths is not everything
Watchdog Timer (MSP430)
The primary function of the watchdog timer+ (WDT+) module is to perform a controlled system restart after a software problem occurs.
If the selected time interval expires, a system reset is generated.
If the watchdog function is not needed in an application, the module can be configured as an interval timer and can generate interrupts at selected time intervals.
RMR©2012
Maths is not everything
Watchdog Timer (MSP430)
Features of the watchdog timer+ module include:
Four software-selectable time intervals
Watchdog mode
Interval mode
Access to WDT+ control register is password protected
Control of RST/NMI pin function
Selectable clock source
Can be stopped to conserve power
Clock fail-safe feature
RMR©2012
Maths is not everything
Watchdog Timer (MSP430) - Watchdog Power-up
After a power-up clear (PUC), the WDT+ module is automatically configured in the watchdog mode with an initial 32768 clock cycle reset interval using the DCOCLK.
The user must setup or halt the WDT+ prior to the expiration of the initial reset interval.
RMR©2012
Maths is not everything
RESET: ! mov.w #0x0300,SP ; Initialize stack pointer ! mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT ! bis.b #0x0f,&P1DIR ; Set P1.0-3 output ! mov.w #0,r14
...
Watchdog (MSP430) example: stoping it
In Assembly
In C
passwd = 0x5A
RMR©2012
Maths is not everything
Auxiliary I/OButtons & Displays
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Switch debouncing
A switch must be debounced to multiple contacts caused by eliminate mechanical bouncing:
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Encoded keyboard
An array of switches is read by an encoder.N-key rollover remembers multiple key depressions.
row
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
LED
Must use resistor to limit current:
RMR©2012
Maths is not everything
Auxiliary I/ODAC & ADC
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Digital-to-analog conversion
Use resistor tree:R
2R
4R
8R
bn
bn-1bn-2bn-3
Vout
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Flash A/D conversion
N-bit result requires 2n comparators:
encoder
Vin
...
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Dual-slope conversion
Use counter to time required to charge/discharge capacitor.Charging, then discharging eliminates non-linearities.
Vin timer
RMR©2012
Maths is not everything
© 2
008
Way
ne W
olf
Sample-and-hold
Required in any A/D:
converterVin