Using PIC Comparator to Monitor Battery [SOLVED]

Thread Starter

jpanhalt

Joined Jan 18, 2008
11,087
I plan to use an internal comparator on a PIC16F1789 (http://ww1.microchip.com/downloads/en/DeviceDoc/40001675C.pdf ) to monitor the battery. Battery will be a single cell Li-ion. LDO regulator is set for 3.3V. The signal will be when Vdd voltage fails out of regulation, e.g., drops to 3.1V. Here's my planned circuit (based on Microchip documents). Both Vref+ and OUTPUT will be internal connections..
1583593221150.png

My assumption is that register CMxCON0,5 should be clear, which sets CxOUT to internal only. Do the settings for the pin usually assigned to that comparator make a difference? Let's say I use comparator 1, which can output to RA4. I am assuming RA4 can be used for anything, including a digital i/o if needed. I will monitor the output status with register CMOUT,MCxOUT.

Second, do PIC comparators require pull-ups? That is, are they normally open collector?

Those questions could easily be answered in hardware, except I would need to take down my current project and rebuild it.

Regards, John
 
Last edited:

John P

Joined Oct 14, 2008
2,026
I believe you're correct about the comparator operation. And no, you don't need pull-ups, either on the comparator output that's internal to the chip, or on the external pin if you decide to use it. (And if you don't use an external output for the comparator, the pin is available for regular use.)

But you can monitor battery voltage without using any external components or extra input pins. You could use the power supply as the positive reference for the A/D converter, and measure the apparent voltage of the fixed voltage reference. So if the processor is receiving 3.3V, you'd be measuring 2.048V as a fraction of that. If the power supply dropped, you'd see the measurement of the fixed voltage get larger(!!) until it hit full scale when the power supply was down to 2.048V. If you want to go lower than that, you could measure 1.024V instead. I've never tried this, but it seems as if it should work.
 

Thread Starter

jpanhalt

Joined Jan 18, 2008
11,087
Thanks, John.

I had checked the pinouts table and saw SDA and SCL were "open drain;" whereas, the comparator outputs were not identified as OD. Still, I wanted to be sure.

Just polling CMOUT will be easy and only requires two resistors to set the level.

John
 
Top