TL;DR: Don't enable the 'brown-out reset' configuration bit if you are using the PIC at less than 5 volts.
I have been playing with Microchip PICs for a number of years. Mostly I use something in the PIC16F628 family. At some point I ordered the LF (low voltage) version, but I still used them with either a 5v power supply or with 3 AA batteries. Every once in a while, since I had the LF version, I would try to use 2 AA batteries or even a 3v coin cell, but the circuit never worked. I wondered why, but I never gave it too much thought. Yet it still nagged me. The specs said the chip should work down to 2 volts, but it was not working for me.
The other night I finally sat down to try it again. This time, instead of starting with a complete project designed for 5 volts, I decided to start with a blank chip, blank project, and blank bread board. I copied the header from one of my other projects, since it set-up the chip and configuration I usually use, and wrote a little code to blink one LED. I programmed the chip, added an LED with a 10 ohm resistor and added a CR2032 coin cell -- and nothing happened. I double checked the wiring, but did not find anything wrong. I removed the battery, then set the programmer to power the chip at 3 volts (thinking that the coin cell did not have enough power) and reconnected it to the breadboard. Still nothing.
I thought that maybe I wired the circuit wrong or had a problem with the program. To rule out these possibilities, I decided to power the circuit at 5 volts (and use a larger resistor). I found a few problems and fixed them. Now the LED was blinking. Again I tried the project at 3 volts, and again, nothing.
When all else fails, double-check the spec. So now I look at the spec and check the chart that shows the supported voltage range. It says it works as low as 2 volts, but my LED is not blinking. I pull out the oscilloscope. Maybe, I think, that the port pin is going high and low, but does not have enough current to drive the LED. The scope shows nothing. I try the circuit at 5 volts again. The LED works and, of course, I see the trace on the scope. I switch back to 3 volts and nothing.
At this point I am really wondering what the problem could be. I start looking through the spec again, but there is no mention of anything special regarding using the chip at 3 volts. I check the settings in MPLAB, the Microchip development environment, and I do not find anything about configuring a chip for low voltage usage. I look at the configuration bits I have set in the program. None of them seem to be related to my problem. There is something called 'low voltage programming', but, I figured, this is not a programming problem. I do not think it is the watchdog timeout.
I notice that I have 'brown out reset' (BOD) enabled. In the spec, there is no mention of a dependency or relationship between the brown out reset voltage and the chip voltage. What I mean is that there is not a sentence that says "do not use brown-out reset for low voltages" or "the brown-out reset voltage level is 80% of the supply voltage". I continue to read the spec hoping to find something useful, something that explains why I can't run the chip at 3v.
Somewhere I notice the term V[BOR], which I take to mean "voltage: brown out reset". In particular, the sentence say "If V[DD] falls below V[BOR] ... the brown-out situation will reset the chip." I also notice the condition in one of tables describing a brown out event that says V[DD] < V[BOR]. There is also a diagram showing the trigger of a brown-own reset when V[DD] dips below V[BOR]. All of a sudden V[BOR] seems important.
A little more searching and I find that V[BOR] is typically 4.0v. I wonder, how can the chip even work if the brown-out reset voltage is 4v, but the power supply is 3v? The answer is, of course it can not. This is why the chip never works for me on 3v. I have the brown-out detect configuration bit set.
I disable the brown-out detect bit and reprogram the chip. All of a sudden, it just works. I can now run the chip on a coin cell.
I realize that I always "brought this problem with me" from project to project because I always copied the top part of the assembly file from one project to another, just as I did for this test project. Some time ago, for some project, I must have thought that I needed the brown-out reset enabled, and it has been set since then.
One more note on this: For some reason the PicKit 2 programmer has a problem programming the PIC16LF648a when the programmer voltage is set to 3v. I don't have a solution to this, just a work-around. I set the voltage of the PicKit 2 to 5v and unplug the LEDs when I am programming the chip.
Comments