1 / 22

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

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.

ramla
Download Presentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

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

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

  6. MSP430 5xx Power Modes

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

  8. 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)?

  9. Review of stack interaction with interrupts.

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

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

  12. Assume one word. Assume only letters.

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

  14. Relocatable expressions

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

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

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

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

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

More Related