利用片内基准电压1.5V 反推电池电压,DVCC做参考电压怎么连接?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
zengbo wang 说:利用片内基准电压1.5V 反推电池电压,DVCC做参考电压怎么连接?
不需要外部连接。
//******************************************************************************
// MSP430FR413x Demo - ADC, Lo_Batt, Set P1.0 if AVcc < 2.50V
//
// Description: A single sample is made on A13 (Vref) with reference set to
// DVCC. Software sets ADC10SC to start sample and conversion
// - ADC10SC automatically cleared at EOC. Once conversion is completed, the
// following equation is used to calculate DVCC = (1023 * 1.5) / adcResult.
// if DVCC is < 2.5V, P1.0 set indicating a lo_Batt condition, else reset.
//
// MSP430FR4133
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// |A13 (Vref) P1.0|-->LED
//
// Ling Zhu
// Texas Instruments Inc.
// Mar 2017
// Built with IAR Embedded Workbench v6.50 & Code Composer Studio v7.0.1
//******************************************************************************
#include <msp430.h>
unsigned int adcResult; // Temporarily stores the ADC value
// that was read from ADCMEM0
int main(void)
{
volatile unsigned long dvccValue; // Calculated DVCC value
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
P1DIR |= BIT0; // Set P1.0 to output direction
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
// Configure ADC10
ADCCTL0 &= ~ADCENC; // Disable ADC
ADCCTL0 = ADCSHT_2 | ADCON; // ADCON, S&H=16 ADC clks
ADCCTL1 = ADCSHP; // ADCCLK = MODOSC; sampling timer
ADCCTL2 = ADCRES; // 10-bit conversion results
ADCIE = ADCIE0; // Enable ADC conv complete interrupt
ADCMCTL0 = ADCINCH_13 | ADCSREF_0; // A13 ADC input select = 1.5V Ref
// Vref = DVCC
// Configure reference module located in the PMM
PMMCTL0_H = PMMPW_H; // Unlock the PMM registers
PMMCTL2 |= INTREFEN; // Enable internal reference
while(!(PMMCTL2 & REFGENRDY)); // Poll till internal reference settles
while(1)
{
ADCCTL0 |= ADCENC | ADCSC; // Sampling and conversion start
__bis_SR_register(LPM0_bits | GIE); // Enter LPM0, ADC_ISR will force exit
__no_operation(); // For debug only
// To calculate DVCC, the following equation is used
// DVCC = (1023 * 1.5) / adcResult
// The following equation is modified to use only integers instead
// of using float. All results needs to be divided by 100 to obtain
// the final value.
// DVCC = (1023 * 150) / adcResult
dvccValue = ((unsigned long)1023 * (unsigned long)150) / (unsigned long) (adcResult);
if (dvccValue < 250) // DVCC < 2.50V ?
P1OUT |= BIT0; // Set P1.0 LED on
else
P1OUT &= ~BIT0; // Clear P1.0 LED off
}
}
// ADC interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC_VECTOR
__interrupt void ADC_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC_VECTOR))) ADC_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(ADCIV, ADCIV_ADCIFG))
{
case ADCIV_NONE:
break;
case ADCIV_ADCOVIFG:
break;
case ADCIV_ADCTOVIFG:
break;
case ADCIV_ADCHIIFG:
break;
case ADCIV_ADCLOIFG:
break;
case ADCIV_ADCINIFG:
break;
case ADCIV_ADCIFG:
adcResult = ADCMEM0; // Read ADC memory
__bic_SR_register_on_exit(LPM0_bits);// Exit from LPM
break;
default:
break;
}
}