PDA

View Full Version : Reset types and the RCON register



jbutera
- 23rd April 2010, 17:24
I have a program that resets ocassionally and to help find out why, I thought I'd make use of the RCON register. There is a hardware watchdog that toggles MCLR, and the internal watchdog is disabled.

The datasheet (18F8722) is a bit confusing with every reset type setting the flags in a different way, but I suppose that's to be expected for these kinds of flags. I was just wondering if anyone has used the RCON register successfully on an 18F with PBP.

Also, MCLoader is being used for the bootloader, but I have been unable to find anything saying if it messed with RCON or not.

Any help would be appreciated. I will post my progress as I go.

John

jbutera
- 23rd April 2010, 19:13
Here's what I have so far


'-------------- Reset Type -----------------------------------------------------
' manage the RCON/STKPTR flags and come up with a sane reset indication
' there will probably be only one bit set, but anything is possible
' especially with regards to the powerdown bit, which gets set by a SLEEP instr.
'
' 0 brownout, 1 poweron, 2 powerdown, 3 wdt timeout
' 4 reset instruction, 5 (unused), 6 stack underflow, 7 stack full

ResetTypeMask var byte
ResetTypeMask = 0

GetResetType:
' Brown-out Reset
if RCON & %11 = %10 then ' BOR 0, POR 1
ResetTypeMask.0 = 1
RCON.0 = 1 ' set BOR
endif

if RCON.1 = 0 then ' POR 0
ResetTypeMask.1 = 1
RCON.1 = 1 ' set POR
endif

' RESET instruction
if RCON.4 = 0 then ' RI 0
ResetTypeMask.4 = 1
RCON.4 = 1 ' set RI
endif

' WDT reset
if RCON.3 = 0 then ' TO 0
ResetTypeMask.3 = 1
' TO is read-only
endif

' Stack Full
if STKPTR.7 = 1 then ' STKFUL 1
ResetTypeMask.7 = 1
STKPTR.7 = 0
endif

' Stack Underflow
if STKPTR.6 = 1 then ' STKUNF 1
ResetTypeMask.6 = 1
STKPTR.6 = 0
endif

' Powerdown Detection
if RCON.2 = 0 then ' PD 0
ResetTypeMask.2 = 1
' PD is read-only
endif

JasonMarsh
- 28th May 2013, 13:06
Hi jbutera,

Did you find a way to do this?

I have a similar problem...

I am performing a hardware MCLR (on rare occasions), and wish to detect when it occured.

My line of code is:

If RCON.1 = 0 Then GoTo mclr