Searching \ for '[PIC:] 16F684 wake up problem' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=16F
Search entire site for: '16F684 wake up problem'.

Exact match. Not showing close matches.
PICList Thread
'[PIC:] 16F684 wake up problem'
2007\02\28@055030 by Peter Feucht

flavicon
face
Dear Piccers,

pls see below most of my code. Everything works fine except my wake up from
sleep, it goes to sleep, no problem, but it never wakes up again. Any idea?

Thanks for help

Peter

'---------------------------------------------------------------------------
-------------
'Compiler Directives
'---------------------------------------------------------------------------
-------------
@ DEVICE PIC16F684, INTRC_OSC_NOCLKOUT 'interner Oszillator 4MHz,
RA4/5=IO-Pins
@ DEVICE PIC16F684, WDT_OFF    'Watchdog OFF
@ DEVICE PIC16F684, PWRT_ON    'Power-Up-Timer ON
@ DEVICE PIC16F684, MCLR_OFF    'Masterclear INTERNAL
@ DEVICE PIC16F684, PROTECT_ON   'Software geschützt
@ DEVICE PIC16F684, CPD_OFF    'EEPROM nicht geschützt
@ DEVICE PIC16F684, BOD_NSLEEP   'Brownout on but off during sleep
@ DEVICE PIC16F684, IESO_OFF    'kein externer Clock, daher keine
Überwachung
@ DEVICE PIC16F684, FCMEN_OFF    'kein externer Clock, daher keine
Überwachung

'---------------------------------------------------------------------------
-------------
'Aliases
'---------------------------------------------------------------------------
-------------
KEY_N   VAR PORTA.0   'Key N
KEY_D   VAR PORTA.1   'Key D
TESTOUT  VAR PORTA.2   'test output (not used so far)
TESTIN  VAR PORTA.3   'test input (not used so far)
X1    VAR PORTA.4   'crystal pin (not used)
X2    VAR PORTA.5   'crystal pin (not used)

LEDS   VAR PORTC.0   'LEDs output (one LED to Vcc, one to GND (via
resistor)
BattSense VAR PORTC.1   'Batt sense input (analog AN5)
MagOut  VAR PORTC.2   'relay output
Plus   VAR PORTC.3   'supply voltage for an external EEPROM
SPIDAT  VAR PORTC.4   'SPI-DAT
SPICLK  VAR PORTC.5   'SPI-CLK (= PWM1A output)

'---------------------------------------------------------------------------
-------------
'Constans/Variables/Inits
'---------------------------------------------------------------------------
-------------

DEFINE OSC 8    '8MHz master clock


OSCCON    = %01110001   'Oscillator Config
      '       ^ internal oscillator is used for system clock
      '     ^^  stable bits (don't care)
      '    ^  device is running from internal oscillator
      ' ^^^   8MHz
      '^    unimplemented

CMCON0    = 7      'disable comparators

OPTION_REG= %00000111
    '     ^^^ TMR0-Prescaler = 1:256
    '    ^    Prescaler assigned to TMR0
    '   ^   TMR0 edge select (don't care)
    '  ^   TMR0 clk source = internal clock
    ' ^   INT edge select (don't care)
    '^    PORTA pullups enabled

T1CON     = %00000001
    '       ^ TMR1 enabled
    '      ^  TMR1 operated from internal clock
    '     ^  ignored (internal clock)
    '    ^  LP oscillator disabled
    '  ^^   Prescaler = 1:1
    '^^   ignored, no gating

INPUT Key_N     'port for KEYN   PORTA.0 INPUT
INPUT Key_D     'port for KEYD   PORTA.1 INPUT
INPUT TESTIN    'test input pin  PORTA.2 INPUT
LOW TESTOUT     'test output   PORTA.3 OUTPUT LOW
LOW X1      'unused crystal port PORTA.4 OUTPUT LOW
LOW X2      'unused crystal port PORTA.5 OUTPUT LOW

WPUA   = %00000011   'enable weak pullup at PORTA0. and .1
IOCA   = %00000011   'INT on change enable für both keys
     
INPUT LEDS     'port for LEDs       PORTC.0 INPUT
INPUT BattSense   'port for sensing batt voltage PORTC.1 INPUT/ANALOG
LOW MagOut     'port for relay      PORTC.2 OUTPUT LOW
LOW Plus      'port for EEPROM supply voltage PORTC.3 OUTPUT LOW
LOW SPICLK     'SPI clock port      PORTC.4 OUTPUT LOW
LOW SPIDAT     'SPI data output port    PORTC.5 OUTPUT LOW

ANSEL   = %00100000   'configure AN5=PORTC.1 as analog input

OM   VAR BYTE       'OperationMode  0 = off
             '      1 = mode N
             '      2 = mode D
OM = 0           'init, but will be changed due to key pressed

BLC   VAR BYTE      'BLinkCounter
BLC = 0           'init
BLCMax  CON 30       'BLinkCounterMaximum (1s)

TICMaxN  CON 18462      'ShutDown N (600s)
TICMaxD  CON 36924      'ShutDown D (1200s)
TICMax  VAR WORD      ''actual TICMax value

TIC   VAR WORD      'TIMerCounter
TIC = 0           'init

SDC   VAR BYTE      'ShutDownCounter
SDC = 0           'init
SDCMax  CON 60       'ShutDownMaximum = 2s

some more variables to be defined...
 
'---------------------------------------------------------------------------
-------------
Start:
'---------------------------------------------------------------------------
-------------
'PIC woke up, now checking, which key has been pressed

IF Key_N = 0 THEN        'if key "N" is pressed
 OM = 1          'set operation mode
 LOW LEDS          'switch on N-LED
 WHILE Key_N = 0        'wait until key is released
 WEND
 INPUT LEDS         'switch off N-LED
