stm8s---Power consumption management shutdown mode (halt) implementation

Source: Internet
Author: User

Official information

?? You can go to the Internet to search the Chinese version, or to the official website to download the English version.
?? English:

?? President

Main Content Introduction
    • Key factors that affect power consumption
    • Power system
    • Clock management
    • Operating mode and low power mode
      • Operating mode
      • Wait mode
      • Active shutdown mode
      • Shutdown mode
    • Measurement and results of power consumption and wake-up events
    • Power Management Essentials
Essentials Summary

?? Shutdown mode (Halt): This mode is the lowest power consumption of the microcontroller, the oscillator, CPU and peripheral clocks are turned off, the main voltage regulator power down. The available reset or external interrupt wakes up, and the register data that was run before wake-up is maintained, and the program continues to execute from halt.

停机模式下的功耗测量结果(MVR关LPVR开):

运行模式下的功耗测量结果(从RAM运行,不是从Flash开始):

停机模式下的唤醒时间测量结果:

Test program
main.c
/*function: Power Management: Shutdown (Halt) mode test, before entering the shutdown mode, four LEDs are lit every 1 seconds, more than 10 seconds later, automatically into the shutdown mode, The outage can then be woken up by an external interrupt, where the program continues down from the stop location. date:2015 July 21 NOTE:STVD + cosmicauthor:yicmversion:0.0.9*/#include <stm8s003f3p.h>/*output pin*/_boolPA3 @PA_ODR:3;_boolPC4 @PC_ODR:4;_boolPC5 @PC_ODR:5;_boolPC6 @PC_ODR:6;_boolPC7 @PC_ODR:7;/*input pin*/_boolPC3 @PC_IDR:3;/ * Battery indicator * /#define LED1 PA3#define LED2 PC5#define LED3 PC6#define LED4 PC7/ * Key indicator * /#define LED5 PC4#define KEY PC3/ * Main clock frequency is 8mhz*/voidINIT_CLK (void) {Clk_ickr |=0x01; CLK_CKDIVR =0x08; while(! (clk_ickr&0x02)); Clk_swr=0xe1;}voidInit_gpio (void){/*led configured for push-pull output * /Pa_ddr |=0X08;//PA3PA_CR1 |=0X08; Pa_cr2 &=0xf7;/*pc4-key led*/Pc_ddr |=0X10; PC_CR1 |=0X10; Pc_cr2 &=0XEF; Pc_ddr |=0XE0;//PC5/6/7PC_CR1 |=0XE0; Pc_cr2 &=0X1F; LED1 =1; LED2 =1; LED3 =1; LED4 =1; LED5 =1;}voidINIT_TIM1 (void) {Tim1_ier =0x00; TIM1_CR1 =0x00; Tim1_egr |=0x01; TIM1_PSCRH =199/ the;//8M system clock f=fck/(pscr+1) TIM1 16-bit dividerTIM1_PSCRL =199% the;//pscr=0x1f3f,f=8m/(0x1f3f+1) =1000hz, each count cycle 1msTIM1_CNTRH =0x00; Tim1_cntrl =0x00; Tim1_arrh = -/ the;//Auto Reload Register arr=0x01f4=500TIM1_ARRL = -% the;//500 times per number of interrupts, i.e. 500msTIM1_CR1 |=0x81; Tim1_ier |=0x01;}/*PC3 set to pull-up input * /voidInit_exti2_gpio (void) {pc_ddr &=0xf7; PC_CR1 &=0xf7; Pc_cr2 |=0X08;}/* rising edge and falling edge hair */voidInit_exti2 (void) {EXTI_CR1 |=0x30;} Main () {_asm ("Sim");    INIT_CLK ();    Init_gpio ();    Init_exti2_gpio ();    Init_exti2 ();    INIT_TIM1 (); _asm ("Rim"); while(1);}/ * External Interrupt wakeup * /@far @interruptvoidExti2_hand_fun (void){}/ * Timer Interrupt function * /@far @interruptvoidTim1_upd_ovf_trg_brk_irqhandler (void){Static unsigned inti =0; TIM1_SR1 &=~ (0x01); ++i;if(0= = (i% -) {LED1 = ~led1;        LED2 = ~led2;        LED3 = ~led3;    LED4 = ~led4; }if(I > +) {_asm ("Halt"); i =0;    LED5 = ~led5; }}
stm8_interrupt_vector.c
/* BASIC INTERRUPT VECTOR TABLE for STM8 devices * Copyright (c) STMicroelectronics */typedef void @far(*interrupt_handler_t) (void);structinterrupt_vector {unsignedCharInterrupt_instruction; interrupt_handler_t Interrupt_handler;};@far @interrupt voidNonhandledinterrupt (void){/ * In order to detect unexpected events during development, it's recommended to set a breakpoint on the follow ing instruction * *    return;}extern void_stext ();/ * Startup routine * /extern @far @interrupt voidExti2_hand_fun (void);extern @far @interrupt voidTim1_upd_ovf_trg_brk_irqhandler (void);structInterrupt_vectorConst_vectab[] = {{0x82, (interrupt_handler_t) _stext},/ * Reset * /{0x82, Nonhandledinterrupt},/ * Trap * /{0x82, Nonhandledinterrupt},/ * Irq0 * /{0x82, Nonhandledinterrupt},/ * IRQ1 * /{0x82, Nonhandledinterrupt},/ * IRQ2 * /{0x82, Nonhandledinterrupt},/ * IRQ3 * /{0x82, Nonhandledinterrupt},/ * Irq4 * /{0x82, Exti2_hand_fun},/ * IRQ5 * /{0x82, Nonhandledinterrupt},/ * IRQ6 * /{0x82, Nonhandledinterrupt},/ * IRQ7 * /{0x82, Nonhandledinterrupt},/ * Irq8 * /{0x82, Nonhandledinterrupt},/ * IRQ9 * /{0x82, Nonhandledinterrupt},/ * Irq10 * /{0x82, Tim1_upd_ovf_trg_brk_irqhandler},/ * Irq11 * /{0x82, Nonhandledinterrupt},/ * IRQ12 * /{0x82, Nonhandledinterrupt},/ * irq13 * /{0x82, Nonhandledinterrupt},/ * irq14 * /{0x82, Nonhandledinterrupt},/ * irq15 * /{0x82, Nonhandledinterrupt},/ * irq16 * /{0x82, Nonhandledinterrupt},/ * IRQ17 * /{0x82, Nonhandledinterrupt},/ * irq18 * /{0x82, Nonhandledinterrupt},/ * IRQ19 * /{0x82, Nonhandledinterrupt},/ * IRQ20 * /{0x82, Nonhandledinterrupt},/ * irq21 * /{0x82, Nonhandledinterrupt},/ * irq22 * /{0x82, Nonhandledinterrupt},/ * irq23 * /{0x82, Nonhandledinterrupt},/ * irq24 * /{0x82, Nonhandledinterrupt},/ * irq25 * /{0x82, Nonhandledinterrupt},/ * irq26 * /{0x82, Nonhandledinterrupt},/ * irq27 * /{0x82, Nonhandledinterrupt},/ * irq28 * /{0x82, Nonhandledinterrupt},/ * irq29 * /};

Copyright NOTICE: This article for Bo Master [original] article, without BO Master permission can be reproduced, annotated blog Source: [Http://blog.csdn.net/FreeApe]

stm8s---Power consumption management shutdown mode (halt) implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.