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.

Difficulty displaying sequential ADC sampling on MSP430FR5739

Other Parts Discussed in Thread: MSP-EXP430FR5739, MSP430FR5739

Hi All,

I am currently using the MSP-EXP430FR5739 board and trying to read the onboard thermistor on PIN 1.4 (A4) aswell as an external potentiometer connected on PIN 1.3 (A3), which I am trying to read both analog channels in sequence. I am using Timer A to generate an interrupt every second and measure the digital values from the ADC but instead I am getting junk values when displaying from the digital values on expression watch window.

Below is my code:

#include <msp430fr5739.h>

volatile long tempvalue, portvalue;

void main(void)

{

WDTCTL = WDTPW + WDTHOLD;     // Stop WDT

CSCTL0_H = 0xA5;                //unlocks CS register
CSCTL1 |= DCOFSEL0 + DCOFSEL1;                      //selects max clocks speed at low speed config
CSCTL2 = (SELA_1 + SELS_3 + SELM_3);              //set ACLK = VLO; SMCLK = DCO; MCLK = DCO
CSCTL3 = DIVA_0 + DIVS_0 +DIVM_0;                     //set all dividers to divide by 1
CSCTL5 &= ~(XT1OFFG);                                   //clears oscilator fault
CSCTL0_H = 0X01;                                        //lock CS register

TA0CTL = TASSEL_1 + MC_2;      //chooses ACLK as source & in continuous mode
TA0CCTL0 = CCIE;
TA0CCR0 = 12000;         //set CCR0 to 12000, which is every one second

PJDIR |= BIT0 + BIT1;             //set leds as outputs
PJOUT &= ~(BIT0 + BIT1);

P1SEL1 |= (BIT4 + BIT3);             //select P1.4 & P1.3 as an input A4 & A3
P1SEL0 |= (BIT4 + BIT3);
P2OUT |= BIT7;
P2DIR |= BIT7;                        //enable P2.7 as power voltage divider on experiential board

_delay_cycles(100);

ADC10CTL0 &= ~ADC10ENC;
ADC10CTL0 = ADC10SHT_5 | ADC10MSC | ADC10ON;                           // ADC10ON, S&H=96 ADC clks
ADC10CTL1 = ADC10SHP | ADC10SHS_0 | ADC10SSEL_0 | ADC10CONSEQ_1;     //sequnce of channels
ADC10CTL2 = ADC10RES;                                                                                // 10-bit conversion results
ADC10MCTL0 = ADC10SREF_0 | ADC10INCH_4;                                       // select; Vref=AVCC & sequence of channels from A4->A0
ADC10IE |= ADC10IE0;                                                                                        // Enable ADC conv complete interrupt

_delay_cycles(500);     //delay values for settings to settle

_bis_SR_register(GIE);

while(1){
}


}

#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
           ADC10CTL0 |= ADC10ENC | ADC10SC;      //sampling and enable conversion
           PJOUT |= BIT0;                                                    //LED on to indicate conversion
            _delay_cycles(500);

           ADC10CTL0 &= ~(ADC10ENC);                  //disable conversion

         ADC10MCTL0 = ADC10SREF_0 + ADC10INCH_4; //select channel 4 (A4) to be read
         tempvalue = ADC10MEM0;                              //read the conversion value
        TA0CCR0 +=4000;                                 
        PJOUT &= ~(BIT0);            //clear LED

        ADC10CTL0 |= ADC10ENC | ADC10SC;             //sampling and enable conversion
        PJOUT |= BIT1;                                                            //LED on to indicate conversion
        _delay_cycles(500);

         ADC10CTL0 &= ~(ADC10ENC);                             //disable conversion
        ADC10MCTL0 = ADC10SREF_0 + ADC10INCH_3;  //select channel 3 (A3) to be read
        portvalue = ADC10MEM0;
        TA0CCR0 +=8000;
        PJOUT &= ~(BIT1);               //clear LED
}

Can someone please guide me to where I might be mistaken or what is it that I am missing in this code.

Thanks,

Lubabalo

  • Sorry to say, but your ADC code is mess :)

    You shall look for ADC example code and analyze it. Generic ADC usage idea (from g2 series chip):

      ADC10CTL1 = INCH_11;                    // select input
      ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON; // configure ADC
      ADC10CTL0 |= ENC + ADC10SC;             // conversion start
      while (ADC10CTL1 & ADC10BUSY);          // ADC10BUSY? - wait for conversion end
      result = ADC10MEM;                     // read result
    

**Attention** This is a public forum