Brown Out Detection

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

Brown Out Detection

Post by Widgetman » Sun Apr 03, 2011 2:18 pm

Hi,
Does anyone know how to use the Brown out feature on some PIC parts ?
I was looking at using the 18F24J10 or 18F25J10 parts for a project, but I do not see in the Include files where POR or BOR are configurable. RCON register bits 1 and 0 are these status flags when a interruption of power occurs. Does this mean I have to modify the Include files to support that feature ? ANy example or help would be greatly appreciated.
Thanks


Here is what I tried

Function Called:

Public Sub PIC_RESET()
Asm
Reset
End Asm

End Sub



Main:

If ((RCON And $02) = $02) Then ' Mask Off Lower Two Bits To See If A BOR Occured. If So Reset Part
PIC_RESET()
End If

Jerry Messina
Swordfish Developer
Posts: 1470
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Mon Apr 04, 2011 9:39 am

I think you're misinterpreting the brownout function.

If you enable the BOR in the config settings, then when a brownout event occurs the processor will automatically reset. You don't have to do anything else.

You can check the bits in RCON at the start of your program to see if any of the various reset events caused you to restart, but it's already happened and this is after the fact.

Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

BOR and POR

Post by Widgetman » Mon Apr 04, 2011 11:41 am

Hi,
I was just reading from the app notes in the datasheet on the 18F25J10 and 24J10 parts. Below is what it states and how to handle a detection of a brownout. The bits are R/W and I believe they require maintence after a condition has occured. The last note 3 talks about how to detect the condition. Maybe I read the notes wrong. Do I just set the BOR bit and forget it ?
Thanks

bit 1 POR: Power-on Reset Status bit
1 = A Power-on Reset has not occurred (set by firmware only)
0 = A Power-on Reset occurred (must be set in software after a Power-on Reset occurs)

bit 0 BOR: Brown-out Reset Status bit(1)
1 = A Brown-out Reset has not occurred (set by firmware only)
0 = A Brown-out Reset occurred (must be set in software after a Brown-out Reset occurs)

Note 1: BOR is not available on PIC18LF2XJ10/4XJ10 devices.

Note 1: It is recommended that the POR bit be set after a Power-on Reset has been detected, so that subsequent
Power-on Resets may be detected.

2: If the on-chip voltage regulator is disabled, BOR remains ‘0’ at all times. See Section 5.4.1 “Detecting
BOR” for more information.

3: Brown-out Reset is said to have occurred when BOR is ‘0’ and POR is ‘1’ (assuming that POR was set to
‘1’ by software immediately after a Power-on Reset).

Jerry Messina
Swordfish Developer
Posts: 1470
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Mon Apr 04, 2011 1:14 pm

Those statements are a bit confusing, at least to me. You're right... once you detect one of the events you should set the bit so you can detect future events next time.

If you look at Table 5-1 (and the other paragraphs in that section), you'll see that the only event that sets all the RCON bits to a known state is a Power-On reset, which sets them to %00111100. After that, each of the different events may only change part of the register.

If you detect a PON reset, set bits POR and BOR. After that, if you see POR =1 and BOR = 0, you know you've been reset due to a BOR.

Code: Select all

pon_stat = RCON and $3F
if (pon_stat = %111100) then						// power-on reset
	RCON.POR = 1									// set bits so we can detect other events later
	RCON.BOR = 1
elseif (pon_stat.1 = 1) and (pon_stat.0 = 0) then	// brown-out reset has occured
	// user code to deal with BOR
	RCON.BOR = 1									// set bit so we can detect other BOR events
else
	// look at the other reset status bits
endif

Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

POR Detection

Post by Widgetman » Mon Apr 04, 2011 8:36 pm

Hi,
Thanks for the input Jerry. I tried the example and ran into issues assigning bit declarations on the RCON register. How do I declare a individual bit access ? the code below did not compile.
thanks

RCON.POR = 1 // set bits so we can detect other events later

Jerry Messina
Swordfish Developer
Posts: 1470
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Mon Apr 04, 2011 8:49 pm

Sorry 'bout that. Just an illustration.

The easiest way is probably just to define aliases...

dim BOR as RCON.0,
POR as RCON.1

BOR = 1
POR = 0

There's a few other ways as well, such as defining a structure of the register layout.

Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

Thanks

Post by Widgetman » Tue Apr 05, 2011 12:44 pm

Hi Jerry,
Thanks for the tip. I had tried a couple different ways to bit address stuff but the compiler did not like it. It never dawned on me to alias it. I will play with the brown out and see what happens. I get plenty of brown outs at my house so I should see something soon.

Jerry Messina
Swordfish Developer
Posts: 1470
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Tue Apr 05, 2011 1:24 pm

There's a couple of different ways to access the bits. If you poke around, you'll find a number of them. Here's a summary of a few...

Code: Select all

#define method = 4

#if (method = 1)
// method 1
// absolute bit reference
RCON.0 = 1

#elseif (method = 2)
// method 2
// bit alias
dim BOR as RCON.0
BOR = 1

#elseif (method = 3)
// method 3
const BOR = 0       // define the bit number in the register
'RCON.BOR = 1            // doesn't work
RCON.bits(BOR) = 1      // works

#elseif (method = 4)
// method 4
structure RCON_T
    b as byte
    BOR     as b.0
    POR     as b.1
    PD      as b.2
    _TO     as b.3
    RI      as b.4
    IPEN    as b.7
end structure

dim _RCON as RCON_T absolute $0FD0
_RCON.BOR = 1

#endif
The structure method is nice, but you need to know the register location. While the register bits themselves can (and do) change from chip to chip, the locations can change as well. It's probably best to put all this stuff in a chip-specific file, and just include that.

User avatar
RadioT
Registered User
Registered User
Posts: 157
Joined: Tue Nov 27, 2007 12:50 pm
Location: Winnipeg, Canada

Post by RadioT » Sun Jul 24, 2011 2:23 pm

As a general point, always check the errata on the Microchip site for your part. They state the known problems with the part number; almost all chips have some errata.

I ran into a BOR and low-power sleep problem on the 18F86J11, at least with the batch we bought 2 years ago. I ended up giving up after working on it with a Microchip engineer and added a 2.5V low-power regulator to the board so the chip would properly sleep when commanded.

-Tom

Post Reply