Introduction Why low power?

Slides:



Advertisements
Similar presentations
UBI >> Contents Chapter 7 Timers Laboratories MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar,
Advertisements

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
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
Instructor: Dr Aleksandar Milenkovic Lecture Notes
LAB 6: Serial Communication
Notes on the ez430-RF2500. Sources
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
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
3-1 System peripherals & Bus Structure Memory map of the LPC2300 device is one contiguous 32-bit address range. However, the device itself is made up of.
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.
Renesas Electronics Europe GmbH A © 2010 Renesas Electronics Corporation. All rights reserved. RL78 Clock Generator.
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.
Clock Options and Sleep Modes. Clock Sources Flash Fuse bits can be programmed to choose one of the following Clock sources: 1. External RC Osc. f = 1/(3RC).
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.
SIGMA-DELTA ADC SD16_A Sigma-Delta ADC Shruthi Sujendra.
Lecture 11: TI MSP430 Timers Compare Modes
LAB 8: Program Design Pattern and Software Architecture
Ultra-low Power Motion Detection using the MSP430F2013.
I NTRODUCTION TO PIC PROGRAMMING By : S HERIF H ARHASH.
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.
Lecture 4 General-Purpose Input/Output NCHUEE 720A Lab Prof. Jichiang Tsai.
CS4101 嵌入式系統概論 Interrupt 金仲達教授 國立清華大學資訊工程學系 ( Materials from MSP430 Microcontroller Basics, John H. Davies, Newnes, 2008 )
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.
Power Management. Outline Why manage power? Power management in CPU cores Power management system wide Ways for embedded programmers to be power conscious.
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
Introduction to MSP430G2553 and MPU6050
CS203 – Advanced Computer Architecture
Introduction Why low power?
CS4101 嵌入式系統概論 General Purpose IO
ECE 3430 – Intro to Microcomputer Systems
Lecture 8: TI MSP430 Interrupts, ISRs
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
Lesson Outline Interrupts Admin Assignment #9 due next lesson
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
Power Management and Sleep Modes
EMBEDDED SYSTEMS Unit 3.
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
Power Management and Sleep Modes
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
UNIT – Microcontroller.
Prof. Chung-Ta King Department of Computer Science
ECE 3430 – Intro to Microcomputer Systems
CS4101 嵌入式系統概論 General Purpose IO
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
Subject Name: Microcontroller Subject Code: 10ES42
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
I/O PORTS : MSP430x5xx devices have up to 12 digital I/O ports :
Processor Fundamentals
ECE 3430 – Intro to Microcomputer Systems
CPE 323 Introduction to Embedded Computer Systems: DMA Controller
Lecture 9: TI MSP430 Interrupts & Low Power Modes
MSP432™ MCUs Training Part 6: Analog Peripherals
8051 Micro Controller.
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
MSP430 Clock System and Timer
COMP3221: Microprocessors and Embedded Systems
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

CS4101 嵌入式系統概論 Low-Power Optimization Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan (Materials from MSP430 Microcontroller Basics, John H. Davies, Newnes, 2008)

Introduction Why low power? Portable and mobile devices are getting popular, but they have limited power sources, e.g., battery Energy conservation for our planet Power generates heat  low carbon Power optimization becomes a new dimension in system design, besides performance and cost MSP430 provides many features for low-power operations, which will be discussed later

Outline Introduction to low-power optimizations Low-power design in MSP430

Energy and Power Energy: ability to do work Most important in battery-powered systems Power: energy per unit time Important even in wall-plug systems---power becomes heat Power increases with… Vcc Clock speed Temperature

Efforts for Low Power Device/transistor level Circuit level Development of low power devices Reducing power supply voltage Reducing threshold voltage Circuit level Clock gating, frequency reduction, circuit turned off Asynchronous circuits System level Compiler optimization for energy OS-directed power management and resource scheduling Application level 4

Power Consumption: Transistor Level Switching consumes power  dynamic power Switching slower, consume less power Smaller sizes reduce power to operate Leakage  static power

Power Consumption: Circuit Level Power consumption of CMOS circuits (ignoring leakage): Delay for CMOS circuits: Decreasing Vdd reduces P quadratically, while the execution time of circuits is only linearly increased 6

Power Consumption: Circuit Level Clock gating for synchronous sequential logic: Disable the clock so that flip-flops will hold their states forever and the whole circuit will not switch  no dynamic power consumed Still need static power to hold the states clock

System Level: Compiler Energy-aware code scheduling Energy-aware instruction selection Operator strength reduction: e.g. replace * by + and << Standard optimizations with energy as a cost function R2 = a[0]; for (i = 1; i < 10; i++) { R1 = a[i]; C = 2 * R1 + R2; R2 = R1; } e.g.: register pipelining: for (i = 1; i < 10; i++) C = 2 * a[i] + a[i-1]; 8

System Level: Compiler First-order optimization: high performance = low energy (some exceptions) Eliminate pipeline stalls (e.g., software pipeline) Use registers efficiently Identify and eliminate cache conflicts Optimize memory access patterns Moderate loop unrolling eliminates some loop overhead instructions Inlining procedures may help: reduces linkage, but may increase cache thrashing

System Level: OS Idle base Power-aware memory management After idle for a period, switch system to sleep mode Power-aware memory management e.g. OS can determine points during execution of an application where memory banks would remain idle, so they can be transitioned to low power modes Power-aware buffer cache Collect disk operations in a cache until the hard drive is running or has enough data

