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.

how to optimize ADC operation



hello, i have 13 analog inputs which i would like to convert A/D and save the A/D inputs into external memory. however, i have a condition where-in at times, i need to sample 5 channels, at times, i have to sample 7 or 8 depending on various conditions. all these conditions would be INITIALIZED in the init routine of the code.Once fixed during the INIT routine, the no. of channels would be fixed until a PUC.

how can i achieve this objective? the way i am doing right now is i sample all the channels, however, save only those which are required. this requires a lot of computations and waste of cycles... it would be nice to sample only those channels which i have to save to mem. pseudo code is below:

//// a d c    i n t e r r u p t   r o u t i n e ////
    {
        switch(ADC_INTERRUPT_VECTOR)
        {
            case 0x0C:// do something

            case 0x32://do something

            default:
            break;
        }
        //save_data_to_memory()

    }

    save_data_to_memory()
    {
        if(channel1== enabled)
        {
            buff[1]= ADC12MEM1;
        }

        if(channel2== enabled)
        {
            buff[2]= ADC12MEM2;
        }

        if(channel3== enabled)
        {
            buff[3]= ADC12MEM3;
        }

        if(channel4== enabled)
        {
            buff[4]= ADC12MEM4;
        }

        if(channel5== enabled)
        {
            buff[5]= ADC12MEM1;
        }

        if(channel6== enabled)
        {
            buff[6]= ADC12MEM2;
        }

        if(channel7== enabled)
        {
            buff[7]= ADC12MEM3;
        }

        if(channel8== enabled)
        {
            buff[8]= ADC12MEM4;
        }
        //and so on... till the end of channels

 

 

  • You don't write which MSP you have.
    However, the ADC12 only has 12 external channels, so 13 is impossible without external multiplexing.

    Bascially, the channel you're sampling is independent from the ADC12MCTLx and ADC12MEMx register you use. You can sample 16 times teh same channel to 16 different registers or sample different channels with the same register set.

    If the required channels are determined on startup, just set ADC12MCTL0 to ADC12MCTL(x-1) for the x channels you require (whatever they are) and then just do a conversion run from 0 to x-1 (set the EOC bit in ADC12MCTL(x-1)).
    After the conversion sare done, just copy x values from ADC12MEM0 to ADC12MEM(x-1) and you're done.

    YOu can use arrays for the initialization:

    unsigned char channels[3][max_channels+1]= { { INCH_0, INCH_1, INCH_7, -1}, {INCH_5, INCH_8,-1}, {INCH_2, INCH_6,INCH_7, INCH_8,-1}};

    For init case 0,1 or 2, you go through the array until you reach the -1 and just configure the first n ADC12MCTLx registers with it. Write down the index of the -1 in a global variable and you know how many values to read later from ADC12MEMx.

  • hello Jens-Michael Gross, i am using MSP430f26xxx series uC with ADC12 channels and i am using an external mux. some more info on the ADC routine, i am using timerA to trigger the interrupt clock for the ADC, so do you think that i should be re-configuring the ADC control registers depending on the no. of the channels selected? also, i am using a single sequence ADC... does it matter to the logic you mentioned? also, i am little confused with the unsigned array initialization..! can you please elaborate a more on that.. that would be great!!

  • The array contains n (in this case n=3) 'configurations'. You simply read one element after the other and use it to configure ADC12MCTLx, beginning with x=0. If you read -1, you know that's it and the ADC12MCTLx before needs the EOS bit set. (and how many ADC12MEM to read later after each conversion sequence).
    So you only need to chose n for any predefined configuration you have. You will always convert all inpout channels you need for this configuraiton and will always have a sequence that stars with ADC12MEM0 and ends on ADC12MEMx.
    The init values are the values needed for setting the input channel, but may as well contain the complete ADC12MCTLx config (including the final EOS bit).
    There is no need to write all init values to fill up the array. The compiler will automatically fill the remaining parts (after the -1) with 0.

    YOu can configure the ADC to trigger each conversion individually, or start a burst conversion of a complete sequence. If you youst trigger the sequence, then the timer interval only needs to be long enough to make the longest conversion chain. If you trigger each conversion individually (e.g. by controlling the S&H gate), then you might need to adjust the timer interval, so you'll get a complete sequence always in the same time, no matte rof the number of conversions.

**Attention** This is a public forum