CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization

Slides:



Advertisements
Similar presentations
Why Keliang’s code maybe did (or maybe didn’t) work … or High (impedance) Anxiety.
Advertisements

UBI >> Contents Chapter 7 Timers Laboratories MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar,
1 ELE271 Mon. April 7, Review LPM -Morse Code Lab -.ref and.def -Multiplication, shift.
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
2008EECS Dealing with Analog Signals A Microcontroller View Jonathan Hui University of California, Berkeley.
Confidentiality/date line: 13pt Arial Regular, white Maximum length: 1 line Information separated by vertical strokes, with two spaces on either side Disclaimer.
LAB 6: Serial Communication
Notes on the ez430-RF2500. Sources
CS4101 嵌入式系統概論 Timers and Clocks 金仲達教授 國立清華大學資訊工程學系 Materials from MSP430 Microcontroller Basics, John H. Davies, Newnes, 2008.
CS4101 嵌入式系統概論 Software UART Revisited Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan ( Materials from MSP430.
Chung-Ta King National Tsing Hua University
LAB 7: WDT+ and Low-Power Optimization
T IMERS - 2. O UTPUT U NIT Each capture/compare block contains an output unit. The output unit is used to generate output signals such as PWM signals.
Lecture 18: ADC Implementation Lecturers: Professor John Devlin.
MSP430 Mixed Signal Microcontroller – Parte 2 Afonso Ferreira Miguel Source: slau056d – Texas instruments.
CPE 323 Introduction to Embedded Computer Systems: Watchdog Timer, Timer A Instructor: Dr Aleksandar Milenkovic Lecture Notes.
Lab 5 System Design Thomas Watteyne EE290Q – Spring 2010
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
CS4101 嵌入式系統概論 Analog-to-Digital Converter 金仲達教授 國立清華大學資訊工程學系 ( Materials from MSP430 Microcontroller Basics, John H. Davies, Newnes, 2008 )
CPE 323 Introduction to Embedded Computer Systems: ADC12 and DAC12 Instructor: Dr Aleksandar Milenkovic Lecture Notes.
Lecture 11: TI MSP430 Timers Compare Modes
LAB 8: Program Design Pattern and Software Architecture
Ultra-low Power Motion Detection using the MSP430F2013.
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Week 7 Low-Power Modes MSP430 Teaching Materials Hacettepe University Copyright 2009 Texas Instruments All Rights Reserved.
Lab 3: ADC.
UNIT 2. CPUXV2 20-bit addressing User-definable Boot Strap Loader RAM starts at 0x1C00 Beginning of MAIN flash moves according to RAM Vector table starts.
ECE 382 Lesson 32 Lesson Outline Lab 6 Introduction Pulse Width Modulation Capture / Compare Example Lab 6 Tips Admin Lab#6 “prelab” due BOC lesson 33.
Recall the Container Thermometer
Recall the Container Thermometer
Introduction to MSP430G2553 and MPU6050
Introduction Why low power?
Introduction Why low power?
CS4101 嵌入式系統概論 General Purpose IO
ECE 3430 – Intro to Microcomputer Systems
Lecture 8: TI MSP430 Interrupts, ISRs
CS4101 Introduction to Embedded Systems Lab 10: Tasks and Scheduling
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
Lesson Outline Interrupts Admin Assignment #9 due next lesson
PWM and DC Motor Control
EMBEDDED SYSTEMS Unit 3.
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
Prof. Chung-Ta King Department of Computer Science
ECE 3430 – Intro to Microcomputer Systems
CS4101 嵌入式系統概論 General Purpose IO
Instructor: Dr Aleksandar Milenkovic Lecture Notes
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 2: Timer and Clock Prof. Chung-Ta King Department of Computer Science National.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 3: Interrupt Prof. Chung-Ta King Department of Computer Science National Tsing.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 6: Serial Communication Prof. Chung-Ta King Department of Computer Science National.
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
CS4101 Introduction to Embedded Systems Lab 7: Serial Communication
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
I/O PORTS : MSP430x5xx devices have up to 12 digital I/O ports :
ECE 3430 – Intro to Microcomputer Systems
CS4101 Introduction to Embedded Systems Lab 7: Serial Communication
Lecture 9: TI MSP430 Interrupts & Low Power Modes
Microcontroller Labs Lab 1 – The LED Test Mode Dr. Gregg Chapman
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
MSP430 Clock System and Timer
ECE 3567 Microcontroller Lab
ECE 3567 Microcontrollers Lab
ECE 3567 Microcontroller Lab
Presentation transcript:

CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan

Introduction In this lab, we will learn power optimization of MSP430 LanuchPad Configuring the low-power modes of MSP430

MSP430 Low-Power Modes Mode CPU and Clocks Active CPU active; all enabled clocks active LPM0 CPU, MCLK disabled; SMCLK, ACLK active LPM1 CPU, MCLK disabled; DCO disabled if not for SMCLK; ACLK active LPM2 CPU, MCLK, SMCLK, DCO disabled; ACLK active LPM3 LPM4 CPU and all clocks disabled

Controlling Low Power Modes Through four bits in Status Register (SR) in CPU SCG0 (System clock generator 0): when set, turns off DCO, if DCOCLK is not used for MCLK or SMCLK SCG1 (System clock generator 1): when set, turns off the SMCLK OSCOFF (Oscillator off): when set, turns off LFXT1 crystal oscillator, when LFXT1CLK is not use for MCLK or SMCLK CPUOFF (CPU off): when set, turns off the CPU All are clear in active mode

Controlling Low Power Modes Status bits and low-power modes

Sample Code 1 for ADC10 Repetitive single conversion: A single sample is made on A1 with reference to Vcc If A1 > 0.5*Vcc, P1.0 set, else reset. Software sets ADC10SC to start sample and conversion. ADC10SC automatically cleared at end of conversion. Use ADC10 internal oscillator to time the sample and conversion.

Sample Code 1 for ADC10 #include "msp430.h" void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT // H&S time 16x, interrupt enabled ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; ADC10CTL1 = INCH_1; // Input A1 ADC10AE0 |= 0x02; // Enable pin A1 for analog in P1DIR |= 0x01; // Set P1.0 to output for (;;) { ADC10CTL0 |= ENC + ADC10SC; // Start sampling __bis_SR_register(CPUOFF + GIE); // Sleep if (ADC10MEM < 0x1FF) // 0x1FF = 511 P1OUT &= ~0x01; // Clear P1.0 LED off else P1OUT |= 0x01; // Set P1.0 LED on } Pulse-width modulation (PWM): The load is switched on and off periodically so that the average voltage has the desired value. The fraction of the time while the load is active is called the duty cycle D. 6 6

Sample Code 1 for ADC10 // ADC10 interrupt service routine #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR) } 7 7

Sample Code 2 for ADC10 Continuous sampling driven by Timer0_A A1 is sampled 16/second (ACLK/2048) with reference to 1.5V, where ACLK runs at 32 KHz driven by an external crystal. If A1 > 0.5Vcc, P1.0 is set, else reset. Timer0_A is run in up mode and its CCR1 is used to automatically trigger ADC10 conversion, while CCR0 defines the sampling period. Use internal oscillator times sample (16x) and conversion (13x).

Sample Code 2 for ADC10 #include "msp430.h" void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT // TA1 trigger sample start ADC10CTL1 = SHS_1 + CONSEQ_2 + INCH_1; ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE; __enable_interrupt(); // Enable interrupts. TA0CCR0 = 30; // Delay for Volt Ref to settle TA0CCTL0 |= CCIE; // Compare-mode interrupt. TA0CTL = TASSEL_2 + MC_1; // SMCLK, Up mode. LPM0; // Wait for settle. TA0CCTL0 &= ~CCIE; // Disable timer Interrupt __disable_interrupt(); Pulse-width modulation (PWM): The load is switched on and off periodically so that the average voltage has the desired value. The fraction of the time while the load is active is called the duty cycle D. 9 9

Sample Code 2 for ADC10 ADC10CTL0 |= ENC; // ADC10 Enable ADC10AE0 |= 0x02; // P1.1 ADC10 option select P1DIR |= 0x01; // Set P1.0 output TA0CCR0 = 2048-1; // Sampling period TA0CCTL1 = OUTMOD_3; // TACCR1 set/reset TA0CCR1 = 2046; // TACCR1 OUT1 on time TA0CTL = TASSEL_1 + MC_1; // ACLK, up mode // Enter LPM3 w/ interrupts __bis_SR_register(LPM3_bits + GIE); } Timer_A CCR1 out mode 3: The output (OUT1) is set when the timer counts to the TACCR1 value. It is reset when the timer counts to the TACCR0 value. 10 10

Sample Code 2 for ADC10 // ADC10 interrupt service routine #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void){ if (ADC10MEM < 0x1FF) // ADC10MEM = A1 > 0.5V? P1OUT &= ~0x01; // Clear P1.0 LED off else P1OUT |= 0x01; // Set P1.0 LED on } #pragma vector=TIMERA0_VECTOR __interrupt void ta0_isr(void){ TA0CTL = 0; LPM0_EXIT; // Exit LPM0 on return 11 11

Lab 6 Basic 1: Flash the green LED at 1 Hz in LPM3 using Timer0_A and measure the temperature using ADC10 at 1 Hz driven by Timer0_A. Calculate the average temperature of last 2 sec. If the average temperature is higher than 30oC, enter LPM0, measure temperature and flash the red LED at 2 Hz, and calculate the average temperature of the past 2 sec. If the average temperature is higher than 35oC, enter active mode, measure temperature and flash both LEDs at 5 Hz, and calculate the average temperature of last 2 sec.

Lab 6 Basic 1: (cont’d) Go back to the initial state when the average temperature drops below 30oC. Draw a finite-state machine to show the logic of your code. Try to minimize the time spent in the ISR.

Lab 6 Bonus: (Game of Memory) Put LaunchPad to LPM4 and wait for button input to start the game. Once the button is pressed, enter LPM0 and turn on the red LED for a random period. After the red LED is turned off, immediately press the button for the duration that the red LED is on. Calculate the difference between the on-time of the red LED and the button. If the difference is larger than 0.5 second, then you lose. Flash the green LED at 2 Hz for 3 seconds and return to the waiting state.

Lab 6 Bonus: (cont’d) At the nth round, turn on the red LED for a random period for n times, with a random interval between two on-time. Ignore button activities during this period of time. After the nth on-time, immediately press the button for the duration of the sum of the n on-time. Calculate the difference between the on-time of the red LED and the button. If the difference is larger than 0.5 second, then you lose. Flash the green LED at 2 Hz for 3 seconds and return to the waiting state. Otherwise, you can enter the next round.