Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Reading the supply voltage

$
0
0
Hi
I like to measure the Vcc. My question is which way is needs more energy. Making like http://fixituntilitsbroken.blogspot.ch/2011/08/reading-supply-voltage-using-msp430s.html or with a interrupt handler like the example below?
 
which way has less time influence on my startup rutine?
 
Has someone a example for the MSP430FR5739? That would be great.
 
Thanks, greetings manuel
 
 
#include <msp430.h>

unsigned int ADC_Result;

int main(void)
{
  volatile unsigned int i;

  WDTCTL = WDTPW+WDTHOLD;                   // Stop WDT
  P1DIR |= BIT0;                            // Set P1.0/LED to output direction
  
  // Configure ADC
  P1SEL1 |= BIT1; 
  P1SEL0 |= BIT1; 
  
  ADC10CTL0 |= ADC10SHT_2 + ADC10ON;        // ADC10ON, S&H=16 ADC clks
  ADC10CTL1 |= ADC10SHP;                    // ADCCLK = MODOSC; sampling timer
  ADC10CTL2 |= ADC10RES;                    // 10-bit conversion results
  ADC10MCTL0 |= ADC10INCH_1;                // A1 ADC input select; Vref=AVCC
  ADC10IE |= ADC10IE0;                      // Enable ADC conv complete interrupt
  
  for (;;)
  {
    __delay_cycles(5000);
    ADC10CTL0 |= ADC10ENC + ADC10SC;        // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE);        // LPM0, ADC10_ISR will force exit
    __no_operation();                       // For debug only
    if (ADC_Result < 0x1FF)
      P1OUT &= ~BIT0;                       // Clear P1.0 LED off
    else
      P1OUT |= BIT0;                        // Set P1.0 LED on
  }
}

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
  switch(__even_in_range(ADC10IV,12))
  {
    case  0: break;                          // No interrupt
    case  2: break;                          // conversion result overflow
    case  4: break;                          // conversion time overflow
    case  6: break;                          // ADC10HI
    case  8: break;                          // ADC10LO
    case 10: break;                          // ADC10IN
    case 12: ADC_Result = ADC10MEM0;         
             __bic_SR_register_on_exit(CPUOFF);                                              
             break;                          // Clear CPUOFF bit from 0(SR)                         
    default: break; 
  }  
}

 


Viewing all articles
Browse latest Browse all 2077

Trending Articles