two cases only low voltage( Low battery will turn a segment ON at the LCD) and High voltage( battery full lights up another segment
On at LCD to indicate)
The corresponding values for :high voltage=3V ...at divider= 1.5 V and ADC value=1.5/0.000614= 2459 (0x99C in hex)
: Low voltage= 2.5 V at divide = 1,25V and ADC value=1.25/0.000614=2049(0x801 in hex)
Hello, I m using MSP430FG4618 experiments board.... I want to display the status of the battery ...using a LCD ...which is configured....to display a full battery sign when BAT-FULL command and Low Battery sign when BAT_LOW command...these are defined in LCD_defs.h in the code below.
Basically i want to use ADC reference and internal voltage divider to monitor the battery.... The code I have written below..is supposed to do that... but it is not working ....whatever....happens the battery sign doesnt respond....is the approach adopted alright?????
#include <msp430fg4618.h>
#include <stdbool.h>
#include "LCD_defs.h"
void Single_Measure(unsigned int);
void Single_Measure_REF(unsigned int, unsigned int);
unsigned int ADCValue; // Measured ADC Value
unsigned int i;
bool ADCDone; // ADC Done flag
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
__bis_SR_register(GIE);
//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; // VLCD = 3,44 V
ADCDone = false;
Single_Measure_REF(INCH_11, REF2_5V);
while(1) {
if (ADCDone) {
ADCDone = 0;
i = ADCValue;
if (i>=0x99C){ // if VCC>=2.5 ( for simplicity i will display any value above 2.5 as battery full
//any value less than 2.5 will be battery low
BAT_FULL;
} else
BAT_LOW;
}// Set breakpoint here
}
}
/// BATTery INDICATION ROUTINE
void Single_Measure_REF(unsigned int chan, unsigned int ref) {
ADC12CTL0 &= ~ENC; // Disable ADC conversion
ADC12CTL0 = SHT0_2 + REFON + ADC12ON +ref ;
ADC12MCTL0=SREF_1+chan; // selecting reference and channel 11(( Avcc-Avss)/2)
__delay_cycles(128); // Delay to allow Ref to settle
ADC12IE=0x01;
// Use reference,
// ADC12CTL0 = SREF_1 + REFON + ADC12ON + ref + ADC12IE; // 16 clock ticks, internal reference on
ADC12CTL1 = ADC12SSEL_3;
__enable_interrupt(); // ADC On, enable ADC interrupt, Internal = 'ref'
// Set 'chan', SMCLK
ADC12CTL0 |= ENC + ADC12SC;
// Enable and start conversion
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR(void) {
//ADCValue =(void(*)())& ADC12MEM;
ADCValue =(unsigned int)ADC12MEM0; // Saves measured value.
ADCDone = 1; // Sets flag for main loop.
ADC12CTL0 &= ~ENC; // Disable ADC conversion
}
cheers any help will be appreciated..!!
This post has been edited by crastonhill: 18 February 2012 - 12:52 PM

New Topic/Question
Reply



MultiQuote



|