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.

ADC Port problem

Hi, 

I'm using ez430-rf2500 (MPS430), I understand how works the ADC with port 2.0 as input, but I need to set another ports as P4.3 (ADC analog input A12).

In the example the program sets P2.0 as ADC10AE0 |= 0x01; but I don't know how to set P4.3 on this way.

Where I could find a document with hexadecimal address for each port?

Thank you.

unsigned short int AnalogDigital()
{
unsigned short int value, a = 125, b = 1023; //1023 as the ADC takes 1 to 1024 is to compensate de float values and reach 1024 in return value.
float factor, motorValueADC;ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled

ADC10AE0 |= 0x01; // P2.0 ADC option select??????????????????????????????

P4DIR |= BIT3; // Set P2.0 to output direction
P4SEL |= BIT3;

factor = (float)a / (float)b; //Obtains factor to change ADC value to engines duty cycle value

for (;;)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit

value = ADC10MEM; // value between 0 - 1023 gives the POTENTIOMETER
motorValueADC = factor * value; // value constant to work with the motors duty cycle

return motorValueADC; //return constant to motors' function, value now is an integer

}
}

  • The information can be found in the user manual under ADC10 and at the end in the device manual (MSP430F22x4) under Application Information.

    In your case for A12: ADC10AE1 |= BIT4;.

    Marcos Marcos said:
    P4DIR |= BIT3; // Set P2.0 to output direction
    P4SEL |= BIT3;

    These are not necessary.

  • Thank you, but unfortunately it doesn't work.

  • I'm working with the following code, but the only works ADC, analog input A0 even if I change the code.

    #include <msp430x22x4.h>

    int main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled
    ADC10AE1 |= 0xff; // P2.0 ADC option select
    P1DIR |= 0x01; // Set P1.0 to output direction

    for (;;)
    {
    ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
    if (ADC10MEM < 0x1FF)
    P1OUT &= ~0x01; // Clear P1.0 LED off
    else
    P1OUT |= 0x01; // Set P1.0 LED on
    }
    }

    // ADC10 interrupt service routine
    #pragma vector=ADC10_VECTOR
    __interrupt void ADC10_ISR(void)
    {
    __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
    }

  • Marcos Marcos said:
    it doesn't work.

    Well, ‘it’ works! But you have to read the manual, there’s more to do to read channel A12, ADC10AEx only changes the behavior of the port pin’s hardware not the operating of the ADC. At least you have to select the required ADC channel, ADC10CTL1 INCHx.

  • Now it works, thanks a lot.

**Attention** This is a public forum