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/MSP430F5529: ADC12 on A12 just like example code ADC_01

Part Number: MSP430F5529

Tool/software: Code Composer Studio

The ADC_01 example code reads A0 (P6.0) and illuminates and LED if the reading is > 0.5V.  What modifications to that simple example will do the exact same thing but read A12 (P7.0) instead?

I'm using a '5529 Launchpad.

  • Hi Clark,

    You can do this by replacing the following line:

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

    with:

    P7SEL |= 0x01; // P7.0 ADC option select

    This will set the ADC to use P7.0 instead of P6.0.

    Please also note that this example turns on the LED when the reading is > 0.5 * AVcc, not when it is > 0.5V.

    Regards,
    Nathan
  • I suspect you also need:

    > ADC12MCTL0 = ADC12INCH_12; // Only A12 , VRSEL=0 (Vcc)

    since the original code had an implicit "ADC12MCTL0=ADC12INCH_0" ( =0). Setting BIT0 (0x01) in ADC12IE refers to MCTL0, which is fine.

  • This issue was taken off line. For anyone following this thread, the 2 changes above are necessary, and the ADC12MCTL0 change needs to happen before the ADC and interrupts are enabled.
  • Thanks Nathan for finding the fix; below is the code I ended up with, which doesn't go into low-power mode, it just delays and then looks at the A12 result.  Sorry the formatting got mangled, but it works for what I needed!

    ------------------

    #include <msp430.h>
    
    
    int main(void)
    
    {
    
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    
    
    ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
    
    ADC12CTL1 = ADC12SHP; // Use sampling timer
    
    ADC12MCTL0 = ADC12INCH_12; // Only A12 , VRSEL=0 (Vcc)
    
    ADC12IE = 0x01; // Enable interrupt
    
    ADC12CTL0 |= ADC12ENC;
    
    P7SEL |= 0x01; // P7.0 ADC option select
    
    P1DIR |= 0x01; // P1.0 output
    
    
    while (1)
    
    {
    
    ADC12CTL0 |= ADC12SC; // Start sampling/conversion
    
    __delay_cycles(1000);
    
    if (ADC12MEM0 >= 0x7ff) // ADC12MEM = A0 > 0.5AVcc?
    
    P1OUT |= BIT0; // P1.0 = 1
    
    else
    
    P1OUT &= ~BIT0; // P1.0 = 0
    
    }
    
    }

     

**Attention** This is a public forum