Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. /** Reads the MSP430 supply voltage using the Analog to Digital Converter (ADC).
  2. On ez430 boards, this is approx. 3600mV
  3. @return Vcc supply voltage, in millivolts
  4. */
  5. unsigned int getVcc3()
  6. {
  7. ADC10CTL0 = SREF_1 + REFON + REF2_5V + ADC10ON + ADC10SHT_3; // use internal ref, turn on 2.5V ref, set samp time = 64 cycles
  8. ADC10CTL1 = INCH_11;
  9. delayMs(1); // Allow internal reference to stabilize
  10. ADC10CTL0 |= ENC + ADC10SC; // Enable conversions
  11. while (!(ADC10CTL0 & ADC10IFG)); // Conversion done?
  12. unsigned long temp = (ADC10MEM * 5000l); // Convert raw ADC value to millivolts
  13. return ((unsigned int) (temp / 1024l));
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement