Hi,
I have referred to the sample programs to configure msp430g2553 ADC10 and deduced the following code for my application as below.
My goal is to sample a pressure sensor that has a maximum sampling frequency of 100Hz.
1) However, I am unable to understand how to configure the sampling rate in MSP430.
2) Also, I have enabled the interrupt but while debugging , the interrupt function is not requested and hence the LED on P2.1 is not turned on.
I have measured the voltage at the P1.0 which is configured as my adc channel and it measure 0.5 volts. Converting that to a digital value I should be reading 256 .
Kindly guide me on configuring the ADC10 and as to what corrections I should make.
Thank you,
int Value=0;
//
// uint16_t avg_adc = 0;
// Function prototypes
void adc_Setup();
void adc_Sam();
#pragma vector=ADC10_VECTOR
void main()
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1 MHz
DCOCTL = CALDCO_1MHZ;
BCSCTL2|= (DIVS_3); //smclk=dc0=1 Mhz , SMCLK/8
P2DIR |= BIT1;
P2OUT &= ~BIT1;// configure P2.1 as output
// Fucntion call for adc_setup
while(1)
{
adc_Setup();
__delay_cycles(1000);
adc_Sam(); // Function call for adc_samp
// Add all the sampled data and divide by 10 to find average
// avg_adc = ((adc[0]+adc[1]+adc[2]+adc[3]+adc[4]+adc[5]+adc[6]+adc[7]+adc[8]+adc[9]) / 10);
}
}
// ADC10 interrupt service routine
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
Value=ADC10MEM;
if (Value< 200) // ADC10MEM = A1 > 0.2V?
P2OUT &= ~BIT1; // Clear P2.0 LED off
else
P1OUT |= BIT1; // Set P2.0 LED on
}
// ADC set-up function
void adc_Setup()
{
ADC10CTL1 = CONSEQ_0 + INCH_0 + SHS0 + ADC10DIV_7 + ADC10SSEL_3; ; // Repeat single channel, A0 ,+ ADC10SC + CLK/5 + SMCLK
ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE + REFON + ADC10SR + ~(REF2_5V)+SREF_0 ; // Sample & Hold Time + ADC10 ON + Interrupt Enable
ADC10DTC1 = 0x00; // 0 conversions
ADC10AE0 |= 0x01; // P1.0 ADC option select
__enable_interrupt();
__bis_SR_register(GIE);// Low Power Mode 0, ADC10_ISR
}
// ADC sample conversion function
void adc_Sam()
{
ADC10CTL0 &= ~ENC; // Disable Conversion
while (ADC10CTL1 & ADC10BUSY); // Wait if ADC10 busy
// Transfers data to next array (DTC auto increments address)
ADC10CTL0 |= ENC + ADC10SC; // Enable Conversion and conversion start
__bis_SR_register(GIE+CPUOFF);// Low Power Mode 0, ADC10_ISR
}