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.

CCS/MSP430F5659: ADC 12 Problem in MSP430F5659

Part Number: MSP430F5659


Tool/software: Code Composer Studio

Hi,

i have some trouble with adc12 in MSP430F5659,i need to read adc reading without interrupt but the problem is that i didn't obtain result in memory register also execution waits for result load in memory(IFG waiting).I post my code below please solve this , hope you can solve it easily.

int main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
P6SEL |= BIT7; // Enable A/D channel inputs
ADC12CTL0 = ADC12ON; // Turn on ADC12, extend sampling time
// to avoid overflow of results
ADC12CTL1 = ADC12CONSEQ_3+ADC12SSEL_3; // Use sampling timer, repeated sequence
ADC12CTL2=ADC12RES_2;
ADC12MCTL7 = ADC12INCH_7; // ref+=AVcc, channel = A0

ADC12CTL0 |= ADC12ENC; // Enable conversions
ADC12CTL0 |= ADC12SC; // Start convn - software trigger

while (1)
{
ADC12CTL0 |= ADC12SC; // Start conversion
while (!(ADC12IFG & ADC12IFG7));
result=ADC12MEM7;
__no_operation(); // SET BREAKPOINT HERE

}

}

 

  • Hi Aju,
    Your getting stuck in the while loop, because the adc is waiting for another rising edge of SAMPCON to start each of the next channels, which in your configuration is directly controlled by ADC12SC. To fix this set ADC12SHP and ADC12MSC. With that done, you should need the second ADC12SC, but it's not hurting anything either.

    Also, you are doing a repeated sequence of channels and only measuring 1, which will cause delays while the ADC scans through the other channels. You might want to change to ADCCONSEQ_2, for repeated single channel. Then you either need to set CSTARTADD for MCTL7 or change INCH_7 to store to MCTL0.
  • Hi Cameron P. LaFollette,
    Thanks for your support.
    I changed my code as per your opinion but still it wait in step while (!(ADC12IFG & ADC12IFG0)) .I changed this to while (!(ADC12IFG & ADC12IFG7)); but still code wait there .Is there anything wrong in my code,help me to correct this.
    int main(void)
    {
    WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
    P6SEL |=BIT7;
    ADC12CTL0=ADC12ON+ADC12MSC+ADC12SHT0_8;
    ADC12CTL0|=ADC12SC;
    ADC12CTL1=ADC12CONSEQ_2+ADC12SSEL_3;
    ADC12CTL2=ADC12RES_2;
    ADC12MCTL0=ADC12INCH_7; //

    ADC12CTL0 |=ADC12ENC;


    while (1)
    {
    ADC12CTL0 |= ADC12SC; // Start conversion
    while (!(ADC12IFG & ADC12IFG0));
    result=ADC12MEM0;
    // sprintf(result_ch,"Adc result= %ld\n\r",result);
    // send_string(result_ch);
    __no_operation(); // SET BREAKPOINT HERE

    }

    }
  • Hi Aju,

    You still need to set your ADC12SHP bit. Try that and let me know how it works.

  • Hi Cameron P. LaFollette,
    Thanks for your support,i obtain the code correctly.I posted it below which may help others .


    AJU S


    void ADC_Init()
    {
    P7SEL|= 0x20; // Enable A/D channel inputs
    ADC12CTL0 = ADC12ON+ADC12MSC+ADC12SHT0_8; // Turn on ADC12, extend sampling time
    ADC12CTL1 = ADC12SHP+ADC12CONSEQ_2; // Use sampling timer, repeated sequence
    ADC12MCTL0 = ADC12INCH_14; // ref+=AVcc, channel = A0
    ADC12CTL0 |= ADC12ENC; // Enable conversions
    ADC12CTL0 |= ADC12SC; // Start convn - software trigger
    }
    int ADC_Read()
    {
    while (!(ADC12IFG & ADC12IFG0));
    return(ADC12MEM0);
    }

**Attention** This is a public forum