Hi,
I am trying to measure battery voltage using the internal comparator B on MSP430F5529. I used the example code and set the reference voltage to negative terminal of Comp B at 2V and the supply connected to the positive terminal of Comp B, CB4 (P6.4). P1.6 is connected to CBOUT (output of comp B) and I probed P1.6 with saleae. I observed that the CBOUT goes high for 1.946V supply and stays high (I expected this to be low). For my application 50mV difference in measurement would make a huge impact.
How accurate is Comp B? Can anybody help me make this more accurate? If there's something missing can somebody please point me to that?
Code used:
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= BIT6; // P1.6 output direction
P1SEL |= BIT6; // Select CBOUT function on P1.6/CBOUT
// Setup ComparatorB
CBCTL0 |= CBIPEN + CBIPSEL_4; // Enable V+, input channel CB4
CBCTL1 |= CBPWRMD_1; // normal power mode
CBCTL2 |= CBRSEL; // VREF is applied to -terminal
CBCTL2 |= CBRS_3+CBREFL_2; // R-ladder off; Bandgap voltage amplifier ON and generates 2.0V reference
CBCTL3 |= BIT4; // Input Buffer Disable @P6.4/CB4
CBCTL1 |= CBON; // Turn On ComparatorB
__delay_cycles(75); // delay for the reference to settle
__bis_SR_register(LPM4_bits); // Enter LPM4
__no_operation(); // For debug
}
Thanks,