Created
January 16, 2013 16:30
-
-
Save ossicode/4548592 to your computer and use it in GitHub Desktop.
MSP430F1611 ADC12 Test OK main.c file for sharing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ossiobc.h" | |
#include "adc12.h" | |
/* | |
* main.c | |
*/ | |
uint16_t adcValueVccRef[7]={0}; | |
uint16_t adcValueIntRef[7]={0}; | |
uint16_t adcValueExtRef[7]={0}; | |
int main(void) { | |
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer | |
// to check timing | |
P6DIR |= BIT0; // P6.0 output | |
P6OUT |= BIT0; | |
clock_setup(); | |
uint8_t systemClock; | |
systemClock = clock_getMode(); | |
if(systemClock == CLOCK_XT2_LFXT1) | |
{ | |
clock_dividerSetup(MCLK_DIVIDED_BY_1, SMCLK_DIVIDED_BY_1, ACLK_DIVIDED_BY_1); | |
} | |
else if(systemClock == CLOCK_DCO_LFXT1) | |
{ | |
clock_dividerSetup(MCLK_DIVIDED_BY_1, SMCLK_DIVIDED_BY_1, ACLK_DIVIDED_BY_1); | |
} | |
adc12_portSetup(ADC12_PIN_6_1+ADC12_PIN_6_2+ADC12_PIN_6_3+ADC12_PIN_6_4+ADC12_PIN_6_5+ADC12_PIN_6_6+ADC12_PIN_6_7); | |
adc12_init(ADC12_CLOCKSOURCE_SMCLK, ADC12_CLOCKDIVIDER_8, ADC12_CYCLEHOLD_16_CYCLES); | |
while(1) | |
{ | |
volatile uint8_t i; | |
_NOP(); | |
// Vref = VCC | |
adc12_setVolReference(ADC12_REF_VCC_VSS); | |
for (i = 0; i < 7;i++) | |
{ | |
adcValueVccRef[i] = adc12_readChannel(i+1); | |
// Convert the value to 0 ~ 3300 mV (3300/2^12 = 0.8056) | |
adcValueVccRef[i] = (uint16_t)(0.8056 * adcValueVccRef[i]); | |
} | |
// Vref = Internal Ref 2.5V | |
adc12_setVolReference(ADC12_REF_VREF_VSS); | |
for (i = 0; i < 7;i++) | |
{ | |
adcValueIntRef[i] = adc12_readChannel(i+1); | |
// Convert the value to 0 ~ 2500 mV (2500/2^12 = 0.6103) | |
adcValueIntRef[i] = (uint16_t)(0.6103 * adcValueIntRef[i]); | |
} | |
// When we use internal reference, | |
// Make sure you turn it off to save power | |
adc12_offInternalVolReference(); | |
// Vref = Internal Ref 1.25V | |
adc12_setVolReference(ADC12_REF_V_EREF_VSS); | |
for (i = 0; i < 7;i++) | |
{ | |
adcValueExtRef[i] = adc12_readChannel(i+1); | |
// Convert the value to 0 ~ 1250 mV (2500/2^12 = 0.3051) | |
adcValueExtRef[i] = (uint16_t)(0.3051 * adcValueExtRef[i]); | |
} | |
_NOP(); | |
// LPM3; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment