Odd startup behavior at low voltage

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Odd startup behavior at low voltage

Post by SHughes_Fusion » Tue Feb 18, 2014 9:11 am

I wonder if anyone on the forum has seen something similar to this and can suggest a possible cause?

I've got a circuit that is powered by a CR2032 cell. It is a PIC18LF14K22 running a 3-digit 7-segment common anode display. It basically just looks for an input pulse from a hall effect sensor and outputs a number based on this.

Everything seems to work fine with a new battery but when the battery is getting low I see some odd effects. The most common one is that the unit will start up and seem to operate correctly but the pattern shown on the display is corrupted. All three digits have a different, random pattern. The unit has a power-down mode if no input signal is received after a few seconds and this works OK, blanking the display and flashing one decimal point as intended. The unit also 'wakes up' properly but still doesn't display correctly.

I've tried various things including making sure the power-up timer is on and that the device isn't clocked until the oscillator is stable (I use the INTOSC at 2MHz). I've also done a DelayMS(50) at the start of the code with no effect.

I can't tell if the memory locations allocated to the variables holding the digit pattern are somehow not working (although as the power-down mode which requires all outputs to be set high works), or whether the pre-programmed bit patterns for the numbers are somehow corrupt.

What is really odd is that sometimes the circuit will turn on and work fine just a minute after it went haywire.

I do have some code in there that monitors the battery voltage by sampling the FVR and displays a Battery-low message if it drops below 2.2V. This is the minimum voltage of the hall effect sensor but the PIC should work down to 1.8V. I was wondering about changing to using the brown-out reset but I'm also considering changing to a different hall sensor which only works down to 2.4V so that isn't a ideal approach.

Any other ideas or things to check? I know there is an errata for the F version of this processor for startup under low voltage but it recommends using the LF version as a resolution which suggests the problem doesn't apply to the variant I'm using.

User avatar
RangerBob
Posts: 152
Joined: Thu May 31, 2007 8:52 am
Location: Beds, UK

Re: Odd startup behavior at low voltage

Post by RangerBob » Tue Feb 18, 2014 12:43 pm

Are you absolutely sure you're not browning out the processor during the LED display sequence? Does it run OK from a bench supply?

A CR2032 has quite a high internal resistance, and if you start pulling a lot of current from it the terminal voltage starts to plummet rapidly. Remember most CR2032's are only rated for a drain current of ~200uA!

Your processor is running pretty fast and hungry (2MHz ~0.6mA core + peripherals), Hall effect sensors can be pretty power hungry (US1881 ~50mA!), and you don't mention how much each segment of the LED display is consuming, but even a couple of simultaneous 5mA led segments soon add up to a significant load.

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: Odd startup behavior at low voltage

Post by SHughes_Fusion » Tue Feb 18, 2014 1:53 pm

I did wonder that but as I say, it runs as expected just the display is corrupted.

The Hall sensor I use is a low power one - the SL353HT. I use 100R resistors on each LED segment, hard to tell what the current will be as you are towards the Vf of the LEDs so you need to study how Vf drops with current. At 20mA the quoted Vf is 2.2V and the PIC18LF can operate down to 1.8V so to be browning out you are probably only putting a couple of mA per segment.

I'm wondering if the best approach is to sample the battery voltage on start-up and refuse to boot if it is less than maybe something like 2.5V.

This isn't a deal-killer as I can just advise the users to change the battery if it misbehaves but I'd prefer to be able to actually give a warning that they need to do so.

I did a search and found this article which actually addresses the topic:
http://m.eet.com/media/1121454/c0924post.pdf

This suggests pulse loads are fine but the reduce the capacity of the battery by as much as half. In this application I have no space for a larger cell so I'm happy with the compromise.

I think this will be a compromise between throwing a battery low warning too early and having these uncontrolled errors that might make a user worry.

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: Odd startup behavior at low voltage

Post by SHughes_Fusion » Wed Feb 19, 2014 8:51 am

I looked in to this a bit more last night and I'm still confused.

I don't have a bench power supply to test it with, but I measured the battery voltage at 2.7V with the display illuminated. The software is also running as expected and is responding to an input by waking from 'sleep' (not the PIC sleep mode, I've implemented a function where the software turns the display off and uses the 32KHz oscillator as the system clock). What isn't working is that the predefined patterns aren't loading properly so the wrong pattern is being shown on the LED display.

If the battery is happily outputting 2.7V with the display on I can't see it dropping a volt below this processor start-up to force a brown-out affecting the startup.

There seem to be two possible issues. Either the Const array I've used to set the bit patterns isn't reading correctly or the RAM location of the buffer registers for the display aren't writing correctly.

Looking at the datasheet the only thing on these PICs that needs 2.7V or more is a bulk erase. I can't see this being used to set up const data - anyone know better?

Also, one last thought. This is the second iteration of this circuit. I didn't notice this phenomenon on the first version but then I didn't look for it specifically. The one difference between the two circuits is that I have a 100nF decoupling capacitor on the PIC for this one. I forgot about it on the first one but it seemed to work fine without it. The theory would suggest it is more likely to work properly with this capacitor but could there be something about it that is causing this unreliable operation? (Straws - clutching....)

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

Re: Odd startup behavior at low voltage

Post by Jerry Messina » Wed Feb 19, 2014 10:20 am

It's definitely not using a bulk erase to set up a table read... if it was somehow, you'd only see it once!

I've never observed where having a decoupling cap has hurt. If anything quite the opposite.

Do you have BOR enabled? If not you could always try setting it up and seeing if it has any effect.

