【发布时间】:2014-08-07 04:21:02
【问题描述】:
我正在努力让 PIC16F1829 进入睡眠模式。该单元消耗大约 18mA 电流,而数据表中的深度睡眠模式为 20nA。有人可以帮忙吗?
根据数据表,我必须执行以下“WDT、BOR、FVR 和 T1OSC disabled, all Peripherals Inactive" 我认为如下所示?
#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();
}
【问题讨论】:
-
你确定 18mA 是由芯片消耗的,而不仅仅是电路的其他部分吗?
-
是的,我确定它不是外部电路,我有与 PIC16F1509 相同的电路。这在深度睡眠中消耗了 20nA。我只是简单地切换了芯片。
-
@Clifford 是的 - 我遇到了这个问题,经过半小时的挠头后,我意识到板上的 LED 仍然亮着:)
-
你用什么来源为处理器计时?通常超低睡眠模式使用辅助低频振荡器(或外部芯片)来完成工作。如果不知何故您错误地使用了高频源,那将大大增加消耗。
-
您也可以尝试在这里提问:electronics.stackexchange.com。您确定
1829与1509具有相同的引脚排列吗?即使在正常工作条件下,PIC 的 18 mA 似乎也相当高,因此这可能是引脚不匹配和短路的情况。
标签: c embedded microcontroller pic microchip