PDA

View Full Version : 16f883 sleeping mode



kolega35
- 2nd January 2015, 17:40
Hi! How can I minimize the currentdraw in sleep mode with a 16f883? I 've disabled most of the peripherals. I use 4 MHz internal oscillator and disabled the watchdog . But in sleep currentdraw still high level(450 ľA) . My goal is <5 ľA is this possible and how.

Codes:

ANSEL=%00000000'all analogue ports to digital
ANSELH=%00000000'all analogue ports to digital
ADCON0.0=0'disable ADC
CM1CON0=%00000000'disable COMPARATOR 1
CM2CON0=%00000000'disable COMPARATOR 2
SSPCON=%00000000'disable SERIAL PORT
RCSTA=%00000000'disable SERIAL PORT
PCON=%00000000'disable BOR and ULPW
OPTION_REG=%00000000'disable INTERNAL PULLUPS
WPUB=%00000000'disable INDIVIDUAL PULLUPS
IOCB=%00000000'disable INTERRUPT ON CHANGE
CCP1CON=%00000000'disable ECCP1
PSTRCON=%00000000'disable PULSE STEERING MODE
T1CON=%00000000'disable TIMER1

TRISB=%11111111
TRISC=%00000000
TRISA=%00000000
porta=0
portc=0


SYMBOL BUTON0=PORTB.0
SYMBOL BUTON1=PORTB.1
SYMBOL BUTON3=PORTB.3
SYMBOL BUTON4=PORTB.4
SYMBOL BUTON5=PORTB.5
SYMBOL BUTON6=PORTB.6


main:
IF BUTON0=0 then portc.1=1
IF BUTON1=0 then portc.2=1
IF BUTON3=0 then portc.3=1
IF BUTON4=0 then portc.4=1
IF BUTON5=0 then portc.5=1
IF BUTON6=0 then portc.6=1
PORTC=%00000000
GOTO main

mackrackit
- 2nd January 2015, 19:01
SLEEP

SLEEP Period

Place microcontroller into low power mode for Period seconds. Period is 16-bits, so delays can be up to 65,535 seconds (just over 18 hours).

SLEEP uses the Watchdog Timer so it is independent of the actual oscillator frequency. The granularity is about 2.3 seconds and may vary based on device specifics and temperature. This variance is unlike the BASIC Stamp. The change was necessitated because when the PICmicro executes a Watchdog Timer reset, it resets many of the internal registers to predefined values. These values may differ greatly from what your program may expect. By running the SLEEP command uncalibrated, this issue is sidestepped.

SLEEP 60 ' Sleep for about 1 minute

The above is from the manual. I post it as I do not see the "SLEEP" command in your code.

kolega35
- 2nd January 2015, 19:34
I don't know how to write code to sleep. I want help for it.
The above is from the manual. I post it as I do not see the "SLEEP" command in your code.

mackrackit
- 3rd January 2015, 13:53
http://melabs.com/samples/PBP-mixed/sleep.htm

andywpg
- 3rd January 2015, 17:15
Here's some code from when I needed a 16f886 to sleep until PORTB.0 went low. You should be able to adapt it. I should mention that I am self-taught at BASIC so there's probably a better way to do this:




#CONFIG __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_OFF

#ENDCONFIG

DEFINE NO_CLEARWDT 1 'NO WATCHDOG TIMER
DEFINE OSC 8 'LETS PBP KNOW THE OSCILLATOR IS RUNNING AT 8MHz

OSCCON = %01110001 '8 MHz INTERNAL OSCILLATOR, INTERNAL OSCILLATOR IS USED FOR SYSTEM CLOCK

DISABLE 'NO INTERRUPTS, NO DEBUG COMMENT THIS OUT FOR INTERRUPTS


ANSEL = 0 'PORTA ALL DIGITAL
ANSELH = 0 'PORTB ALL DIGITAL

OPTION_REG = 0 'PORT B PULLUPS ENABLED
WPUB = %01111111 'PULL UPS ENABLED ON PORTB 0-6

INTCON = 0 'INTERRUPTS DISABLED
IOCB = %00000001 'PORTB.0 INTERRUPT ON CHANGE ENABLED
TRISA = 0 'PORTA ALL OUTPUTS
TRISB = %01111111 'B7 OUTPUT, ALL THE OTHERS INPUTS
TRISC = 0 'PORTC ALL OUTPUTS

DUMMY VAR BYTE

<irrelevant code here>

INTCON = %00001000 'PORTB CHANGE INTERRUPT ENABLED GIE *NOT* ENABLED
NAP 0 'NAP (ENTER VERY LOW POWER MODE) FOR ABOUT 18mS. SINCE THE WATCHDOG TIMER IS NOT ENABLED,
'THE PROCESSOR WOULD NAP FOREVER, EXCEPT FOR THE FACT THAT THE 'INTERRUPT-ON-STATE-CHANGE'
'BIT FOR PORTB.0 (MASTER SWITCH) IS ENABLED. THIS MEANS THAT A CHANGE ON THE MASTER SWITCH
'(OFF TO ON) WILL GENERATE AN INTERRUPT. HOWEVER, THE GLOBAL INTERRUPT ENABLE BIT IS *NOT*
'SET. THIS MEANS A *REAL* INTERRUPT WILL NOT BE GENERATED. THE PROCESSOR WILL NOT JUMP TO THE INTERRUPT
'ROUTINE, AND WILL, INSTEAD, EXECUTE THE NEXT INSTRUCTION AFTER THE NAP - IN OTHER WORDS, CONTINUE
'THE MAIN LOOP WHERE THE NEW STATE OF THE MASTER SWITCH WILL BE CAUGHT BY THE IF STATEMENT. THIS
'HAS THE EFFECT OF SHUTTING THE PROCESSOR DOWN (ESSENTIALLY) UNTIL THE MASTER SWITCH IS TURNED ON
'AGAIN - SAVING THE VEHICLE'S BATTERY IF THE MAIN POWER SWITCH IS ACCIDENTALLY LEFT ON. OPERATION
'OF ANY OF THE OTHER SWITCHES WILL NOT CAUSE THE ABOVE TO HAPPEN AS THEIR ENABLE BITS IN THE IOCB
'REGISTER HAVE NOT BEEN SET.
DUMMY = PORTB 'READ PORTB TO CLEAR THE MISMATCH THAT GENERATED THE INTERRUPT
INTCON = 0 'INTERRUPTS OFF AGAIN

kolega35
- 3rd January 2015, 21:27
Thanks for your help. Best Regards.