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 2 ADC12MEM Registers

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,

I dont know how to use  CSTARTADD and ADC12CONSEQ_3(what should be the value of  "adc12conseq" as am using 2 channels from p6.0 and p6.4)

please assist me regarding my doubts and see my code ...........as i DINT GET PROPER SUPPORT inmy old thread so am openig new thread........

and no where in texas standard programs it is not given how to use CSTARTADD.please see the code and do some modification.

#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
}

thank you.

  • HI,

    I modified my code but not includes CSTARTADD , and I want to use two channels for ADC input and am storing it to ADC12MEM0  for channel 0 (p6.0) AND ADC12MEM4 for channel 4(p6.4) .I am using P6.0 as channel 1st, and P6.4 as channel 2nd,

    see it and please tell me where should i wish to change the code for adding CSTART.

    #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

     ADC12MCTL4 = 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 (ADC12MEM4 <= 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 Mohammad!

    The code examples contain one example that samples two channels:

    • MSP430F55xx_adc_08.c              ADC12, Using A8 and A9 Ext Channels for Conversion

    Maybe building your code based on this example will help.

    Dennis

  • Hi Dennis,

    I changed the code,am using CHANNEL 0 n CHANNEL 4,with ADC12MCTL0 and ADC12MCTL4, and ADC12MEM0(from channel 0)   n ADC12MEM4(from channel 4).please see and let me know the result wheather it is right or not.

    #include <msp430.h>

    int main(void)

    {

     WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

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

     ADC12CTL1 = ADC12SHP + ADC12CONSEQ_1;                     // Use sampling timer

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

     ADC12MCTL4 = ADC12INCH_4 + ADC12EOS;                 // 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 (ADC12MEM4 <= 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 Mohammad,

    could you please edit your post and insert source code using the Syntaxhighlighter that is available in rich formatting mode? It is the </> symbol in the task bar. This makes code easier to read and you will have line numbers one can refer to.

    Dennis

  • #include <msp430.h>
    
    int main(void)
    
    {
    
     WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
    
     ADC12CTL0 = ADC12SHT02 + ADC12ON + ADC12MSC;         // Sampling time, ADC12 on
    
     ADC12CTL1 = ADC12SHP + ADC12CONSEQ_1;                     // Use sampling timer
    
     ADC12MCTL0 = ADC12INCH_0;                 // ref+=AVcc, channel = A0
    
     ADC12MCTL4 = ADC12INCH_4 + ADC12EOS;                 // 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 (ADC12MEM4 <= 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
    
     }

  • Thanks!
    And now what does not work? Is the ADC result not as expected? Does the interrupt not fire at all?
  • Please note that input channels are independent from the memory register numbers; you should use MCTL0/MCTL1 and MEM0/MEM1.
  • Hi

    @Clemens............,

    Please note that input channels are independent from the memory register numbers; you should use MCTL0/MCTL1 and MEM0/MEM1.

    --->>In my code  am using the lines 

    ADC12MCTL0 = ADC12INCH_0;                 // ref+=AVcc, channel = A0
     ADC12MCTL4 = ADC12INCH_4 + ADC12EOS;
    @Dennis..............,
    And now what does not work? Is the ADC result not as expected? Does the interrupt not fire at all?
    --->>>Is my code is right,can i use this code for using channel 0 and channel 4 and ADC12MEM0 n ADC12MEM4 with ADC12MCTL0 nADC12MCTL4 respectively.along with that what i have using ADC12CONSEQ_1 and ADC12EOS  is in right manner..................Finally i wanted to ask IS MY CODE IS RIGHT?
    thank you.

     

  • With CSTARTADD = 0 and EOS in MCTL4, the ADC will do conversions according to MCTL0, MCTL1, MCTL2, MCTL3, and MCTL4, from inputs A0, A0, A0, A0, and A4. This is probably not what you want.

    The only bit set in the IE register is bit 4, so you should get an interrupt after MEM4 has been written.
  • Hi Clemens,
    You are right,I want only channel 0 and channel 4,so what to do with CSTARTADD.
    Thank you.
  • Nothing. Just configure MCTL0 to use A0 and MCTL1 to use A4.
  • Hi Clemens,

    see the code ,i did what you advised me and let me know for changes.

    thank you.

    #include <msp430.h>
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      ADC12CTL0 = ADC12SHT02 + ADC12ON + ADC12MSC;         // Sampling time, ADC12 on
      ADC12CTL1 = ADC12SHP + ADC12CONSEQ_1;                     // Use sampling timer
    
      ADC12MCTL0 = ADC12INCH_0;                 // ref+=AVcc, channel = A0
      ADC12MCTL1 = ADC12INCH_4 + ADC12EOS;                 // 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
    
      }
    
    
    

  • The line "ADC12IE = 0x01;" is meaningless because this register gets overwritten in the next line.

    But why are you dumping the code here? Does it work, or not?
  • But am using two channels ,so ADC12IE = 0x01 for channel 0 and ADC12IE = BIT4 for channel 4.So i want interrupt from both the channels.
    If write only ADC12IE = BIT4,will it takes the signals from both the channels ie channel 0 and channel 4 and is it storesin ADC12MEM0 n ADC12MEM1.
  • If you want an interrupt after both values have been converted, you should set only the IE bit for the last register. If you set both IE bits, you get two interrupts.

    And the interrupt handler must clear the IFG bit.
  • yes Clemens,
    i am taking two anolog signals from p6.0 and p6.4,so i want two interrupts and two seperate data wish two to store in ADCMEM0 n ADC12MEM1.
    what to do...
    than you
  • You will get two independent data values with one interrupt. The interrupt will fire after the second one was converted. Grab the values from MEM0 and MEM1 for the two channels. Why having more interrupts than required - the ADC module will work in the background.
  • #include <msp430.h>
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      ADC12CTL0 = ADC12SHT02 + ADC12ON + ADC12MSC;         // Sampling time, ADC12 on
      ADC12CTL1 = ADC12SHP + ADC12CONSEQ_1;                     // Use sampling timer
    
      ADC12MCTL0 = ADC12INCH_0;                 // ref+=AVcc, channel = A0
      ADC12MCTL1 = ADC12INCH_4 + ADC12EOS;                 // ref+=AVcc, channel = A1
    
      ADC12IE = 0x01;                           // Enable interrupt
      
    
      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
    
      }

    fine Dennis, i change my code from your advise see is it right or not...

  • Mohammad,

    why don't you simply first test if your code behaves as expected? Reading over someone's code and deciding if everything is correct or not isn't that easy. Of course sometimes you can see big mistakes immediately, but running a program inside one's mind is difficult. When code does not work, it often is a very little fault (one wrong bit in a configuration) that you read over easily. So run your code and debug it.

    Dennis

**Attention** This is a public forum