Msp430g2533 lm35

Discussion in 'Embedded Systems and Microcontrollers' started by ivaninspace, Dec 8, 2013.

  1. ivaninspace

    Thread Starter New Member

    Jul 28, 2013
    10
    0
    Hello I am using
    Code composer 5.1
    Microcontroller: MSP430G2533
    LM35
    Using Putty for m hyperterminal

    Question: I can't seem to get the data of two LM35's to display on my hyperterminal? The follow code is the best I've been able to think of.

    The code is based on the following website.
    http://karve.in/?p=597#comment-507

    code:
    Code ( (Unknown Language)):
    1.  
    2. #include <msp430g2553.h>
    3. #include <stdbool.h>
    4. ////////////////Defines////////////////
    5. #define LED1        BIT6
    6. #define LED0        BIT0
    7. #define Error       BIT0
    8. #define GND         BIT4
    9. #define DAT         BIT5
    10. #define DAT2        BIT7////////////////////////////////////////////////////new
    11. #define VCC         BIT0 //port P2.0
    12. char buffer[4];
    13. float temp;
    14. float temp2;
    15. int n_temp,r_temp;
    16.  
    17. int x=0,y=0;
    18.  
    19. ////////////////Function Protos////////////////
    20. void TX(char *tx_message);
    21. static char *i2a(unsigned i, char *a, unsigned r);
    22. char *itoa(int i, char *a, int r);
    23. void ADC_init(void);
    24.  
    25. static char *i2a(unsigned i, char *a, unsigned r)
    26. {
    27.     if (i/r > 0) a = i2a(i/r,a,r);
    28.     *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
    29.     return a+1;
    30. }
    31.  
    32. char *itoa(int i, char *a, int r)
    33. {
    34.     if ((r < 2) || (r > 36)) r = 10;
    35.     if (i < 0)
    36.     {
    37.         *a = '-';
    38.         *i2a(-(unsigned)i,a+1,r) = 0;
    39.     }
    40.     else *i2a(i,a,r) = 0;
    41.     return a;
    42. }
    43.  
    44. void TX(char *tx_message)
    45. {
    46.     unsigned int i=0; //Define end of string loop int
    47.     char *message; // message variable
    48.     unsigned int message_num; // define ascii int version variable
    49.     message = tx_message; // move tx_message into message
    50.     while(1)
    51.     {
    52.         if(message[i]==0) // If end of input string is reached, break loop.
    53.         {break;}
    54.         message_num = (int)message[i]; //Cast string char into a int variable
    55.         UCA0TXBUF = message_num; // write INT to TX buffer
    56.         i++; // increase string index
    57.         __delay_cycles(10000); //transmission delay
    58.         if(i>50) //prevent infinite transmit
    59.         {
    60.             P1OUT |= Error;
    61.             break;
    62.         }
    63.     } // End TX Main While Loop
    64. } // End TX Function
    65.  
    66. ///////////////////////////////////////////////////////////////////////////////////////////////////
    67. void ADC_init()
    68. {
    69.     /* Configure ADC  Channel */
    70.     ADC10CTL1 = INCH_5 + ADC10DIV_3 ;         // Channel 5, ADC10CLK/4
    71.     ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;  //Vcc & Vss as reference
    72.     ADC10AE0 |= BIT5;                         //P1.5 ADC option
    73. }
    74. ///////////////////////////////////////////////////////////////////////////////////////////////////
    75. void ADC2_init()
    76. {
    77.     /* Configure ADC  Channel */
    78.     ADC10CTL1 = INCH_7 + ADC10DIV_3 ;         // Channel 7, ADC10CLK/4
    79.     ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;  //Vcc & Vss as reference
    80.     ADC10AE0 |= BIT7;                         //P1.7 ADC option
    81. }
    82. ///////////////////////////////////////////////////////////////////////////////////////////////////
    83.  
    84.  
    85.  
    86. ////////////////////////////////MAIN PROGRAM LOOP//////////////////////////////////////////////////
    87.  
    88. void main(void)
    89. {
    90.  
    91.  
    92.     WDTCTL = WDTPW + WDTHOLD;         // Stop WDT
    93.     BCSCTL1 = CALBC1_1MHZ;            // Set DCO to 1MHz
    94.     DCOCTL = CALDCO_1MHZ;
    95.     ////////////////USCI setup////////////////
    96.     P1SEL = BIT1 + BIT2;            // Set P1.1 to RXD and P1.2 to TXD
    97.     P1SEL2 = BIT1 + BIT2;            //
    98.     UCA0CTL1 |= UCSSEL_2;            // Have USCI use SMCLK AKA 1MHz main CLK
    99.     UCA0BR0 = 104;                  // Baud: 9600, N= CLK/Baud, N= 10^6 / 9600
    100.     UCA0BR1 = 0;                  // Set upper half of baud select to 0
    101.     UCA0MCTL = UCBRS_1;               // Modulation UCBRSx = 1
    102.     UCA0CTL1 &= ~UCSWRST;             // Start USCI
    103.     ////////////////General GPIO Defines////////////////
    104.     P1DIR |= (LED1+GND+LED0);            //Define GPIOs as outputs else GPIOs are inputs
    105.     P2DIR |=VCC;
    106.     P1OUT =0;                     //All Outputs off except for Green_LED
    107.     P2OUT|=VCC;
    108.     P1OUT&=~GND;
    109.  
    110. while(1)
    111. {
    112. /*    do{
    113. ///////////////////SETUP ADC10 TO READ FROM CH A4 (P1.5)/////////////////////////////////////////////
    114.     ADC_init();
    115.     __enable_interrupt();                     // Enable interrupts.
    116.     int value=0;
    117. ///////////////////////////////Main Loop/////////////////////////////////////////////////////////////
    118.  
    119.         __delay_cycles(1000);                   // Wait for ADC Ref to settle
    120.         ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
    121.         __bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled
    122.         value = ADC10MEM;
    123.         temp=value*0.317;
    124.         r_temp=((temp*10)-10) * ((temp*10)/10);
    125.         itoa(temp, buffer, 10);
    126.         TX("External Temp:");
    127.         TX(buffer);
    128.         TX(".");
    129.         itoa(r_temp, buffer, 10);
    130.         TX(buffer);
    131.         TX(" Celsius\r\n");
    132.         P1OUT ^= LED0;
    133.         _delay_cycles(500000);
    134.         y=0;
    135.         x++;
    136. }while(x==1000);*/
    137.  
    138. do{
    139. ///////////////////SETUP ADC10 TO READ FROM CH A4 (P1.7)/////////////////////////////////////////////
    140.     ADC2_init();
    141.     __enable_interrupt();                     // Enable interrupts.
    142.     int value2=0;
    143. ///////////////////////////////Main Loop/////////////////////////////////////////////////////////////
    144.  
    145.         __delay_cycles(1000);                   // Wait for ADC Ref to settle
    146.         ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
    147.         __bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled
    148.         value2 = ADC10MEM;
    149.         temp2=value2*0.317;
    150.         r_temp=((temp2*10)-10) * ((temp2*10)/10);
    151.         itoa(temp2, buffer, 10);
    152.         TX("Internal Temp:");
    153.         TX(buffer);
    154.         TX(".");
    155.         itoa(r_temp, buffer, 10);
    156.         TX(buffer);
    157.         TX(" Celsius\r\n");
    158.         P1OUT ^= LED0;
    159.         _delay_cycles(500000);
    160.         x=0;
    161.         y++;
    162. }while(y==1000);
    163.  
    164. } //End while
    165.  
    166. } // End Main Program
    167.  
    168. // ADC10 interrupt service routine
    169. #pragma vector=ADC10_VECTOR
    170. __interrupt void ADC10_ISR (void)
    171. {
    172.   __bic_SR_register_on_exit(CPUOFF);        // Return to active mode
    173.   P1OUT ^= LED1;
    174. }
    175. [/i][/i]
     
    Last edited by a moderator: Dec 8, 2013
  2. ivaninspace

    Thread Starter New Member

    Jul 28, 2013
    10
    0
    If anyone has any ideas I would much appreciate that, for my c skills are weak.
     
  3. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    So have you got working? Have you verified that your uC is able to send data over to the terminal correctly? What about interfacing to the LM35?

    In short, what is and isn't working?

    Adding a question mark doesn't make it a question.
     
    ivaninspace likes this.
  4. ivaninspace

    Thread Starter New Member

    Jul 28, 2013
    10
    0
    The programming in the link I provided works great, I can see the temp of the LM35 on my computer. Now I'm trying to change a bit so that it outputs the value of two LM35s. The second LM35 I am trying to view as well is connected to port P1.7 using the same ground and Vcc as the first. When I try to run two different While loops or just simply add a copy of the code in the int main but changing it for the new pin, it outputs the text like below but the values are not different. I can put my finger on the second LM35 and I don't see any change in the second LM35 value. But once I put my finger on the first LM35 the value changes but for both.

    This is an example of how the hyperterminal would output the data
    ------------------------
    First LM35: 19 Celsius
    Second LM35: 19 Celsius
     
  5. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    For one thing, when both ADC blocks are in effect, you are ORing the contents of the ADC10AE0 register, meaning that after configuring the first LM35, you have INCHx = 0b0101,
    Code ( (Unknown Language)):
    1. ADC10AE0 |= BIT5;
    then you OR that value with BIT 7, making INCHx = 0111
    Code ( (Unknown Language)):
    1. ADC10AE0 |= BIT7;
    , which would be fine - for a single cycle. Since your do-while loop is only done once (while(y==1000); will always be false, unless, on the off chance that it gets initialized to 1000, but even then, it will get incremented and be stuck in the same loop).

    Code ( (Unknown Language)):
    1. char *message; // message variable
    2. [...]
    3.     message = tx_message; // move tx_message into message
    I know that this wasn't written by you, but this is the problem with trying to copy another person's code without understanding the syntax. This is a pointer, you are copying a pointer, not moving anything.

    Anyway, I'm off to the store, I'll have another look when I get back...
     
    ivaninspace likes this.
  6. ivaninspace

    Thread Starter New Member

    Jul 28, 2013
    10
    0
    Thanks for looking this over for me. I decided to take out the (Do While) and just leave one continuous while loop with both LM35's being sampled. But I still managed to get the first LM35's value in both outputs when i view it on the hyperterminal. I think I'm having a problem with the ADC10CTL1 where the CONSEQ is not set to 01 for Sequence of Channels. Am I going on the right track? I really appreciate your time!
    Here is the new code
    #include <msp430g2553.h>
    #include <stdbool.h>
    ////////////////Defines////////////////
    #define LED1 BIT6
    #define LED0 BIT0
    #define Error BIT0
    #define GND BIT4
    #define DAT BIT5
    #define DAT2 BIT7////////////////////////////////////////////////////new
    #define VCC BIT0 //port P2.0
    char buffer[4];
    float temp;
    float temp2;
    int r_temp,r_temp2;


    ////////////////Function Protos////////////////
    void TX(char *tx_message);
    static char *i2a(unsigned i, char *a, unsigned r);
    char *itoa(int i, char *a, int r);

    void ADC_init(void);
    void ADC2_init(void);

    static char *i2a(unsigned i, char *a, unsigned r)
    {
    if (i/r > 0) a = i2a(i/r,a,r);
    *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
    return a+1;
    }

    char *itoa(int i, char *a, int r)
    {
    if ((r < 2) || (r > 36)) r = 10;
    if (i < 0)
    {
    *a = '-';
    *i2a(-(unsigned)i,a+1,r) = 0;
    }
    else *i2a(i,a,r) = 0;
    return a;
    }

    void TX(char *tx_message)
    {
    unsigned int i=0; //Define end of string loop int
    char *message; // message variable
    unsigned int message_num; // define ascii int version variable
    message = tx_message; // move tx_message into message
    while(1)
    {
    if(message==0) // If end of input string is reached, break loop.
    {break;}
    message_num = (int)message; //Cast string char into a int variable
    UCA0TXBUF = message_num; // write INT to TX buffer
    i++; // increase string index
    __delay_cycles(10000); //transmission delay
    if(i>50) //prevent infinite transmit
    {
    P1OUT |= Error;
    break;
    }
    } // End TX Main While Loop
    } // End TX Function

    ///////////////////////////////////////////////////////////////////////////////////////////////////
    void ADC_init()
    {
    /* Configure ADC Channel */
    ADC10CTL1 = INCH_5 + ADC10DIV_3; // Channel 5, ADC10CLK/4
    ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE; //Vcc & Vss as reference
    ADC10AE0 |= BIT5; //P1.5 ADC option
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    void ADC2_init()
    {
    /* Configure ADC Channel */
    ADC10CTL1 = INCH_7 + ADC10DIV_3; // Channel 7, ADC10CLK/4
    ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE; //Vcc & Vss as reference
    ADC10AE0 |= BIT7; //P1.7 ADC option
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////



    ////////////////////////////////MAIN PROGRAM LOOP//////////////////////////////////////////////////

    void main(void)
    {


    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
    DCOCTL = CALDCO_1MHZ;
    ////////////////USCI setup////////////////
    P1SEL = BIT1 + BIT2; // Set P1.1 to RXD and P1.2 to TXD
    P1SEL2 = BIT1 + BIT2; //
    UCA0CTL1 |= UCSSEL_2; // Have USCI use SMCLK AKA 1MHz main CLK
    UCA0BR0 = 104; // Baud: 9600, N= CLK/Baud, N= 10^6 / 9600
    UCA0BR1 = 0; // Set upper half of baud select to 0
    UCA0MCTL = UCBRS_1; // Modulation UCBRSx = 1
    UCA0CTL1 &= ~UCSWRST; // Start USCI
    ////////////////General GPIO Defines////////////////
    P1DIR |= (LED1+GND+LED0); //Define GPIOs as outputs else GPIOs are inputs
    P2DIR |=VCC;
    P1OUT =0; //All Outputs off except for Green_LED
    P2OUT|=VCC;
    P1OUT&=~GND;
    while(1)
    {
    ///////////////////SETUP ADC10 TO READ FROM CH A4 (P1.5)/////////////////////////////////////////////
    ADC_init();
    __enable_interrupt(); // Enable interrupts.
    int value=0;
    ///////////////////////////////Main Loop/////////////////////////////////////////////////////////////

    __delay_cycles(1000); // Wait for ADC Ref to settle

    ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
    value = ADC10MEM;

    temp=value*0.317;
    r_temp=((temp*10)-10) * ((temp*10)/10);

    itoa(temp, buffer, 10);
    TX("External Temp:");
    TX(buffer);
    TX(".");
    itoa(r_temp, buffer, 10);
    TX(buffer);
    TX(" Celsius\r\n");
    P1OUT ^= LED0;

    _delay_cycles(500000);
    _delay_cycles(500000);


    ///////////////////SETUP ADC10 TO READ FROM CH A4 (P1.7)/////////////////////////////////////////////
    ADC2_init();
    __enable_interrupt(); // Enable interrupts.
    int value2=0;
    ///////////////////////////////Main Loop/////////////////////////////////////////////////////////////

    __delay_cycles(1000); // Wait for ADC Ref to settle

    ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
    value2 = ADC10MEM;

    temp2=value2*0.317;
    r_temp2=((temp2*10)-10) * ((temp2*10)/10);

    itoa(temp2, buffer, 10);
    TX("Internal Temp:");
    TX(buffer);
    TX(".");
    itoa(r_temp2, buffer, 10);
    TX(buffer);
    TX(" Celsius\r\n");
    P1OUT ^= LED0;

    _delay_cycles(500000);
    _delay_cycles(500000);

    } //End while

    } // End Main Program

    // ADC10 interrupt service routine
    #pragma vector=ADC10_VECTOR
    __interrupt void ADC10_ISR (void)
    {
    __bic_SR_register_on_exit(CPUOFF); // Return to active mode
    P1OUT ^= LED1;
    }
     
  7. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    You don't seen to be waiting for the ADC conversion to finish...you enable the ADC, turn on interrupts, then read the value returned from the last ADC conversion, which probably hadn't been updated. I would suggest polling (I wouldn't advise using interrupts at your level) the ADC status and wait until it's finished (I'm not at my computer, so I can't tell you specifics at the moment).

    Also, please use code tags when posting code (the # button).
     
  8. ivaninspace

    Thread Starter New Member

    Jul 28, 2013
    10
    0
    Thanks a lot, I think I know where you going with this. I should remove the __enable_interrupt(); // Enable interrupts. routine and let the rest of the code poll the pins.
     
  9. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    The interrupt that is therejust toggles an LED, indicating a conversion - this one is fine to leave in. I was referring to using interrupts to do the ADC conversion.

    You need to make your code sample the status the ADC and only get the converted value once the conversion is finished - your code now isn't polling...
     
  10. ivaninspace

    Thread Starter New Member

    Jul 28, 2013
    10
    0
    If you don't mind, could you give me an example of how to use the code I have to poll?

    The following code has a lot of the interrupt code commented out but it still outputs the same value for both LM35's on the hyperterminal

    Code ( (Unknown Language)):
    1. #include <msp430g2553.h>
    2. #include <stdbool.h>
    3. ////////////////Defines////////////////
    4. #define LED1        BIT6
    5. #define LED0        BIT0
    6. #define Error       BIT0
    7. #define GND         BIT4
    8. #define DAT         BIT5
    9. #define DAT2        BIT7////////////////////////////////////////////////////new
    10. #define VCC         BIT0 //port P2.0
    11. char buffer[4];
    12. char buffer2[4];
    13. float temp;
    14. float temp2;
    15. int r_temp,r_temp2;
    16.  
    17.  
    18. ////////////////Function Protos////////////////
    19. void TX(char *tx_message);
    20. static char *i2a(unsigned i, char *a, unsigned r);
    21. char *itoa(int i, char *a, int r);
    22.  
    23. void ADC_init(void);
    24. void ADC2_init(void);
    25.  
    26. static char *i2a(unsigned i, char *a, unsigned r)
    27. {
    28.     if (i/r > 0) a = i2a(i/r,a,r);
    29.     *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
    30.     return a+1;
    31. }
    32.  
    33. char *itoa(int i, char *a, int r)
    34. {
    35.     if ((r < 2) || (r > 36)) r = 10;
    36.     if (i < 0)
    37.     {
    38.         *a = '-';
    39.         *i2a(-(unsigned)i,a+1,r) = 0;
    40.     }
    41.     else *i2a(i,a,r) = 0;
    42.     return a;
    43. }
    44.  
    45. void TX(char *tx_message)
    46. {
    47.     unsigned int i=0; //Define end of string loop int
    48.     char *message; // message variable
    49.     unsigned int message_num; // define ascii int version variable
    50.     message = tx_message; // move tx_message into message
    51.     while(1)
    52.     {
    53.         if(message[i]==0) // If end of input string is reached, break loop.
    54.         {break;}
    55.         message_num = (int)message[i]; //Cast string char into a int variable
    56.         UCA0TXBUF = message_num; // write INT to TX buffer
    57.         i++; // increase string index
    58.         __delay_cycles(10000); //transmission delay
    59.         if(i>50) //prevent infinite transmit
    60.         {
    61.             P1OUT |= Error;
    62.             break;
    63.         }
    64.     } // End TX Main While Loop
    65. } // End TX Function
    66.  
    67. void TX2(char *tx_message2)
    68. {
    69.     unsigned int i=0; //Define end of string loop int
    70.     char *message2; // message variable
    71.     unsigned int message_num2; // define ascii int version variable
    72.     message2 = tx_message2; // move tx_message into message
    73.     while(1)
    74.     {
    75.         if(message2[i]==0) // If end of input string is reached, break loop.
    76.         {break;}
    77.         message_num2 = (int)message2[i]; //Cast string char into a int variable
    78.         UCA0TXBUF = message_num2; // write INT to TX buffer
    79.         i++; // increase string index
    80.         __delay_cycles(10000); //transmission delay
    81.         if(i>50) //prevent infinite transmit
    82.         {
    83.             P1OUT |= Error;
    84.             break;
    85.         }
    86.     } // End TX Main While Loop
    87. } // End TX Function
    88.  
    89.  
    90.  
    91. ///////////////////////////////////////////////////////////////////////////////////////////////////
    92. void ADC_init()
    93. {
    94.     /* Configure ADC  Channel */
    95.     ADC10CTL1 = INCH_5 + ADC10DIV_3;         // Channel 5, ADC10CLK/4
    96.     ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;  //Vcc & Vss as reference
    97.     ADC10AE0 |= BIT5;                         //P1.5 ADC option
    98. }
    99. ///////////////////////////////////////////////////////////////////////////////////////////////////
    100. void ADC2_init()
    101. {
    102.     /* Configure ADC  Channel */
    103.     ADC10CTL1 = INCH_7 + ADC10DIV_3;         // Channel 7, ADC10CLK/4
    104.     ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;  //Vcc & Vss as reference
    105.     ADC10AE0 |= BIT7;                         //P1.7 ADC option
    106. }
    107. ///////////////////////////////////////////////////////////////////////////////////////////////////
    108.  
    109.  
    110. ////////////////////////////////MAIN PROGRAM LOOP//////////////////////////////////////////////////
    111.  
    112. void main(void)
    113. {
    114.         WDTCTL = WDTPW + WDTHOLD;         // Stop WDT
    115.         BCSCTL1 = CALBC1_1MHZ;            // Set DCO to 1MHz
    116.         DCOCTL = CALDCO_1MHZ;
    117.         ////////////////USCI setup////////////////
    118.         P1SEL = BIT1 + BIT2;            // Set P1.1 to RXD and P1.2 to TXD
    119.         P1SEL2 = BIT1 + BIT2;            //
    120.         UCA0CTL1 |= UCSSEL_2;            // Have USCI use SMCLK AKA 1MHz main CLK
    121.         UCA0BR0 = 104;                  // Baud: 9600, N= CLK/Baud, N= 10^6 / 9600
    122.         UCA0BR1 = 0;                  // Set upper half of baud select to 0
    123.         UCA0MCTL = UCBRS_1;               // Modulation UCBRSx = 1
    124.         UCA0CTL1 &= ~UCSWRST;             // Start USCI
    125.         ////////////////General GPIO Defines////////////////
    126.         P1DIR |= (LED1+GND+LED0);            //Define GPIOs as outputs else GPIOs are inputs
    127.         P2DIR |=VCC;
    128.         P1OUT =0;                     //All Outputs off except for Green_LED
    129.         P2OUT|=VCC;
    130.         P1OUT&=~GND;
    131.  
    132. while(1)
    133. {
    134. ///////////////////SETUP ADC10 TO READ FROM CH A4 (P1.5)/////////////////////////////////////////////
    135.     ADC_init();
    136. //  __enable_interrupt();                     // Enable interrupts.
    137.     int value=0;
    138. ///////////////////////////////Main Loop/////////////////////////////////////////////////////////////
    139.  
    140.              __delay_cycles(1000);  // Wait for ADC Ref to settle
    141.              ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
    142.              //__bis_SR_register(CPUOFF + GIE); //       // LPM0 with interrupts enabled
    143.              value = ADC10MEM;
    144.  
    145.              temp=value*0.317;
    146.              r_temp=((temp*10)-10) * ((temp*10)/10);
    147.  
    148.              itoa(temp, buffer, 10);
    149.              TX("External Temp:");
    150.              TX(buffer);
    151.              TX(".");
    152.              itoa(r_temp, buffer, 10);
    153.              TX(buffer);
    154.              TX(" Celsius\r\n");
    155.              P1OUT ^= LED0;
    156.  
    157.              _delay_cycles(500000);
    158.              _delay_cycles(500000);
    159.              _delay_cycles(500000);
    160.              _delay_cycles(500000);
    161.  
    162. ///////////////////SETUP ADC10 TO READ FROM CH A4 (P1.7)/////////////////////////////////////////////
    163.     ADC2_init();
    164. //  __enable_interrupt();                     // Enable interrupts.
    165.     int value2=0;
    166. ///////////////////////////////Main Loop/////////////////////////////////////////////////////////////
    167.                          __delay_cycles(1000);  // Wait for ADC Ref to settle
    168.                          ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
    169.                         // __bis_SR_register(CPUOFF + GIE); //       // LPM0 with interrupts enabled
    170.                          value2 = ADC10MEM;
    171.  
    172.                          temp2=value2*0.317;
    173.                          r_temp2=((temp2*10)-10) * ((temp2*10)/10);
    174.  
    175.                          itoa(temp2, buffer2, 10);
    176.                          TX2("Internal Temp:");
    177.                          TX2(buffer2);
    178.                          TX2(".");
    179.                          itoa(r_temp2, buffer2, 10);
    180.                          TX2(buffer2);
    181.                          TX2(" Celsius\r\n");
    182.                          P1OUT ^= LED0;
    183.  
    184.                         _delay_cycles(500000);
    185.                         _delay_cycles(500000);
    186.  
    187.  
    188.  
    189. } //End while
    190.  
    191. } // End Main Program
    192.  
    193. // ADC10 interrupt service routine
    194. #pragma vector=ADC10_VECTOR
    195. __interrupt void ADC10_ISR (void)
    196. {
    197.   __bic_SR_register_on_exit(CPUOFF);        // Return to active mode
    198.   P1OUT ^= LED1;
    199. }[/i][/i][/i][/i]
     
  11. ivaninspace

    Thread Starter New Member

    Jul 28, 2013
    10
    0
    Dear tshuck, I got my code to work by using these lines between each LM35 sampler block

    ADC10CTL0 &= ~ENC; //disable so we can modify control bits
    ADC10CTL1 &= 0x0FFF; //clear input source

    Thank you very much for your time and knowledge, I really really really appropriate that man!!!!!!!!!!!!!!!!!!!
     
  12. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Good, I'm glad you got it working!
    This is, however, what I was saying back in post # 3.;)
     
    ivaninspace likes this.
  13. MrChips

    Moderator

    Oct 2, 2009
    12,447
    3,363
    shucks, I was just about to join the party!:(
     
    ivaninspace likes this.
Loading...