搜索
bottom↓
回复: 7

C8051F921为什么休眠电流那么大!求大侠解救!

[复制链接]

出0入0汤圆

发表于 2013-9-27 20:47:29 | 显示全部楼层 |阅读模式
一开始用自己的程序发现休眠时,正常工作时电流有40mA,休眠后居然32mA也有这么大,后来用下面这个例程,也是一样的效果。
哪位大侠救救我啊!我是新手,不明白这是怎么回事!应该怎么办!

//-----------------------------------------------------------------------------
// F93x_SleepMode_PortMatchWake.c
//-----------------------------------------------------------------------------
// Copyright (C) 2007 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This program flashes the red LED on the C8051F930 target board using the
// interrupt handler for Timer2 when the MCU is awake.
//
// Pressing the switch on P0.3 will place the device in a low power mode.
// Pressing the switch on P0.2 will wake up the device using Port Match.
//
// How To Test:
//
// 1) Download code to the 'F93x target board
// 2) Ensure that pins 1-2, 3-4, 5-6, 7-8 are shorted together on the
//    J8 header
// 3) Run the program. Press P0.3 to place the device in sleep mode.
//    Press P0.2 to wake it back up. The Red LED will blink when
//    the device is awake.
//
//
// Target:         C8051F93x-C8051F92x
// Tool chain:     Generic
// Command Line:   None
//
// Release 1.0
//    -Initial Revision (FB)
//    -8 OCT 2007
//

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <compiler_defs.h>             // compiler declarations
#include <C8051F930_defs.h>            // SFR declarations

//-----------------------------------------------------------------------------
// Pin Declarations
//-----------------------------------------------------------------------------

SBIT (RED_LED,    SFR_P1, 5);          // '0' means ON, '1' means OFF
SBIT (YELLOW_LED, SFR_P1, 6);          // '0' means ON, '1' means OFF
SBIT (SW2,        SFR_P0, 2);          // SW2 == 0 means switch pressed
SBIT (SW3,        SFR_P0, 3);          // SW3 == 0 means switch pressed

//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------

#define SYSCLK          20000000       // SYSCLK frequency in Hz


#define LED_ON           0
#define LED_OFF          1

#define SUSPEND          0x40          // Value to write to PMU0CF to place
                                       // the device in Suspend mode

#define SLEEP            0x80          // Value to write to PMU0CF to place
                                       // the device in Sleep Mode

#define POWER_MODE      SLEEP          // Select between Suspend and Sleep
                                       // mode. When debugging, if the
                                       // MCU is stopped/halted while
                                       // in Sleep Mode, the connection
                                       // to the IDE will be lost. The
                                       // IDE connection will not be lost
                                       // if the MCU is stopped/halted
                                       // while in suspend mode.
//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------
void OSCILLATOR_Init (void);
void PORT_Init (void);
void Timer2_Init (int counts);

//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
void main (void)
{
   U8 wakeup_event_pending;
   U8 wakeup_source;
   
   PCA0MD &= ~0x40;                    // WDTE = 0 (clear watchdog timer
                                       // enable)

   PORT_Init ();                       // Initialize Port I/O
   OSCILLATOR_Init ();                 // Initialize Oscillator
   
   Timer2_Init (SYSCLK / 12 / 32);     // Init Timer2 to generate interrupts
                                       // at a 32 Hz rate.

   // Setup the Port Match Wake-up Source to wake up on the falling
   // edge of P0.2 (when the switch is pressed)
   P0MASK = 0x04;                      // Mask out all pins except for P0.2
   P0MAT = 0x04;                       // P0.2 should be HIGH while the device
                                       // is in the low power mode

   EA = 1;                             // Enable global interrupts
   
   //----------------------------------
   // Main Application Loop
   //----------------------------------
   while (1)
   {
      if(!SW3)                         // If the P0.3 switch is pressed
      {
         

         // Configure the Port I/O for Low Power Mode
         RED_LED = LED_OFF;            // Turn off the LED or other
                                       // high-current devices         
                  
         // Place the device in the Low Power Mode
         PMU0CF = 0x20;                // Clear all wake-up flags
         wakeup_event_pending = 0;     // Clear software event pending flag         

         if(!SW2)                      // Check each wake-up event to ensure
         {                             // it has not occured while the
            wakeup_event_pending = 1;  // wake-up flags were being cleared
         }                             // In this example, we are only using
                                       // a single wake-up source
         
         if(!wakeup_event_pending)
         {
            YELLOW_LED = LED_ON;       // Turn on Yellow LED to indicate that
                                       // the device is entering the low power
                                       // state
            
            // Enable Port Match wake-up source and place the device in
            // the low power state
            PMU0CF = (POWER_MODE | 0x02);
         }

         //--------------------------------------------------------------------
         // Device Sleeping until P0.2 is pressed
         //--------------------------------------------------------------------
         
         // Turn off the Yellow LED to indicate that we are in the
         // high power mode
         YELLOW_LED = LED_OFF;         

         RED_LED = LED_ON;            // Turn on the LED or other
                                       // high-current devices   
         // Read the wake-up source flags
         wakeup_source = PMU0CF & 0x1F;

         // Clear the wake-up source flags
         PMU0CF = 0x20;            
         
         // Decode the wakeup source
         if(wakeup_source & 0x10)
         {
            // We have been awaken by the reset pin (most likely C2 traffic)
            EA = 0;
            YELLOW_LED = LED_ON;
            RED_LED = LED_ON;  
            while(1);
         
         }         

         if(wakeup_source & 0x02)
         {
            // We have been awaken by a port match
         }
                     

      }
   }                        
}

