Hi i am using a MSP430FG4618 experiments board. I have this program....to display battery status on the LCD screen. I wanted to ask whether
the way i m doing the ADC conversion is correct or not. So initially what happens I choose the internal voltage divider using ADC12MCTL0
Running on a 3V battery just now. So for example the value at divide for 3v will be 1.5 v ..which can be then converted to an ADC value(the
variable defined as unsigned ADC Value) .Now considering this value is copied to ADC12MEM0.I perform some conversion in the
interrupt routine in the ISR to convert it back into voltage( BAT_VOLT variable defined) . Multiple conversions are enabled by setting MSC.
This program is not working....The battery symbol for full battery is displayed...However, when voltage falls below 2.5 the symbol doesnt
change.(SEE ISR ) ..BAT_full and BAT_50 are variables defined in LCD_defs.h...just to dispaly the LCDMEM values on screen.
Can anyone help with this??? does this code makes sense??
///////////////////////////////////////////////////////////CODE START/////////////////////////////////////////////////////////
#include <msp430fg4618.h>
#include <stdint.h>
#include<intrinsics.h> //For add_bcd_short function to be used
#include "LCD_defs.h" // P7_A1...P1_A0....all defined here
unsigned int ADCValue;
double BAT_VOLT;
void LCD_all_off(void);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
//LCD_A S0-S21 configuration
LCDAPCTL0 = LCDS24 | LCDS20 | LCDS16 | LCDS12 | LCDS8 | LCDS4;
// LCD_A configuration
LCDACTL = LCDFREQ_192 | LCD4MUX | LCDSON | LCDON; // (ACLK = 32768)/192, 4-mux LCD, LCD_A on, Segments on
LCDAVCTL0 = LCDCPEN; // Charge pump enable
LCDAVCTL1 = VLCD_3_44;
LCD_all_off();
// ADC CONFIGURATION
P6SEL |= 0x01; // Enable A/D channel A0
//ADC12CTL0 = ADC12ON + SHT0_8 + MSC; // Turn on ADC12, set sampling time
ADC12CTL0 = REFON + REF2_5V + ADC12ON + SHT0_8+ MSC;//reference used 2.5 v , MSC= multiple sample and conversion starts another
//conversions as one ends// SHT0_8 ..256 cycles of clock
ADC12CTL1 = SHP + CONSEQ_2; // Use sampling timer, set mode//repeat single channel conversions
ADC12IE = 0x01; // Enable ADC12IFG.0
ADC12CTL0 |= ENC; // Enable conversions
ADC12MCTL0=SREF_1+INCH_11; // selecting reference and channel 11(( Avcc-Avss)/2)
__enable_interrupt(); // Enable interrupts
ADC12CTL0 |= ADC12SC; // Start conversion
for(;;){
__bis_SR_register(LPM3_bits + GIE);
}
}
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
ADCValue= ADC12MEM0; // Move conversion result, IFG is cleared
BAT_VOLT= (double)((ADCValue)*(2.5/4095)) ; //coverting the value from ADC into voltage
if (BAT_VOLT>=1.25){ //using voltage divide 2.5/2 =1.25 (not sure abt this bit??)
BAT_FULL; // Any battery value above 2.5 gives symbol battery full
}else{
BAT_50;} //any battery value below 2.5 gives low battery symbol(BAT_50 or BAT_LOW...same thing defined)
}
//LCD clear routine
void LCD_all_off(void)
{
LCDM2 = 0x00;
LCDM3 = 0x00;
LCDM4 = 0x00;
LCDM5 = 0x00;
LCDM6 = 0x00;
LCDM7 = 0x00;
LCDM8 = 0x00;
LCDM9 = 0x00;
LCDM10 = 0x00;
LCDM11 = 0x00;
LCDM12 = 0x00;
LCDM13 = 0x00;
}