ENDIF
   
IF Key_D = 0 THEN        'if key "D" is pressed
 OM = 2          'set operation mode
 HIGH LEDS          'switch on D-LED
 WHILE Key_D = 0        'wait until key is released
 WEND
 INPUT LEDS         'switch off D-LED
ENDIF

GOSUB InitVars         'setup several variables and constants

'check batt status (still missing)

Plus = 1           'activate supply voltage for external EEPROM
PAUSE 50           'wait until EEPROM is ready for operation

B1=3 : SHIFTOUT SPIDAT,SPICLK,1,[B1] 'shitout start adress to external
EEPROM
B1=0 : SHIFTOUT SPIDAT,SPICLK,1,[B1] 'start adress = 00
B1=0 : SHIFTOUT SPIDAT,SPICLK,1,[B1]
 
PAUSE 50           '???

HPWM 1,127,13000        'now set SPICLK to continuous 13KHz
             'all further reads to be performed serially
             'without any pauses, loop until device is
             'switched off

'---------------------------------------------------------------------------
-------------
MainLoop:
'---------------------------------------------------------------------------
-------------
IF INTCON.2 = 1 THEN       'if TMR0 overflow
 INTCON.2 = 0        'reset overflow flag
 TIC = TIC + 1        'increment TImerCounter
 BLC = BLC + 1        'increment BLinkCounter
 SDC = SDC + 1        'increment ShutDownCounter
ENDIF

IF TIC > TICMax THEN       'if operation time is reached
 GOTO ShutDown        'switch off the device
ENDIF

INPUT LEDS          'first switch off LEDs
IF BLC = BLCMax THEN       'if 1s is over
 IF OM = 1 THEN        'if Mode = "N"
  LOW LEDS         'switch on LED "N" now
 ENDIF
 IF OM = 2 THEN        'if Mode = "D"
  HIGH LEDS        'switch on LED "D" now
 ENDIF
 BLC = 0          'and re-init blink counter
ENDIF  

IF Key_N = 1 THEN        'if no key is pressed
 IF Key_D = 1 THEN
  SDC = 0         'reset ShutDownCounter
 ENDIF           'if any key is pressed SDC continues to
ENDIF            'increment

IF SDC > SDCMax THEN       'if any key was pressed long enough
 GOTO ShutDown        'shut down the device
ENDIF

IF OM = 2 THEN         'if Mode "D" is active
 IF Key_N = 0 THEN       'and mode shall change
  OM = 1         'set to new mode
  GOSUB InitVars       'and init some variables and constants
 ENDIF
ENDIF

IF OM = 1 THEN         'if Mode "N" is active
 IF Key_D = 0 THEN       'and mode shall change
  OM = 2         'set to new mode
  GOSUB InitVars       'and init some variables and constants
 ENDIF
ENDIF

IF OM = 1 THEN N       'now branch according to opartion mode
IF OM = 2 THEN D

GOTO MainLoop         'for operation mode = 0 (should never happen)

'---------------------------------------------------------------------------
-------------
N:
'---------------------------------------------------------------------------
-------------
'do something
GOTO MainLoop

'---------------------------------------------------------------------------
-------------
D:
'---------------------------------------------------------------------------
-------------
'do something
GOTO MainLoop

'---------------------------------------------------------------------------
-------------
ShutDown:
'---------------------------------------------------------------------------
-------------
IF Key_D = 0 THEN ShutDown     'wait until both keys are released
IF Key_N = 0 THEN ShutDown

PAUSE 10           'wait some time (debounce)
Plus = 0           'swutch off EEPROM
MagOut = 0          'switch off relay output
SPICLK = 0          'switch off SPI ports
SPIDAT = 0
HPWM 1,127,0         'switch off PWM

B1 = PORTA          'dummy reads to actualize port states
B1 = PORTC

INTCON.7 = 1         'enable global interrupt
OM = 0           'set operation mode to 0 (for the case that
             'device wakes up due to any kind of
             'electrostatic spike or something else), in this
             'case the software should jump to START and then
             'go to SHUTDOWN again (and fall asleep again)
             
SLEEP 50000          'now sleep

'  *** when device wakes up it should be here, right?

PAUSE 1
INTCON.7 = 0         'disable global interrupt

PAUSE 10            '???
GOTO Start            'from the top....

STOP            'to prevent running into following GOSUB

'---------------------------------------------------------------------------
-------------
InitVars:
'---------------------------------------------------------------------------
-------------
' init some variables
RETURN  

2007\02\28@133410 by Vasile Surducan

face picon face
Which is the result of the instruction SLEEP 50000 ?

On 2/28/07, Peter Feucht <spam_OUTp.feuchtTakeThisOuTspampalmed-medizintechnik.de> wrote:
{Quote hidden}

>

2007\02\28@153250 by Tech

flavicon
face
> pls see below most of my code. Everything works fine except my wake up from
> sleep, it goes to sleep, no problem, but it never wakes up again. Any idea?

>  @ DEVICE PIC16F684, WDT_OFF    'Watchdog OFF

The BASIC version of SLEEP requires you to have the WDT enabled. It sets up a loop
that counts down the SLEEP time interval, and exits the loop once the time interval
has expired.

If you have WDT disabled, and want to use wake-up-on-change, then use the @ SLEEP
assembler option.

Otherwise, you're waking up within the BASIC SLEEP loop, and execution begins with the
next instruction in the BASIC SLEEP loop, waiting for the time period to expire.

Regards,

-Bruce

.....techKILLspamspam@spam@rentron.com
Reynolds Electronics

More... (looser matching)
- Last day of these posts
- In 2007 , 2008 only
- Today
- New search...