Hola!
Tengo mi proyecto practicamente desarrollado al 100%, pero al validarlo y comprobar el consumo en sleep, estoy viendo que es de 1.55 mA.
He chequeado registro por registro y he desactivado previamente o justo antes del sleep todo lo posible, y no sé ya qué puede ser.
El micro controlador es el 12F1840. Os dejo un resumen de las declaraciones:
#device PIC12F1840 // Definición PIC
#include <12F1840.h> // Incluir especificaciones PIC
#device ADC = 10 // Analog output data with 10bits length
// CONFIG1
#fuses INTRC_IO // Internal Oscillator
#fuses NOWDT // Watch Dog Timer Disabled
#fuses NOPUT // Power-Up Timer Disabled
#fuses NOMCLR // Master Clear Reset pin disabled
#fuses NOPROTECT // Code not protected
#fuses NOCPD // Data Code not protected
#fuses BROWNOUT_NOSL // BrownOut reset enabled and disabled during sleep
#fuses NOCLKOUT // Clock Out is disabled. Enable to tune OSC frequency.
#fuses NOIESO // Internal/external switchover disabled
#fuses FCMEN // Fail safe clock monitor enabled
// CONFIG2
#fuses NOLVP // Low Voltage Programming disabled
//#fuses NODEBUG // Debug disabled
#fuses BORV19 // BrownOut reset 2.4V
#fuses NOSTVREN // Stack Overflow/Underflow Reset disabled
#FUSES PLL_SW //4X HW PLL disabled
#fuses NOWRT // Write protection disabled
#use delay(clock = 4MHZ) // Velocidad reloj PIC
void main (void) {
VREGPM = 1; // Enable Low-Power Sleep Mode
WPUA = 0; // Deactivate Weak pull-up resistor on every pin to avoid current consumption
T1GSEL = 1; // Select RA3 as Timer 1 Gate pin
TXCKSEL= 0; // Deactivated - Select RA4 as Tx pin for Rs232
// TIMER1 CONFIGURATION
// 00 = Timer1 clock source (Fosc/4)
// 11 = 1:8 Prescaler value
// 0 = Dedicated Timer1 oscillator circuit disabled (LP osc)
// 1 = Do not synchronize asynchronous clock input to Fosc
// 0 - Unimplemented
// 1 = Enable Timer1
T1CON = 0b00110101; // TIMER1 CONFIGURATION
// TIMER2 CONFIGURATION
// 0 - Unimplemented
// 1111 = 1:16 Postscaler
// 1 = Timer is ON
// 11 = Prescaler is 1:64
T2CON = 0b01111111; // TIMER2 CONFIGURATION
// INTERRUPT CONFIGURATION
GIE = 1; // Enable General interrupts
PEIE = 1; // Enable Peripheral Interrupts (TIMER1 uses it)
IOCAN3 = 1; // Enable IOC falling edge on pin RA3
TMR1GIE = 0; // Disable TMR1 Gate Acquisition interrupt. Code doesn't flow properly (too many interrupts)
TMR1IE = 1; // Enable TMR1 Overflow interrupt
TMR2IE = 1; // Enable TMR2 PR2 match flag
// Set inputs and outputs
// Inputs: RA3 RA4
// Outputs: RA0 RA1 RA2 RA5
TRISA = 0b00011000;
// Set analog or digital I/O
// Analog: RA4
// Digital I/O: RA0 RA1 RA2 RA3 RA5
ANSELA = 0b00010000;
// Configure Fixed Voltage Reference module
// FVR 1.024V and FVR ADC enabled, Temperature indicator disabled, and Comparator and DAC FVR disabled
FVRCON = 0b11000001;
// Set inputs and outputs
// Inputs: RA3 RA4
// Outputs: RA0 RA1 RA2 RA5
TRISA = 0b00011000;
// Set analog or digital I/O
// Analog: RA4
// Digital I/O: RA0 RA1 RA2 RA3 RA5
ANSELA = 0b00010000;
// Configure Fixed Voltage Reference module
// FVR 1.024V and FVR ADC enabled, Temperature indicator disabled, and Comparator and DAC FVR disabled
FVRCON = 0b11000001; // Set inputs and outputs
while (1) {
// ---------------------------------------------------
// ----- En este espacio van las condiciones para entrar en el sleep. No las pongo para resumir. ----------------------
// ---------------------------------------------------
GIE = OFF; // Global interrupt should be disabled before SLEEP to avoid entering in ISR
IOCAF3 = 0; // Clear flag
IOCIE = ON; // Activate IOC and deactivate timers
TMR1ON = OFF;
TMR2ON = OFF;
ANSELA = 0x00; // Disable Anagolic module on every pin to avoid current consumption during sleep
TRISA = 0b00001000; // Put pins to Output to minimize current consumption. RA3 can only be input
sleep(); // Go to sleep mode. Use capacitor to avoid bounce and undesired weak-up
IOCIE = OFF; // Go back to normal functioning and activate the timers
IOCAF3 = 0; // Clear flag
TMR1ON = ON;
TMR2ON = ON;
TRISA = 0b00011000; // Restore pin configuration after weak-up
ANSELA = 0b00010000; // Enable again Anagolic module on pin RA4
GIE = ON;
// ---------------------------------------------------
// ----- Continúa la ejecución del programa ----------------------
// ---------------------------------------------------
}
}
Alguien tiene alguna idea de qué puede ser?
He medido los voltajes de los pines con el polímetro y todos están a 0, excepto 2, que están a 0.5V (uno es el del botón y el otro es de un sensor resistivo).
¿Es posible que el consumo no me lo esté produciendo el PIC sino el sensor resistivo?
Gracias de antemano!
Saludos