220 likes | 363 Views
ELE271 Mon. April 7, 2014 Review LPM Morse Code Lab .ref and . def Multiplication, shift. Low Power Modes. Principles of Low-Power Apps. Maximize the time in low-power modes. Sleep as long as possible and use interrupts to wakeup.
E N D
ELE271 • Mon. April 7, 2014 • Review LPM • Morse Code Lab • .ref and .def • Multiplication, shift
Low Power Modes 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_Aand 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.
How are these concepts applied to microcontroller programming? • Low Power design isn’t just for low power applications. • Low Power/Interrupt-driven design helps with modular design. • The following techniques are applied to low power Design: • Use of Interrupts. • Controlling the clock.
Low Power Modes MSP430 Clock Modes Average • 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.
Processor Clocks 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
Low Power Modes MSP430 Clock Settings (r2) SMCLK and ACLK Active Only ACLK Active No Clocks! Sleep Modes ; enable interrupts / enter low-power mode 0 bis.w#LPM0|GIE,SR ; LPM0 w/interrupts Can be combined
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)?
How to come out of LPM in active mode. A mildly tricky line of assembly language is required to clear the bits set for the low power mode PORT1_ISR bic.w #LPM4,0(SP) reti See Jimenez Ex. 7.4
Morse Code Lab Objective: to program the device using assembly code to toggle the LED to send a Morse Code message “SOS” each time S1 is pressed. This lab will illustrate the following concepts: • 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).
Assume one word. Assume only letters.
Morse code has a variable-length code for each character. Question: how to represent this in memory. Solution: use pointers or “relocatable expressions” in assembly: ; letters--->A_ptr---->DOT,DASH,END ; A ; B_ptr---->DASH,DOT,DOT,DOT,END ; B ,etc…
Morse Code Data Structure DOT .equ1 DASH .equ 3 letters: .word A_ptr .word B_ptr ,etc… dot dash end A_ptr: .byte DOT,DASH,END ; A B_ptr: .byte DASH,DOT,DOT,DOT,END ; B , etc… ; letters--->A_ptr---->DOT,DASH,END ; A ; B_ptr---->DASH,DOT,DOT,DOT,END ; B
Morse Code Algorithm Sleep; Get address of .cstring message. Get first character. Whilecharacter!= 0, do normalize ASCII to 41h (ie, so “A”=1) Get address of letters Get first code ; code = dot or dash Whilecode!= 0, do Turn LED on Sleep(1|3) ; 1unit=dot,3 units=dash Turn LED off Sleep(1) ; 1 unit Get next code EndWhile Sleep(3) Read next character. Endwhile
RTN to Assembly: The While Statement Part 2 Usually a “while” statement implies a “cmp” “while” loops cause jmp backwards while ( n > 0 ) { s1… } Loop: cmp #0,r6 dec r6 jz End s1… jmp Loop End: Until condiion is met, then Jmp forward.
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
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.