Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.

Similar presentations

Presentation on theme: "1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift."— Presentation transcript:

1 1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift

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. 2 Low Power Modes

3 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.

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 Modes 4 Low Power Modes Average

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 5 Processor Clocks

6 6

7 7 MSP430 5xx Power Modes

8 8 ReservedV SCG1SCG0 OSC OFF CPU OFF GIENZC Active Mode LPM0 LPM3 LPM4 00110011 00110011 00010001 01110111 ~ 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 Modes Only ACLK Active No Clocks! Can be combined

9 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)?

10 10 Review of stack interaction with interrupts.

11 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.

12 12

13 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.

14 14 Assume one word. Assume only letters.

15 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:

16 16

17 17 Relocatable expressions

18 18 DOT.equ1 DASH.equ3 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 0x5c000x5c10 01h 03h 00h 0x5c1303h 01h 00h dot dash end Morse Code Data Structure ; letters--->A_ptr---->DOT,DASH,END ; A ; B_ptr---->DASH,DOT,DOT,DOT,END ; B

19 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

20 while ( n > 0 ) { s1… } Loop: cmp #0,r6 dec r6 jzEnd 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.

21 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

22 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.

Download ppt "1 ELE271 Mon. April 7, 2014 -Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift."

Similar presentations

Ads by Google