PDA

View Full Version : Cannot wake from SLEEP



BrianT
- 20th May 2013, 05:31
I cannot get my PIC18F4620 to wake from sleep. The code and the configuration settings are below. It is such a simple program but obviously I am missing some necessary register setting.

All suggestions gratefully received.
BrianT

</code>
'************************************************* ***************
'* Name : SleepLED.pbp *
'* Author : Brian Taylor *
'* Notice : Copyright (c) 2013 Brian Taylor *
'* : All Rights Reserved *
'* Date : 20/05/2013 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************

'*** PIC18F4620 Config Register setup for MeLabs U2 USB programmer ******
' OSC = INTIO2, Set to 4 MHz via OSCCON, FSCM = Dis, IESO = Dis, PwrupTmr = Dis
' BrownOut = Dis, BOR Volts = 2, WDT = Dis, WDTPS = 1:512, CCP2 mux = RC1,
' PortB reset = Digital, LPT1Osc = Low Pwr, MCLR = Reset, Stack overflow = Ena
' LVP = Dis, Enhanced CPU = Dis, All memory = Not Protected
'************************************************* ***********************


LED var PORTC.6 ' LED activity indicator
A var byte

OSCCON = %01101111 ' 4 MHz

Test:
debug "FlashTest", 13, 10
for a = 0 to 7 : high led : pause 50 : low led : pause 150 : next a

debug "LED sleep test", 13, 10
SleepTest:
high led
sleep 10
low led
pause 10
goto test

</endcode>

Archangel
- 20th May 2013, 07:01
sleep requires you enable WDT

BrianT
- 20th May 2013, 09:36
Something else is needed though. The next code snip hangs at the SLEEP line. WDTCON = 1 turns the SoftWDT on but that does not stop the hang..
</>
read 47, snooze.byte0
read 48, snooze.byte1
gosub lowestpower
WDTCON = %00000001
sleep snooze ' SLEEP for SNOOZE time
WDTCON = %00000001
gosub runstate
goto CheckLaunchHour
endif 'RunFlag = 0 case

</endcode>

This next code block works provided there is a WDTCON in the code.

'************************************************* ***************
'* Name : SleepLED.pbp *
'* Author : Brian Taylor *
'* Notice : Copyright (c) 2013 Brian Taylor *
'* : All Rights Reserved *
'* Date : 20/05/2013 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************

'*** PIC18F4620 Config Register setup for MeLabs U2 USB programmer ******
' OSC = INTIO2, Set to 4 MHz via OSCCON, FSCM = Dis, IESO = Dis, PwrupTmr = Dis
' BrownOut = Dis, BOR Volts = 2, WDT = Dis, WDTPS = 1:512, CCP2 mux = RC1,
' PortB reset = Digital, LPT1Osc = Low Pwr, MCLR = Reset, Stack overflow = Ena
' LVP = Dis, Enhanced CPU = Dis, All memory = Not Protected
'************************************************* ***********************

DEFINE OSC 4 'Define crystal frequency. Needs setting via OSCCON
DEFINE DEBUG_REG PORTB 'Debug output pin port
DEFINE DEBUG_BIT 6 'Debug output pin bit
DEFINE DEBUG_BAUD 19200 'Debug baud rate
DEFINE DEBUG_MODE 0 'Debug mode: 0 = True, 1 = Inverted

LED var PORTC.6 ' LED activity indicator
A var byte

WDTCON = %00000001 ' enables SWDT - needs WDT OFF in config
OSCCON = %01101111 ' 4 MHz
Test:
high portb.6 : pause 1 'make the TxD pin an output
debug "FlashTest", 13, 10
for a = 0 to 7 : high led : pause 50 : low led : pause 150 : next a
debug "LED sleep test", 13, 10
sleep 5
low led
pause 100
goto test

Gusse
- 20th May 2013, 10:57
How about WDT_ON_2H in CONFIG?
PICs CONFIGS (http://www.picbasic.co.uk/forum/content.php?r=467-PICs-CONFIGS-and-Oscillator-Settings-for-Beginners)

BrianT
- 21st May 2013, 01:17
I am using PBP3.0.1.4 with MCSPX 5.0.0.5

I set the config state through the drop down [C] button that pops up whenever I do a 'compile/program'. There is no choice to set WDT_ON_2H.

Is WDT_ON_2H a valid directive for a PIC18F4620?

Gusse
- 21st May 2013, 07:47
Yes it is. Below is part of PIC18F4620.PBPINC from device -folder.


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The #CONFIG block is passed directly to the asm file, but PBP will replace it
; automagically with the contents of a user-defined #CONFIG block if one is
; found in the PBP source program. There is no need to edit or comment this
; block in this file. Simply copy it to your source program and edit it there.

#CONFIG
__CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L
#ENDCONFIG

This is example that I have used with PIC18F4520 and it might be just fine for you too. If not, then change according to your needs.
At least sleep & nap are working OK, also with interrupt. Check right parameters for CONFIGS from link that I sent earlier (credits to Demon).

#CONFIG
__CONFIG _CONFIG1H, _OSC_INTIO67_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOREN_OFF_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
#ENDCONFIG