//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// OSCILLATOR_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function initializes the system clock to use the internal low power
// oscillator.
//
//-----------------------------------------------------------------------------
void OSCILLATOR_Init (void)
{
   
   
         
   RSTSRC = 0x06;                      // Enable missing clock detector and
                                       // leave VDD Monitor enabled.

   CLKSEL = 0x04;                      // Select low power internal osc.
                                       // divided by 1 as the system clock
  
}

//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function configures the crossbar and ports pins.
//
// P0.2   digital   open-drain    Switch 2
// P0.3   digital   open-drain    Switch 3
// P1.5   digital   push-pull     Red LED
// P1.6   digital   push-pull     Yellow LED
//-----------------------------------------------------------------------------
void PORT_Init (void)
{
   P0MDIN |= 0x0C;                     // P0.2, P0.3 are digital
   P1MDIN |= 0x60;                     // P1.5, P1.6 are digital

   P0MDOUT &= ~0x0C;                   // P0.2, P0.3 are open-drain
   P1MDOUT |= 0x60;                    // P1.5, P1.6 are push-pull

   P0     |= 0x0C;                     // Set P0.2, P0.3 latches to '1'

   XBR2    = 0x40;                     // Enable crossbar and enable
                                       // weak pull-ups
}

//-----------------------------------------------------------------------------
// Timer2_Init
//-----------------------------------------------------------------------------
//
// Configure Timer2 to 16-bit auto-reload and generate an interrupt at
// interval specified by <counts> using SYSCLK/48 as its time base.
//
void Timer2_Init (int counts)
{
   TMR2CN  = 0x00;                        // Stop Timer2; Clear TF2;
                                          // use SYSCLK/12 as timebase
   CKCON  &= ~0x60;                       // Timer2 clocked based on T2XCLK;

   TMR2RL  = -counts;                     // Init reload values
   TMR2    = TMR2RL;                      // initalize timer to reload value
   ET2     = 1;                           // enable Timer2 interrupts
   TR2     = 1;                           // start Timer2
}

//-----------------------------------------------------------------------------
// Interrupt Service Routines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Timer2_ISR
//-----------------------------------------------------------------------------
// This routine changes the state of the LED whenever Timer2 overflows.
//
INTERRUPT(Timer2_ISR, INTERRUPT_TIMER2)
{
   TF2H = 0;                              // clear Timer2 interrupt flag
   RED_LED = !RED_LED;                    // change state of LED

}

//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入0汤圆

发表于 2013-9-28 01:13:41 | 显示全部楼层
上到mA以上,证明你休眠没成功。
检查一下晶振有没有在振,输出口有没有输出电流。

出0入42汤圆

发表于 2013-9-28 01:24:27 | 显示全部楼层
这个电流全部是MCU的?外围电路还有工作的吗?有没有从IO口供出的电流或吸入的电流。
另外,单片机的输入端是在VDD或GND电平下很重要。

出0入0汤圆

 楼主| 发表于 2013-9-28 09:14:34 | 显示全部楼层
cocom 发表于 2013-9-28 01:24
这个电流全部是MCU的?外围电路还有工作的吗?有没有从IO口供出的电流或吸入的电流。
另外,单片机的输入 ...

谢谢大侠!32mA的休眠电流确实包括了外围,其实我也考虑到了!把外围的串口,指示灯,传感器都去掉了!但是电路里还有复位电路,和稳压芯片,后来单独测试了MCU的休眠电流确实很小!我用的是AMS1117-3.3的稳压芯片!这个这么耗电嘛!由于是新手,原先没有考虑过功耗问题!求大侠指教!我是不是应该选一个低功耗的稳压芯片!

出70入145汤圆

发表于 2013-9-28 09:33:59 | 显示全部楼层
AMS1117-3.3的稳压芯片这种芯片是耗电大户,静态电流5mA。你使用HT7533好了,静态电流小于1uA(实测值)。外围电路要是不需要在休眠时一直工作的你就使用PMOS把对这些电路的电源关掉。

出0入8汤圆

发表于 2013-9-28 09:45:19 | 显示全部楼层
低功耗  还用AMS1117   本身这个LDO的功耗就有几个mA 看数据手册。  还有休眠是的IO口状态也很重要。 不用的IO口要设置成固定电平。

出0入0汤圆

发表于 2013-9-28 09:47:19 | 显示全部楼层
1117相比780x没有好到哪里去
如果外围没有射频等对电压相当敏感的东西就改被动元件降压
要是外围有多0.1v少0.1v都不行对电压相当敏感的东西就别用1117这种廉价LDO了

出0入0汤圆

发表于 2014-1-4 09:57:16 | 显示全部楼层
mark一下  学习学习
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-26 09:19

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表