1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.
-
Upload
darby-muddiman -
Category
Documents
-
view
217 -
download
1
Transcript of 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.
![Page 1: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/1.jpg)
1
ELE271
Mon. April 7, 2014- Review LPM
- Morse Code Lab
- .ref and .def
- Multiplication, shift
![Page 2: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/2.jpg)
2
Principles of Low-Power Apps• Maximize the time in low-power modes.• Sleep as long as possible and use interrupts to wakeup.• Use the slowest clock while still meeting processing needs.• Switch on peripherals only when needed (ie, switch off
peripherals when not needed).• Use low-power integrated computer peripherals.
– Timers: Timer_A and Timer_B for PWM– A/D convertors, flash, LCD’s
• Use faster software algorithms / programming techniques– Calculated branches instead of flag polling.– Fast table look-ups instead of iterative calculations.– Use in-line code instead of frequent subroutine / function calls.– More single-cycle CPU register usage.
Low Power Modes
![Page 3: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/3.jpg)
3
How are these concepts applied to
microcontroller programming?
The following techniques are applied to low power Design:
- Use of Interrupts.
- Controlling the clock.
- Low Power design isn’t just for low power applications.
- Low Power/Interrupt-driven design helps with modular design.
![Page 4: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/4.jpg)
4
A method to reduce power consumption is to turn off some (or all) of the system clocks (and turning off the power to some circuits).
A device is said to be sleeping when in low-power mode; waking refers to returning to active mode.
MSP430 Clock ModesLow Power Modes
Average
![Page 5: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/5.jpg)
5
Processor Clock Speeds• Often, the most important factor for reducing power
consumption is slowing the clock down.– Faster clock = Higher performance, more power required– Slower clock = Lower performance, less power required
Processor Clocks
0.25 0.18 0.13 0.09 0.0650
50
100
150
200
250
300
Active Power
Leakage
Clock Speeds ()P
ow
er
(Wa
tts
)
Power Consumption
![Page 6: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/6.jpg)
6
![Page 7: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/7.jpg)
7
MSP430 5xx Power Modes
![Page 8: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/8.jpg)
8
Reserved V SCG1 SCG0OSCOFF
CPUOFF GIE N Z C
Active Mode
LPM0
LPM3
LPM4
0
0
1
1
0
0
1
1
0
0
0
1
0
1
1
1
~ 250 µA
~ 35 µA
~ 0.8 µA
~ 0.1 µA
; enable interrupts / enter low-power mode 0 bis.w #LPM0|GIE,SR ; LPM0 w/interrupts
MSP430 Clock Settings (r2)Low Power Modes
SMCLK and ACLK Active
Sleep ModesOnly ACLK
Active No Clocks!
Can be combined
![Page 9: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/9.jpg)
9
Two problems with this:
- What if you want to stay in active mode after ISR?
- What if you want to keep ISR small (so you don’t turn off other interrupts)?
![Page 10: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/10.jpg)
10
Review of stack interaction with interrupts.
![Page 11: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/11.jpg)
11
PORT1_ISR
bic.w #LPM4,0(SP)
reti
A mildly tricky line of assembly language is required to clear the bits set for the low power mode
See Jimenez Ex. 7.4
How to come out of LPM in active mode.
![Page 12: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/12.jpg)
12
![Page 13: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/13.jpg)
13
Morse Code Lab
- Interrupt-driven programming.
- Multiple source files (.ref,.def directives)
- Subroutines
- Timers
- Low Power Modes
- Advanced data structures (pointers)
- Exit an ISR in Active Mode (AM).
This lab will illustrate the following concepts:
Objective:
to program the device using assembly code to toggle the LED to send a Morse Code message “SOS” each time S1 is pressed.
![Page 14: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/14.jpg)
14
Assume one word.
Assume only letters.
![Page 15: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/15.jpg)
15
Morse code has a variable-length code for each character.
; letters--->A_ptr---->DOT,DASH,END ; A
; B_ptr---->DASH,DOT,DOT,DOT,END ; B
,etc…
Question: how to represent this in memory.
Solution: use pointers or “relocatable expressions” in assembly:
![Page 16: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/16.jpg)
16
![Page 17: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/17.jpg)
17
Relocatable expressions
![Page 18: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/18.jpg)
18
DOT .equ 1
DASH .equ 3
letters:
.word A_ptr
.word B_ptr
,etc…
A_ptr: .byte DOT,DASH,END ; A
B_ptr: .byte DASH,DOT,DOT,DOT,END ; B
, etc…
A_ptr
0x5c00 0x5c10
0x5c10 01h
03h
00h
0x5c13 03h
01h
01h
01h
00h
dot
dash
end
Morse Code Data Structure
; letters--->A_ptr---->DOT,DASH,END ; A
; B_ptr---->DASH,DOT,DOT,DOT,END ; B
![Page 19: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/19.jpg)
19
Sleep;
Get address of .cstring message.
Get first character.
While character != 0 , do
normalize ASCII to 41h (ie, so “A”=1)
Get address of letters
Get first code ; code = dot or dash
While code != 0, do
Turn LED on
Sleep(1|3) ; 1unit=dot,3 units=dash
Turn LED off
Sleep(1) ; 1 unit
Get next code
End While
Sleep(3)
Read next character.
End while
Morse Code Algorithm
![Page 20: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/20.jpg)
while ( n > 0 ) {
s1…
}
Loop:
cmp #0,r6
dec r6
jz End
s1…
jmp Loop
End:
Usually a “while” statement implies a “cmp”RTN to Assembly: The While Statement Part 2
“while” loops
cause jmp
backwards
Until condiion is met, then
Jmp forward.
![Page 21: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/21.jpg)
21
sleep
If(pushbutton) do
R4<-#message ; get address of message
R5<-(r4) ; get character pointed to by #message
while (r5 != 0), do ; keep getting another char unless zero
r5<-r5-41h ; normalize ASCII character to 40h (ie, A=0)
r5<-r5*2 ; multiply by 2 for word boundary
r7<-letters(r5) ; get first code for letter (dot or dash)
while(r7 != 0), do ; get next code unless end (0)
beep(r7) ; beep amount of code (1 or 2)
short_delay ; short delay between beeps
r5<-r5+1 ; increment address
r7<-letters(r5) ; get next code
endwhile
r4<-r4+2 ; increment character address
long_delay ; long delay between characters
Endwhile
End if
![Page 22: 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.](https://reader034.fdocuments.in/reader034/viewer/2022052701/56649c785503460f9492d1ce/html5/thumbnails/22.jpg)
22
Write an interrupt-driven program to toggle the LED based on the Morse Code.
• Learn how to use multiple source files with the .ref and .def directives.
• Learn how to use subroutines.
• Learn how use Timers.
• Learn how use Low Power Modes.
• Learn how use pointer data types.
• Learn how to come out of an ISR in active mode.