MC13213  voltage level detection

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MC13213  voltage level detection

3,515 Views
McGillMike
Contributor I
I was wondering how can I acertain that I ma no longer supplying my processor with a constant wall-power source and that the battery supply has kicked in (let's assume that a power shortage has occured)?
 
I know about the LVD interrupts, but don't those just arise in the event of complete loss of all power (going towards 0) to intiate a hardware reset to preserve memory integrity?
 
I think what I'm looking for is how to gauge the current power level (much like the indicators on a cell-phone battery) or at least something along the lines of knowing that I am now dealing with batteries instead of wall or USB power (CPU crashed...).
 
 
Thanks. 
Labels (1)
0 Kudos
Reply
4 Replies

716 Views
bigmac
Specialist III
Hello,
 
I might suggest using a couple of ATD channels.  One of the channels could be used to sense the presence of external DC voltage, and the other to measure the battery voltage.  The connection details will depend on whether the MC13213 is supplied via a regulator, or not.  Suitable input voltage dividers will probably be required.
 
For the special case where the unregulated battery voltage is directly used as Vdd for the device, you will have to indirectly measure the battery voltage, since Vdd is the reference for the ATD.  You will need an external voltage reference device, perhaps 1.2 volts, and measure its voltage (relative to Vdd = battery).  Since you will probably need low power, except when a measurement is actually occurring, the external reference would be driven by an additional GP output from the MCU.
 
Regards,
Mac
 
0 Kudos
Reply

716 Views
rocco
Senior Contributor II
Hi, Mike:

Both Peg's and Mac's ideas are good, but here is yet another one that I like to use. It requires just an opto-coupler, a resistor, and timer firmware.

I put an AC opto-coupler on the AC side of the line, and allow its output to interrupt the microcontroller. I then setup a timer to interrupt every 12 milliseconds (long enough for both 60Hz and 50Hz) that checks that the opto-coupler interrupt has indeed occurred. If not, then the power has failed.

This allows me to know about a power-failure within a half cycle, enough to do a clean shutdown even without a battery. On some less critical systems, I test only on the timer overflow interrupt, which occurs about eight times a second.
0 Kudos
Reply

716 Views
strikecity
Contributor I
ummmm
Maybe I'm too simple minded, but couldn't an NPN transistor be used in conjunction with a GPIO pin with internal pullup enabled? Use your wall-provided DC rail to drive the base of the transistor, connect the emitter to gnd, and the collector will be pulled to gnd whenever wall power is present. When wall power goes away, the transistor will turn off, the internal pullup will bring the pin to +Vcc, and you're done. As peg mentioned, you need to ensure that the DC rail which drives the transistor base in this example cannot be back-fed by the battery. You could do that by sampling pre-regulator as she suggests, or you could use a schottky diode to prevent backfeeding. To me, one GPIO pin is simpler than 2 ATD's, 2 interrupt routines, etc.
0 Kudos
Reply

716 Views
peg
Senior Contributor IV
Hi Mike,
 
The simplest method is to sample the voltage before the final regulator, condition it and feed it to the MPU. It could be a digital or analogue signal here. The battery will not be feeding this part of the circuitry.
 
0 Kudos
Reply