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/MSP430F5438A: MSP430F5438A ADC12 more channel conversion

Part Number: MSP430F5438A
Other Parts Discussed in Thread: MSP430WARE

Tool/software: Code Composer Studio

Hi,

I am having problem with initialization of 2 (or more) ADC12 channels and potentiometers. I have succeded with one, but the problem is happeng when trying with more channels. How should my initialization look like if I want to use channel 14 and channel 15 with P1 and P2?While the program runs used channel changes by users input.

  • Hi Srdjan,
    Take a look at the examples adc12_06 and adc12_09 in TI Resource Explorer. You can swap out the ADC12MCTLx assignment to your desired channel.

    Can you elaborate on how the used channels change with user input?
    If it's something like a GPIO, you could just use an interrupt to reconfigure the ADC as desired.
  • Thank you for your reply!

    Where can I find this Ti Resource Explorer? Is that pdf file?

    I want to send from Computer-terminal number. For example numbers 1, 2 ,3 or 4. If I send 1, starts conversion on first conv. channel. The result of the conversion should be used for PWM toggling first diode.

    If I send 2 from terminal, starts second conversion channel, and result is used for PWM toggling second diode.

    Thank you in advance

  • In CCS, go to View in the Tool bar and click Resource Explorer. Then expand Software, then MSP430Ware, then Devices, Then MSP430F5XX_6XX, then MSP430F5438A, then Peripheral Examples. then Register Level or Driver Library.

    It sounds like you could implement a switch case with a USCI ISR for the user input!
  • Thank you a lot. I found the explanation for my problem.

    And sorry if my English is not so good.

    I have only one more question. I will ask it there, but if you think I should open new thread i will do this.

    When conversion is finished I read the result, and place the value (0-4095) in an integer, for example "int adcResult". This value I want to use for PWM toggling led diode, viz this result i put in matching CCR.

    But, i have problem with conversion this value to value at range 0-100. If I do PWMvalue = adcResult/4095*100, in PWMvalue will be false value. If I do PWMvalue = adcResult*100/4095.

    I tried to change type of adcResult and PWMvalue, but again in PWMvalue is false value.

    In adcResult, when I read result of conversion, is good value, in range 0-4095. But after conversion to value in range 0-100 i get false value. Can you say me how to convert this to value in range 0-100.

    Thank you in advance.

    Best regards,

    Srdjan

  • And some addition for ADC conversion.
    I can not change my adc channel.
    If I initialize
    ADC12MCTL0 = ADC12INCH_8;
    I received result of conversion from channel 8. But then I want to change channel
    ADC12MCTL0 = ADC12INCH_14;
    It continues to received values from channel 8.

    Also, if I initialize it with channel 14, I received values from channel14, but when I changed channel to, for example channel 8, register continues to receive conversion results from channel 14.
    I don't know why, is there maybe some flag that should be set?

    ADC12CTL0 = ADC12ON + ADC12SHT0_15;
    ADC12CTL1 = ADC12SHP;
    ADC12MCTL0 = ADC12INCH_8;
    ADC12IE |= ADC12IE0;
    ADC12CTL0 |= ADC12ENC;

    This is my initializing of adc conversion.
    And in a function I want to change channel

    void switchChannelAdc(int id){
    switch(id)
    {
    case 1:
    ADC12MCTL0 = ADC12INCH_14;
    break;
    case 2:
    ADC12MCTL0 = ADC12INCH_15;
    break;
    case 3:
    ADC12MCTL0 = ADC12INCH_8;
    break;
    case 4:
    ADC12MCTL0 = ADC12INCH_9;
    break;
    }
    }
  • Hi Srdjan,
    In the first equation you doing adcResult/4095*100, which will equate to 0*100 unless adcValue is 4095. In the second case, I believe that you are using an int, and overflowing it. Try changing this a long, as it is recommended to avoid using floats.

    As for changing the channels, the userguide states that ADC12MCTLx must only be changed while ADC12ENC = 0.
  • Thank you for help! This resolved my problem.

    Best regards,
    Srdjan

**Attention** This is a public forum