Quantcast
Channel: MSP low-power microcontrollers
Viewing all articles
Browse latest Browse all 64870

Forum Post: RE: How to monitor battery voltage for MSP430F5528?

$
0
0
The output of COMP_B is a bit only i.e. the CBOUT bit. "1" means the voltage on V+ is greater than V-. Which code (line) produces the error "unable to read"? Unlike MSP430FR6972 , the reference output of MSP430F5528IRGC is pin-9 (VREF+) and the CB0 input is pin-1. So you have to manually short (connect) these two pins in your PCB board. For FR6972, they are the same pin, so they are already shorted. The idea is, the REFOUT at pin 9 is routed to input at CB0 as V- terminal. So, you have to check the mounted IC package and ensure the two pins are connected. Below is the code I used in a MSP430F5430 project to detect the rough battery voltage. I use C++ for this project. The variable status and voltage are member variables. prcm is another C++ class. prcm.delay_us() is just like __delay_cycles() but delays in micro-seconds. This example is exact what you need. You only have to adjust the pinout. void BatMon::update() { // Battery curve: // 0% 5% 10% 20% 100% // 2.0V 2.7V 2.85V 2.89V 2.95V // The idea is to output VREF+ at P5.0 which is connected with P6.5 as CB5 input of comparator. // Compare VCC (through resistor ladder) with VREF(1.5V). // V*(i+1)/32 > 1.5 // V*(i+1) > 48 // V > 48/(i+1) // // 48/(15+1) = 3.000 // 48/(16+1) = 2.823 // 48/(17+1) = 2.667 // 48/(18+1) = 2.526 // Enable COMP_B REFCTL0 |= REFOUT|REFON; // Enable REFOUT CBCTL0 = CBIMSEL_5|CBIMEN; // CB5 is set to V- terminal CBCTL1 = CBPWRMD_1|CBFDLY_2; CBCTL3 |= (1<<5); // Select CB5 function at P6.5 CBCTL1 |= CBON; // Enable COMPE_B int i = 15; for (; i<18; i++) { CBCTL2 = CBRS_1|(i<<8)|(i<<0); // CBREF(VCC) is set to V+ terminal prcm.delay_us(1); // Wait for filter circuit to be stable if (CBCTL1 & CBOUT) break; } // Disable COMP_B CBCTL1 &= ~CBON; // Disable COMP_B REFCTL0 &= ~REFOUT; // Don't clear REFON since ADC may be using it int mV; switch (i-15) { case 0: status = BAT_NEW; mV = 3000; break; case 1: status = BAT_GOOD; mV = 2823; break; case 2: status = BAT_OK; mV = 2667; break; case 3: status = BAT_LOW; mV = 2526; break; default: status = BAT_CRITICAL; mV = 2400; break; } voltage = (status<<12) | mV; }

Viewing all articles
Browse latest Browse all 64870

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>