What about the other CONFIG settings? You don't have LVP enabled by chance, do you? I've seen that cause issues before.

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: Odd startup behavior at low voltage

Post by SHughes_Fusion » Wed Feb 19, 2014 10:25 am

I don't use BOR, that was my next step as I was wondering if I could create a low-battery detect using the BOR, but it might be worth trying just to get it reliable.

I've got the following CONFIG settings:
Config
DEBUG = OFF,
FCMEN = OFF,
IESO = OFF,
PWRTEN = ON,
BBSIZ = OFF,
BOREN = OFF,
WDTEN = OFF,
WDTPS = 4096,
MCLRE = OFF,
STVREN = OFF,
XINST = ON,
LVP = OFF

I also set FOSC = IRC in a separate module which writes OSCCON.

Daft question, do you need to use the power-up timer with the INTOSC? That said, I can't see it hurting...

I think my next step is to implement the BOR (and I guess I should use the WDT as well) and see if that makes any difference. I guess I don't actually need to monitor the power flags at this stage to check for a BOR, just see if it makes any difference.

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

Re: Odd startup behavior at low voltage

Post by Jerry Messina » Wed Feb 19, 2014 12:28 pm

Try setting XINST = OFF.

Since it's a battery powered device, I don't know how much the power-up timer would get used but I always like to enable it when possible.

Since you're not using MCLR, I'd definitely try setting up the BOR and seeing if that helps out. Is the power ever shutoff/removed or do you just use your "low power sleep" mode?

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: Odd startup behavior at low voltage

Post by SHughes_Fusion » Wed Feb 19, 2014 1:43 pm

I'll give that a shot.

Thinking about it, I don't use MCLR for anything on this version of the design. I did have it going to an option jumper as I had made allowance for an analogue input but decided I didn't need that. I could solder a pull-up resistor on the ICSP header.

I must admit I don't know the difference between internal and external MCLR, I always thought it was better to use the internal one on modern PICs?

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

Re: Odd startup behavior at low voltage

Post by Jerry Messina » Wed Feb 19, 2014 2:07 pm

I always thought it was better to use the internal one on modern PICs?
Unless I really can't do it, I always enable the external MCLR pin and use a proper power supply voltage monitor IC to provide the reset.

This is probably just me being paraniod, but over the years I've had too many issues with power up/down problems.
Many of the PICs work at such low voltage/current they seem to run if you look at them cross-eyed... they just don't run properly.

That said, I've had reasonable luck using the BOR in its place for small circuits that don't have much extra circuitry involved.

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: Odd startup behavior at low voltage

Post by SHughes_Fusion » Thu Feb 20, 2014 9:40 am

Well, I'm still stumped!

I tried enabling BOR and.... no change.

I must admit I've never used a supervisor IC with a PIC and only on one critical application with an 8051 and never really seen any problems. I don't really want to add cost to the design (and a PCB re-spin...) so I'd prefer to resolve this but I'm starting to run out of ideas!

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

Re: Odd startup behavior at low voltage

Post by Jerry Messina » Thu Feb 20, 2014 4:21 pm

Maybe it's time to try your idea of enabling the MCLR input. If you can get it to screw up, just ground MCLR low for a bit and see if it starts up ok.

btw... you did change XINST = OFF, right? The extended instruction set changes the way certain asm code works, so the code generator has to be aware of that.

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: Odd startup behavior at low voltage

Post by SHughes_Fusion » Fri Feb 21, 2014 9:23 am

Jerry, you are a certified, grade A genius!

I'd forgotten your comment about turning off XINST. Did so last night and no issues at all since then.

What confuses me is why XINST makes it work sometimes and not others. I can see where it was going wrong - it was trying to read or write the wrong RAM locations due to the change in how XINST instructions reference addresses. However, what I can't understand is why this only happened some of the time, surely it should either work or not!

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

Re: Odd startup behavior at low voltage

Post by Jerry Messina » Fri Feb 21, 2014 11:20 am

Well, having XINST = ON adds some new instructions, but you wouldn't have to worry about those since SF wouldn't generate them. It also fundamentally changes the way some existing instructions work, like enabling the Indexed with Literal Offset Mode.

That mode effects about half the instruction set and depends on the contents of FSR2, which usually isn't used by SF and remains unknown since a reset doesn't effect it or initialize it. If you feel adventurous, you could try adding "FSR2 = 0" to your main code and re-enabling XINST to see what happens.

Definitely turn it back off when you're done playing around, though.

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: Odd startup behavior at low voltage

Post by SHughes_Fusion » Fri Feb 21, 2014 11:44 am

Right, I'd not spotted the link between XINST ON and FSR2, and that FSR2 isn't initialised on reset. I guess it is just resetting to a random value, most of the time it resets to 0 but under odd conditions it resets to something else.

I must admit I can't remember why I turned XINST on in the first place. I think I had an issue getting another circuit which used the 14K22 to boot up and found it worked when I turned XINST on and since then I've just kept the same config for everything.

I'd say this is a bit of a mistake by Microchip, they should have ensured FSR2 resets to zero under all circumstances to at least keep a degree of compatibility between the two modes.

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

Re: Odd startup behavior at low voltage

Post by Jerry Messina » Fri Feb 21, 2014 12:17 pm

I remember somebody else here had a similar issue. They were using a bootloader that needed XINST ON and was able to get SF to work with it by initializing FSR2 in the startup code.

Personally, doing that scares the willies out of me. I'd have switched bootloaders.

Post Reply