Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 6 months ago.
Detect charging
Hello,
I have a KL25z mounted on a custom PCB which is powered by a small Lipo battery. With a USB cable I can charge this battery (using a MCP73831). The USB is also connected to the KL25Z via the VREGIN, USB0_DM and USB0_DP. Could I use any of those ports to detect if I'm charging my battery or if I should operate normally? I wanted to do something like the following:
#include "mbed.h" AnalogIn _Vusb( VREGIN ); // error: VREGIN is undefined AnalogIn _Vbatt( PTC2 ); Serial pc( USBTX, USBRX ); int main(){ while(1){ pc.printf( "Vusb = %.2f V; Vbatt = %.2f\r\n", _Vusb->read() * 5.0, _Vbatt.read() * 3.3 ); wait( 0.5 ); } }
However, VREGIN, USB0_DM and USB0_DP are not recognized. How could I detect if the board is powered by USB and my battery is charging?
Thank you very much,
Bob
1 Answer
7 years, 6 months ago.
Hi Bob. Review the details of the MCP73831 datasheet and note the STAT pin. Recommend to consider to use the STAT pin and a free GPIO pin on your KL25z to monitor the status of the LiPo charging. During a charge, this pin should be LOW. Upon completion, the pin should be high impedance (tristate / Hi-z) so be sure there is a pull-up resistor to offer the logic high.
MCP73831 Datasheet: https://www.sparkfun.com/datasheets/Prototyping/Batteries/MCP73831T.pdf
See section 3.3 and also Figure 4-1 for details on STAT pin during operation.
Quote:
3.3 Charge Status Output (STAT) STAT is an output for connection to an LED for charge status indication. Alternatively, a pull-up resistor can be applied for interfacing to a host microcontroller. STAT is a tri-state logic output on the MCP73831
If you have a LED on the STAT pin, remove the LED from the circuit and insert a 4.7k -> 47k or similar resistor value onto STAT pin and 3V3 power supply. Now the STAT pin should be LOW during the LiPo charge and HIGH otherwise. Proceed to mate this STAT pin onto a free GPIO pin of your mbed board.