Microchip PIC16F1829深度休眠

时间:2014-06-17 08:22:57

标签: c embedded microcontroller pic microchip

我很难让PIC16F1829进入睡眠模式。该单元消耗大约18​​mA,而数据表在深度睡眠模式下引用20nA。有人可以帮忙吗?

根据数据表,我必须做以下事项" WDT,BOR,FVR和T1OSC 禁用,所有外围设备不活动"我想如下所示?

    #include <pic16Lf1829.h>
    #include <plib/adc.h>
    #include <plib/pconfig.h>
    #include <plib/usart.h>


    // Use project enums instead of #define for ON and OFF.

    // CONFIG1
    #pragma config FOSC = ECL    // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
    #pragma config WDTE = OFF       // Watchdog Timer Enable (WDT disabled)
    #pragma config PWRTE = OFF      // Power-up Timer Enable (PWRT disabled)
    #pragma config MCLRE = ON       // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
    #pragma config CP = OFF         // Flash Program Memory Code Protection (Program memory code protection is disabled)
    #pragma config CPD = OFF        // Data Memory Code Protection (Data memory code protection is disabled)
    #pragma config BOREN = OFF      // Brown-out Reset Enable (Brown-out Reset disabled)
    #pragma config CLKOUTEN = OFF   // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
    #pragma config IESO = ON        // Internal/External Switchover (Internal/External Switchover mode is enabled)
    #pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)

    // CONFIG2
    #pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)
    #pragma config PLLEN = OFF      // PLL Enable (4x PLL disabled)
    #pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
    #pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
    #pragma config LVP = ON         // Low-Voltage Programming Enable (Low-voltage programming enabled)


int main(int argc, char** argv) {
/*******************OSCILATOR CONFIGURATION*************/
    OSCCON = 0b01101000; // OSCILATOR CONTROL REGISTER 1MHz
    BORCON = 0x00;
    WDTCON    = 0x00; // Enable watchdog timer
/*******************************************************************************/


/**********************PORT A,B,C SETUP*************************************/

    ANSELB  =   0b00000000; /* Enable Digital input = 0 or Analogue = 1*/
    WPUB     =  0b00000000; /* Enable PULL UP 1 = yes 0 - NO*/
    TRISB   =   0b00000000; /* Tri-state PIN*/
    PORTB   =   0b00000000; /* Set PORTB Logic */

    WPUC =      0b00000000;
    ANSELC  =   0b00000000; /* Enable Digital input = 0 or Analogue = 1*/
    TRISC   =   0b00000000; /* Tri-state PIN*/
    PORTC =     0b00000000; /* Set PORTB Logic */

    WPUA =      0b00000000;
    ANSELA  =   0b00000000; /* Enable Digital input = 0 or Analogue = 1*/
    TRISA   =   0b00000000; /* Tri-state PIN*/
    PORTA   =   0b00000000; /* Set PORTB Logic */


    IOCBP   = 0b00100000;  /* INTERRUPT-ON-CHANGE PORTB POSITIVE EDGE REGISTER*/
    IOCBN   = 0b00000000;  /* INTERRUPT-ON-CHANGE PORTB NEGATIVE EDGE REGISTER*/
    INTCON  = 0b01011000;  /* Enable int on PIN Change*/
 /*******************************************************************************/

    bit_set(INTCON,7); /*ENABLE GLOBAL INTERUPTS*/

    ADCON0 = 0x00;
    ADCON1 = 0x00;

    T1CON  = 0x00;
    T2CON  = 0x00;
    FVRCON = 0x00; //FIXED VOLTAGE REFERENCE CONTROL REGISTER
    CM1CON0 = 0x00;
    CM1CON1 = 0x00;
    CM2CON1 = 0x00;
    CM2CON0 = 0x00;
    PWM1CON = 0x00;
    PWM2CON = 0x00;
    DACCON0 = 0X00;
    DACCON1 = 0X00;
    T1CON =   0X00;


    /********** MAIN LOOP START*******************/
        for(;;) {

    SLEEP();


           }

2 个答案:

答案 0 :(得分:1)

这可能是缺乏异常处理的结果。您启用了中断但没有捕获它们的功能。如果出于任何原因,将设置中断标志,则无需清除它,并且由于GIE已设置(即使处于休眠状态),因此pic将分支到中断向量。由于您尚未指定中断功能,您可能(取决于您的编译器)最终进入未编程的存储区域,以全速执行任意指令。

尝试使用相同的代码:

---  INTCON  = 0b01011000;  /* Enable int on PIN Change*/
+++  INTCON  = 0b00000000;  /* Disable all int */

答案 1 :(得分:0)

根据数据表,18mA对于这个mcu来说太高了(~5mA @ 32Mhz)。

  • 确认mcu引脚没有短路。
  • 验证输出电压是否已配置当前(例如,i2c引脚应为&#34;输出高电平&#34;等等&#39;)
  • 确认您的VCC没有为其他模块供电。