Power Control (PCON) Register
I have a situation where I need to skip over part of a program if a MCLR reset has occurred. The device is 16F1823. MCLRE is enabled on. The manual says a MCLR reset can be differentiated from a power on reset by observing the bits in the PCON register. The code I tried works some of the time, but is inconsistent and ultra sensitive to noise and grounding conditions. The code section:
Code:
if PCON.3 = 0 then 'when mclr reset has occurred
PCON.3 = 1 'set mclr flag
goto current 'jump over data display
endif
Question: Is the PCON register accessible by PBP? Should asm be used for this task instead?
Re: Power Control (PCON) Register
In answer to own question, of course PCON is accessible by PBP, all registers are. I tried asm and it makes no difference, the sensitivity to noise is still there. The circuit does work some of the time, so this is most likely a hardware issue. I'll keep working on it.
Re: Power Control (PCON) Register
The following code modification fixes the problem. The idea is a double set of the MCLR reset flag. Electrical noise tends to disrupt the initial condition of the MCLR bit so a double set is needed:
Code:
if PCON.1 = 0 then 'when por reset has occurred
PCON.3 = 1 'set mclr flag
PCON.1 = 1 'set por flag
endif
if PCON.3 = 0 then 'when mclr reset has occurred
PCON.3 = 1 'set mclr flag
goto current 'jump over data display
endif
This is working nearly 100% of the time, unless the noise environment is very,very severe.
The fix is posted here for future reference.
Re: Power Control (PCON) Register
I'm just curious as to what machine is making so much electrical noise that it's affecting your circuit?
Is it time for a new power supply or a few capacitors and a coil?
Are there electrical issues in your other devices?
Like I said, just curious.
Re: Power Control (PCON) Register
Thanks Dick, I am now using this info to control a field of solar micros to stow with central power control -- RCON.1
Re: Power Control (PCON) Register
AV1
The system is brushless dc motor control. My project is an energy meter in series with the battery power line. The motor controller generates lots of electrical noise, especially during the startup phase of motor operation.
SUNFLOWER
I'm glad the PCON tactic is working for you.