Jump to content
43oh

Recommended Posts

Hi,

 

I'm new to MSP430,  I'm using a MSP430G2553 in a project and need help with an in depth understanding of programming the ADC10 inputs of the MCU. I'm using a potentiometer in order to light one of 3 LEDs. 

 

For example, LED1 lights up when input voltage is 1V or less, LED2 lights up between 1V and 2V and LED3 lights up when the input voltage is greater than or equal to 2V. I have attached my code below but I am not clear on how to read, convert and store a voltage so that I can use the IF statements to light the respective LEDs.

 

#include <msp430g2553.h>

void indicator_LED();

 

int main(void) {

unsigned int i;

 

    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer

    P1DIR = 0x00;

    P2DIR = 0xff;

    P1OUT = 0x00;

    P2OUT = 0x00;

 

 

 

    while(1) // keep looping

    {

 

       ADC10CTL1 = CONSEQ_2 + INCH_0;                                             // Repeat single channel, A0

       ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;                          // Sample & Hold Time + ADC10 ON + Interrupt Enable

       ADC10DTC1 = 0x0A;                                                          // 10 conversions

       ADC10AE0 |= 0x01;                                                          // P1.0 ADC option select

 

 

       ADC10CTL0 |= ENC + ADC10SC;                                                // Sampling and conversion start

 

       __low_power_mode_0();                                                      //__bis_SR_register (CPUOFF + GIE);// LPM0, ADC10_ISR will force exit

 

       if (ADC10MEM <= 0x228 && ADC10MEM > 0x1D6)

           {

               P2OUT = P2OUT | BIT1;

                           for(i=0;i<=1;i++);

           }

       else if (ADC10MEM <= 0x1D6)

           {

               P2OUT = P2OUT | BIT2;

                           for(i=0;i<=1;i++);

           }

       else if (ADC10MEM > 0x228)

           {

               P2OUT = P2OUT | BIT0;

                           for(i=0;i<=1;i++);

           }

       else

           {

               P2OUT = ~P2OUT;

                           for(i=0;i<=1;i++);

           }

    }

}

Link to post
Share on other sites
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...