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.

msp430f5529 with ADC12MEM

Dear sir,

I want to use two channels for ADC input and am storing it to ADC12MEM0  for channel 0 (p6.0) AND ADC12MEM1 for channel 4(p6.4) .I am using P6.0 as channel 1, and P6.4 as channel 2,

please see my code and let me know the thing what am doing is right or not.

#include <msp430.h>

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer

ADC12IE = 0x01; // Enable interrupt for channel 0

ADC12IE = BIT4;// Enable interrupt for channel 4


ADC12CTL0 |= ADC12ENC;


P6SEL |= 0x01; // P6.0 ADC option select

P6SEL |= BIT4;// P6.4 ADC option select

P6DIR |= BIT2 | BIT3 | BIT1; //for taking input for dc driver       doing some project on this pins
P4DIR |= BIT7; //for green led p4.7 output
P1DIR |= 0x01; //for red led P1.0 output

while (1)
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion

__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
__no_operation(); // For debugger
}
}


#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
// Vector 6: ADC12IFG0
if (ADC12MEM0 >= 0x7ff){ // ADC12MEM = A0 > 0.5AVcc?

if (ADC12MEM1 <= 0x0ff){ //CAN I DO LIKE THIS BY TAKING THE SIGNAL FROM P6.4 AND STORE IT IN ADC12MEM1

P4OUT |= BIT7; // P1.0 = 0

P1OUT &=~ BIT0;

P6OUT &=~ BIT1;
P6OUT &=~ BIT2;
P6OUT &=~ BIT3;

}

else{

P1OUT |= BIT0; // P1.0 = 1
P4OUT &=~ BIT7;

P6OUT |= BIT1;
P6OUT |= BIT2;
P6OUT &=~ BIT3;

}

__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU

}

  • To set a single bit, use "|=". Using "=" clears all the other bits in the register.

    You did not configure the ADC12MCTLx registers and the CSTARTADD and CONSEQ fields.
  • Hi Clemens,

    I ll change the code to,is this ok....

    #include <msp430.h>

    int main(void)

    {

    WDTCTL = WDTPW + WDTHOLD; // Stop WDT

    ADC12CTL0 = ADC12SHT02 + ADC12ON + ADC12MSC; // Sampling time, ADC12 on

    ADC12CTL1 = ADC12SHP+ADC12CONSEQ_3;       // Use sampling timer, repeated sequence

    ADC12MCTL0 = ADC12INCH_0;                 // ref+=AVcc, channel = A0

    ADC12MCTL1 = ADC12INCH_4;                 // ref+=AVcc, channel = A1

    ADC12IE = 0x01; // Enable interrupt for channel 0

    ADC12IE = BIT4;// Enable interrupt for channel 4

    ADC12CTL0 |= ADC12ENC;

    P6SEL |= 0x01; // P6.0 ADC option select

    P6SEL |= BIT4;// P6.4 ADC option select

    P6DIR |= BIT2 | BIT3 | BIT1; //for taking input for dc driver       doing some project on this pins

    P4DIR |= BIT7; //for green led p4.7 output

    P1DIR |= 0x01; //for red led P1.0 output

    while (1)

    {

    ADC12CTL0 |= ADC12SC; // Start sampling/conversion

    __bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit

    __no_operation(); // For debugger

    }

    }

    #pragma vector = ADC12_VECTOR

    __interrupt void ADC12_ISR(void)

    {

    // Vector 6: ADC12IFG0

    if (ADC12MEM0 >= 0x7ff){ // ADC12MEM = A0 > 0.5AVcc?

    if (ADC12MEM1 <= 0x0ff){ //CAN I DO LIKE THIS BY TAKING THE SIGNAL FROM P6.4 AND STORE IT IN ADC12MEM1

    P4OUT |= BIT7; // P1.0 = 0

    P1OUT &=~ BIT0;

    P6OUT &=~ BIT1;

    P6OUT &=~ BIT2;

    P6OUT &=~ BIT3;

    }

    else{

    P1OUT |= BIT0; // P1.0 = 1

    P4OUT &=~ BIT7;

    P6OUT |= BIT1;

    P6OUT |= BIT2;

    P6OUT &=~ BIT3;

    }

    __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU

    }

  • MOHAMMAD NASEER M N said:
    I ll change the code to,is this ok....

    Does it work as expected?

  • Hi Dennis,

    No,it wont work.So am asking for where to change in the code and requesting you to correct the code .

    thank you.
  • Then please narrow down the problem you have. What exactly dows not work? Did you have a look at the code examples from TI? They show you the basic configuration. You can download them on the product webpage for your processor.

  • Hi,

    I want to use P6.4 as one of the analog input and i need to take this signal from channel say channel 4,then i need to store it in ADC12MEM1.

    So is my below code works for the same .

    thank you.

    #include <msp430.h>

    int main(void)

    {

     WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

     ADC12CTL0 = ADC12SHT02 + ADC12ON + ADC12MSC;         // Sampling time, ADC12 on

     ADC12CTL1 = ADC12SHP + ADC12CONSEQ_3;                     // Use sampling timer

     ADC12MCTL0 = ADC12INCH_0;                 // ref+=AVcc, channel = A0

     ADC12MCTL1 = ADC12INCH_4;                 // ref+=AVcc, channel = A1

     ADC12IE = 0x01;                           // Enable interrupt

     ADC12IE = BIT4;// Enable interrupt for channel 4

     ADC12CTL0 |= ADC12ENC;

     P6SEL |= 0x01;                            // P6.0 ADC option select

     P6SEL |= BIT4;// P6.4 ADC option select

     P6DIR |= BIT2 | BIT3 | BIT1;                     //for taking input for dc driver

     P4DIR |= BIT7; //for green led p4.7 output

     P1DIR |= 0x01;                            //for red led P1.0 output

     while (1)

     {

       ADC12CTL0 |= ADC12SC;                   // Start sampling/conversion

       __bis_SR_register(LPM0_bits + GIE);     // LPM0, ADC12_ISR will force exit

       __no_operation();                       // For debugger

     }

    }

    #pragma vector = ADC12_VECTOR

    __interrupt void ADC12_ISR(void)

    {

                                      // Vector  6:  ADC12IFG0

       if (ADC12MEM0 >= 0x7ff){                 // ADC12MEM = A0 > 0.5AVcc?

        if (ADC12MEM1 <= 0x0ff){

         P4OUT |= BIT7;                       // P1.0 = 0

             P1OUT &=~ BIT0;

             P6OUT &=~ BIT1;

             P6OUT &=~ BIT2;

             P6OUT &=~ BIT3;

        /* P1OUT |= BIT0;                        // P1.0 = 1

         P4OUT &=~ BIT7;

         P6OUT |= BIT1;

         P6OUT |= BIT2;

         P6OUT &=~ BIT3;*/

        }

       }

       else{

         P1OUT |= BIT0;                        // P1.0 = 1

             P4OUT &=~ BIT7;

             P6OUT |= BIT1;

             P6OUT |= BIT2;

             P6OUT &=~ BIT3;

         /*P4OUT |= BIT7;                       // P1.0 = 0

         P1OUT &=~ BIT0;

         P6OUT &=~ BIT1;

         P6OUT &=~ BIT2;

         P6OUT &=~ BIT3;*/

       }

       __bic_SR_register_on_exit(LPM0_bits);   // Exit active CPU

     }

  • Hi,

    waiting for your reply.

    thank you

  • Hi,
    waiting for your reply

    thank you.
  • I see no CSTARTADD.

    (And to insert code, use the "Insert Code" button.)
  • Sorry i dint get you,can you please explain where should i do changes in code.
    thank you.
  • Sorry, CSTARTADD is not needed; the default value of zero is OK here.

    But you also need to set EOS for the last register.

  • HI,
    I dont knw how to use CSTARTADD and where and what data to be store in that.please assist me in writting .
    thank you.

**Attention** This is a public forum