System Level: Cooperative I/O Time Idle Standby Time Standby Idle Reduces power consumption by batching requests

Outline Introduction to low-power optimizations Low-power design in MSP430

General Strategies Put the system in low-power modes and/or use low- power modules as much as possible How? Provide clocks of different frequencies  frequency scaling Turn off clocks when no work to do  clock gating Use interrupts to wake up the CPU, return to sleep when done (another reason to use interrupts) Switch on peripherals only when needed Use low-power integrated peripheral modules in place of software, e.g., move data between modules

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

MSP430 Low Power Modes Active mode: LPM0: MSP430 starts up in this mode, which must be used when the CPU is required, i.e., to run code An interrupt automatically switches MSP430 to active Current can be reduced by running at the lowest supply voltage consistent with the frequency of MCLK, e.g. VCC to 1.8V for fDCO = 1MHz LPM0: CPU and MCLK are disabled Used when CPU is not required but some modules require a fast clock from SMCLK and DCO Low-power mode 2 or 3 is selected if bits CPUOff and SCG1 in the status register are set. Immediately after the bits are set, CPU, MCLK, and SMCLK operations halt and all internal bus activities stop until an interrupt request or reset occurs. Peripherals that operate with the MCLK or SMCLK signal are inactive because the clock signals are inactive. Peripherals that operate with the ACLK signal are active or inactive according with the individual control registers and the module enable bits in the SFRs. All I/O port pins and the RAM/registers are unchanged. Wake up is possible byenabled interrupts coming from active peripherals or RST/NMI.

MSP430 Low Power Modes LPM3: LPM4: Only ACLK remains active Standard low-power mode when MSP430 must wake itself at regular intervals and needs a (slow) clock Also required if MSP430 must maintain a real-time clock LPM4: CPU and all clocks are disabled MSP430 can be wakened only by an external signal, e.g., RST/NMI, also called RAM retention mode

Power Saving in MSP430 The most important factor for reducing power consumption is using the MSP430 clock system to maximize the time in LPM3 “Instant on” clock

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

Entering/Exiting Low-Power Modes Interrupt wakes MSP430 from low-power modes: Enter ISR: PC and SR are stored on the stack CPUOFF, SCG1, OSCOFF bits are automatically reset  entering active mode MCLK must be started so CPU can handle interrupt Options for returning from ISR: Original SR is popped from the stack, restoring the previous operating mode SR bits stored on stack can be modified within ISR to return to a different mode when RETI is executed

Sample Code 1 for Low Power void main(void) { //Toggle P1.0 every 50000 cycles WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR |= 0x01; // P1.0 output TA0CCTL0 = CCIE; // CCR0 interrupt enabled TA0CCR0 = 50000-1; TA0CTL = TASSEL_2 + MC_1; // SMCLK, up mode _BIS_SR(LPM0_bits + GIE); // LPM0 w/ interrupt } #pragma vector=TIMERA0_VECTOR __interrupt void Timer0_A (void) { P1OUT ^= 0x01; // Toggle P1.0 Use _BIC_SR_IRQ(LPM0_bits) to exit LPM0

Sample Code 2 for Low Power Repetitive single conversion: Repetitively perform single samples on A1 (pin P1.1) with reference to Vcc If A1 > 0.5*Vcc, P1.0 set, else reset. Set ADC10SC to start sample and conversion But ADC10SC is automatically cleared at end of conversion CPU goes to sleep while waiting for the ADC10 conversion and is waken up when ADC10 conversion is done. Use ADC10 internal oscillator to time the sample and conversion

Sample Code 2 for Low Power #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 } Why not read ADC10MEM right after setting ADC10CTL0? While wait for interrupt? Any one of the pins of Port 1 can be set to be an analog input. Thus up to 8 channels are available for separate ADC inputs. Analog Enable control register ADC10AE0 will be use for enabling the corresponding input channels. The settling time for the internal reference is < 30µs. A value of 5 cycles would be 40µs. We should allow thirteen ADC10CLK cycles before we read the conversion result. Thirteen cycles of the 5MHz ADC10CLK is 2.6µs. Even a single cycle of the DCO/8 would be longer than that. We will leave the LED on and use the same delay so that we can see it with our eyes. When the conversion is complete, the encoder and reference need to be turned off. 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. 23 23

Sample Code 2 for Low Power // 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) } 24 24

Sample Code 3 for Low Power Continuous sampling driven by Timer0_A3 A1 is sampled 16/second with reference to 1.5V, where ACLK runs at 32 KHz driven by an external crystal (2048 ACLK cycles give 1/16 second (ACLK/2048)) If A1 > 0.5Vcc, P1.0 is set, else reset. Timer0_A3 is run in up mode with CCR0 defining the sampling period (2048 cycles) Use CCR1 to automatically trigger ADC10 conversion

Sample Code 3 for Low Power #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. 26 26

Sample Code 3 for Low Power 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 and is reset when the timer counts to the TACCR0 value. 27 27

Sample Code 3 for Low Power // 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 28 28

Summary Power and energy Efforts for low power operations Low-power modes of MSP430 Active, LPM0, LPM3 Controlling low power modes Which saves more energy? Use a higher frequency to run a program faster so as to sleep longer Use a lower frequency to run a program to save power, but system may be active longer