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.

Multiple ADC10 ports - each read separately - using MSP430f6723

Hi,

I've been looking through the code on the forum, but I haven't found an answer to my specific problem.

I need 2 channels on the ADC10 - each one sampled at different times.

A0 - has High/Lo values for trigger

A1 - when I sample, must get 2kHz samples to analyze.

Here's my code for the A0 sampling channel - which works. How do I add in the A1 ADC10 channel?

//Initialize the ADC10 Module
/*
* Use internal ADC10 bit as sample/hold signal to start conversion
* USE MODOSC 5MHZ Digital Oscillator as clock source
* Use default clock divider of 1
*/
ADC10_init(__MSP430_BASEADDRESS_ADC10_A__,
ADC10_SAMPLEHOLDSOURCE_SC,
ADC10_CLOCKSOURCE_ADC10OSC,
ADC10_CLOCKDIVIDER_1);

ADC10_enable(__MSP430_BASEADDRESS_ADC10_A__);

/*
* Sample/hold for 16 clock cycles
* Do not enable Multiple Sampling
*/
ADC10_setupSamplingTimer(__MSP430_BASEADDRESS_ADC10_A__,
ADC10_CYCLEHOLD_16_CYCLES,
ADC10_MULTIPLESAMPLESDISABLE);

//Convert data into signed, 2's complement format
ADC10_setDataReadBackFormat(__MSP430_BASEADDRESS_ADC10_A__,
ADC10_SIGNED_2SCOMPLEMENT);

//Configure Memory Buffer
/*
* Use input A0
* Use positive reference of AVcc
* Use negative reference of AVss
*/
ADC10_memoryConfigure(__MSP430_BASEADDRESS_ADC10_A__,
ADC10_INPUT_A0,
ADC10_VREFPOS_AVCC,
ADC10_VREFNEG_AVSS);

//Enable all window comparator HI + LO interrupts
ADC10_setWindowComp(__MSP430_BASEADDRESS_ADC10_A__, tmr.sense * 2000, (unsigned int)(tmr.sense * -2000));
ADC10_enableInterrupt(__MSP430_BASEADDRESS_ADC10_A__, ADC10HIIE + ADC10LOIE);
ADC10_startConversion(__MSP430_BASEADDRESS_ADC10_A__, ADC10_SINGLECHANNEL);

And here's the interrupt routine:

//ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR

__interrupt void ADC10_ISR (void)
{

switch (__even_in_range(ADC10IV,12))

{
case 0: break; //No interrupt
case 2: break; //conversion result overflow
case 4: break; //conversion time overflow

// interrupt from MIC - if higher/lower than threshold
case 6: //break; //ADC10HI
case 8: //break; //ADC10LO
      tmr.tstart = timeNow; 
break;

case 12: break; //ADC10IFG0
case 10: break; //ADC10IN

default:
break;
}

}

Thanks,

Mechi

  • And something else...

    I just downloaded the newest version of MSPWare (driverlib_1_40_00_00). I noticed that in the adc10.c code there is the following message:


    //adc10.c - Driver for the ADC10 Module.
    //THIS FILE IS INCLUDED FOR BACKWARD COMPATIBILTY. PLEASE DO NOT USE THIS FILE
    //AND INCLUDED APIS FOR NEW APPLICATIONS.

    Since i'm still in development/evaluation, I have no problem using a newer version or API - please advise.

    Thanks,

    Mechi

  • If of the two inputs only the timing of one is important (which apparently is the case), then just sample both channels alternatively with the same timing.
    If you need A2 with 2kHz, then setup the ADC for repeated sequence of channels (which converts A1, A0, A1, A0,...), program it for being triggered by a timer and program the timer for 4kHz trigger frequency.

    You then will get an interrupt every 250µs(when a conversion is done). You only need to keep track of which is which sample (A0 or A1) and if you don't need A0 as often, ignore all A0 samples except every nth.

  • A0 should only trigger an interrupt if it's over or below a certain threshold -

    There fore i set the following:

    ADC10_setWindowComp(__MSP430_BASEADDRESS_ADC10_A__, tmr.sense * 2000, (unsigned int)(tmr.sense * -2000));
    ADC10_enableInterrupt(__MSP430_BASEADDRESS_ADC10_A__, ADC10HIIE + ADC10LOIE);

    and the interrupt is received on case 6: and case 8: (ADC10HI and ADC10LO)

    For A1, when there are incoming signals, I need to constantly get and save the data:

    case 12: //ADC10IFG0
                inBuf[idx] = ADC10_getResults(__MSP430_BASEADDRESS_ADC10_A__);
                newData++;
               ADC10_startConversion(__MSP430_BASEADDRESS_ADC10_A__, ADC10_SINGLECHANNEL);
               break;

    Thanks for any ideas,

    Mechi

  • Mechi Fendel said:
    A0 should only trigger an interrupt if it's over or below a certain threshold -

    Ah, you're using the comparator feature. Well, the ADC can only access one input at a time. So when sampling A1, you cannot at the same time use the comparator on A0. Actually, the comparator doesn't care for the selected channel. It compares any conversion result, no matter how it was gathered.

    When using my suggestion, you can compare the A0 result (on every second interrupt) against your thresholds and do what you want. Or else keep and store the A1 result. Two code lines more for the compare, many lines less for not switching ADC modes.

    Or you have to constantly reprogram the ADC for either comparator or sampling use. But not both simultaneously.

**Attention** This is a public forum