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.

28035 ADC software triggerd conversation configuration

Hello, i want to sample 13 channels software triggerd. My problem is the conversation is running once and in the secound conversation it is spinning in the while

//Wait for ADCINT1 to trigger, then add ADCRESULT0-7 registers to sum
        while (AdcRegs.ADCINTFLG.bit.ADCINT1 == 0){}

maybe anybody have an idea.


Thanks a lot

here is my code:

    EALLOW;
    AdcRegs.ADCCTL1.bit.ADCREFSEL = 1;        // use external REF with 2.5V
    AdcRegs.ADCCTL1.bit.ADCBGPWD  = 1;      // Power ADC BG
    AdcRegs.ADCCTL1.bit.ADCREFPWD = 1;      // Power reference
    AdcRegs.ADCCTL1.bit.ADCPWDN   = 1;      // Power ADC
    AdcRegs.ADCCTL1.bit.ADCENABLE = 1;      // Enable ADC
//    AdcRegs.ADCCTL1.bit.ADCREFSEL = 0;      // Select interal BG
    EDIS;

    EALLOW;
    AdcRegs.ADCSOC0CTL.bit.CHSEL= 1;    // A1 first conversation is sumetimes corrupt see errata
    AdcRegs.ADCSOC1CTL.bit.CHSEL= 1;    // A1
    AdcRegs.ADCSOC2CTL.bit.CHSEL= 2;    // A2
    AdcRegs.ADCSOC3CTL.bit.CHSEL= 3;    // A3
    AdcRegs.ADCSOC4CTL.bit.CHSEL= 4;    // A4
    AdcRegs.ADCSOC5CTL.bit.CHSEL= 6;    // A6
    AdcRegs.ADCSOC6CTL.bit.CHSEL= 7;    // A7

    AdcRegs.ADCSOC7CTL.bit.CHSEL=     8;    // B0
    AdcRegs.ADCSOC8CTL.bit.CHSEL=     9;  // B1
    AdcRegs.ADCSOC9CTL.bit.CHSEL=     10; // B2
    AdcRegs.ADCSOC10CTL.bit.CHSEL=     11; // B3
    AdcRegs.ADCSOC11CTL.bit.CHSEL=     12; // B4
    AdcRegs.ADCSOC12CTL.bit.CHSEL=     14; // B6
    AdcRegs.ADCSOC13CTL.bit.CHSEL=     15;    // B7
//    AdcRegs.ADCSOC13CTL.bit.CHSEL= ch_no;
//    AdcRegs.ADCSOC14CTL.bit.CHSEL= ch_no;
//    AdcRegs.ADCSOC15CTL.bit.CHSEL= ch_no;
    EDIS;

    ACQPS_Value = 0x3f;
    EALLOW;
    AdcRegs.ADCSOC0CTL.bit.ACQPS  = ACQPS_Value;
    AdcRegs.ADCSOC1CTL.bit.ACQPS  = ACQPS_Value;
    AdcRegs.ADCSOC2CTL.bit.ACQPS  = ACQPS_Value;
    AdcRegs.ADCSOC3CTL.bit.ACQPS  = ACQPS_Value;
    AdcRegs.ADCSOC4CTL.bit.ACQPS  = ACQPS_Value;
    AdcRegs.ADCSOC5CTL.bit.ACQPS  = ACQPS_Value;
    AdcRegs.ADCSOC6CTL.bit.ACQPS  = ACQPS_Value;
    AdcRegs.ADCSOC7CTL.bit.ACQPS  = ACQPS_Value;
    AdcRegs.ADCSOC8CTL.bit.ACQPS  = ACQPS_Value;
    AdcRegs.ADCSOC9CTL.bit.ACQPS  = ACQPS_Value;
    AdcRegs.ADCSOC10CTL.bit.ACQPS = ACQPS_Value;
    AdcRegs.ADCSOC11CTL.bit.ACQPS = ACQPS_Value;
    AdcRegs.ADCSOC12CTL.bit.ACQPS = ACQPS_Value;
    AdcRegs.ADCSOC13CTL.bit.ACQPS = ACQPS_Value;
//    AdcRegs.ADCSOC14CTL.bit.ACQPS = ACQPS_Value;
//    AdcRegs.ADCSOC15CTL.bit.ACQPS = ACQPS_Value;


    //Enable ping-pong sampling

    // Enabled ADCINT1 and ADCINT2
    AdcRegs.INTSEL1N2.bit.INT1E = 1;
    AdcRegs.INTSEL1N2.bit.INT2E = 1;

    // Disable continuous sampling for ADCINT1 and ADCINT2
    AdcRegs.INTSEL1N2.bit.INT1CONT = 0;
    AdcRegs.INTSEL1N2.bit.INT2CONT = 0;

    AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;    //ADCINTs trigger at end of conversion

    // Setup ADCINT1 and ADCINT2 trigger source
    AdcRegs.INTSEL1N2.bit.INT1SEL = 6;      //EOC5 triggers ADCINT1
    AdcRegs.INTSEL1N2.bit.INT2SEL = 13;     //EOC12 triggers ADCINT2

    // Setup each SOC's ADCINT trigger source
    AdcRegs.ADCINTSOCSEL1.bit.SOC0  = 2;    //ADCINT2 starts SOC0-6
    AdcRegs.ADCINTSOCSEL1.bit.SOC1  = 2;
    AdcRegs.ADCINTSOCSEL1.bit.SOC2  = 2;
    AdcRegs.ADCINTSOCSEL1.bit.SOC3  = 2;
    AdcRegs.ADCINTSOCSEL1.bit.SOC4  = 2;
    AdcRegs.ADCINTSOCSEL1.bit.SOC5  = 2;
    AdcRegs.ADCINTSOCSEL1.bit.SOC6  = 2;
    AdcRegs.ADCINTSOCSEL1.bit.SOC7  = 1;    //ADCINT1 starts SOC6-13
    AdcRegs.ADCINTSOCSEL2.bit.SOC8  = 1;
    AdcRegs.ADCINTSOCSEL2.bit.SOC9  = 1;
    AdcRegs.ADCINTSOCSEL2.bit.SOC10 = 1;
    AdcRegs.ADCINTSOCSEL2.bit.SOC11 = 1;
    AdcRegs.ADCINTSOCSEL2.bit.SOC12 = 1;
    AdcRegs.ADCINTSOCSEL2.bit.SOC13 = 1;
//    AdcRegs.ADCINTSOCSEL2.bit.SOC14 = 1;
//    AdcRegs.ADCINTSOCSEL2.bit.SOC15 = 1;
    EDIS;
    DELAY_US(ADC_usDELAY);                  // Delay before converting ADC channels

    for (i=0; i<13; i++)   // clear the buffer
    {
        adc_result[i] = 0;
    }
//ADC Conversion
    AdcRegs.ADCSOCFRC1.all = 0x007F;  // Force Start SOC0-6 to begin ping-pong sampling
    while( index < SampleSize )        // take 8 samples
    {
        //Wait for ADCINT1 to trigger, then add ADCRESULT0-7 registers to sum
        while (AdcRegs.ADCINTFLG.bit.ADCINT1 == 0){}      // ADCINT1 is not going to 1 again
//        while(AdcRegs.ADCCTL1.bit.ADCBSY)asm("    nop");
        AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;   //Must clear ADCINT1 flag since INT1CONT = 0
        i16_tmp = AdcResult.ADCRESULT0;                            // A1; SOC0 1st conversation is corrupt see errata
        adc_result[CURRENT_HEATER_1] += AdcResult.ADCRESULT1;    // A1; SOC1
        adc_result[CURRENT_HEATER_2] += AdcResult.ADCRESULT2;    // A2; SOC2
        adc_result[CURRENT_HEATER_3] += AdcResult.ADCRESULT3;    // A3; SOC3
        adc_result[CURRENT_HEATER_4] += AdcResult.ADCRESULT4;    // A4; SOC4
        adc_result[CURRENT_HEATER_5] += AdcResult.ADCRESULT5;    // A6; SOC5
        adc_result[CURRENT_HEATER_6] += AdcResult.ADCRESULT6;    // A7; SOC6

//        adc_result[0] = AdcResult.ADCRESULT7;

        //Wait for ADCINT2 to trigger, then add ADCRESULT8-15 registers to sum
        while (AdcRegs.ADCINTFLG.bit.ADCINT2 == 0)asm("    nop");
//        while(AdcRegs.ADCCTL1.bit.ADCBSY){}
        AdcRegs.ADCINTFLGCLR.bit.ADCINT2 = 1;   //Must clear ADCINT2 flag since INT2CONT = 0
        adc_result[CURRENT_HEATER_7] += AdcResult.ADCRESULT7;    // B0; SOC7
        adc_result[CURRENT_HEATER_8] += AdcResult.ADCRESULT8;    // B1; SOC8
        adc_result[VOLTAGE_24V] += AdcResult.ADCRESULT9;        // B2; SOC9
        adc_result[VOLTAGE_5V] += AdcResult.ADCRESULT10;            // B3; SOC10
        adc_result[CJ125_UR] += AdcResult.ADCRESULT11;            // B4; SOC11
        adc_result[CJ125_UA] += AdcResult.ADCRESULT12;            // B6; SOC12
        adc_result[PRESSURE_SENSOR] += AdcResult.ADCRESULT13;    // B7; SOC13
//        adc_result[13] = AdcResult.ADCRESULT13;
        ++index;

    } // end data collection
    //Disable ADCINT1 and ADCINT2 to STOP the ping-pong sampling
    AdcRegs.INTSEL1N2.bit.INT1E = 0;
    AdcRegs.INTSEL1N2.bit.INT2E = 0;

  • Hello, my solutio is at the moment to start the ad conversation again with AdcRegs.ADCSOCFRC1.all = 0x007F;  in the while loop

        while( index < SampleSize )        // take 8 samples
        {
            //Wait for ADCINT1 to trigger, then add ADCRESULT0-7 registers to sum
            while (AdcRegs.ADCINTFLG.bit.ADCINT1 == 0){}
    //        while(AdcRegs.ADCCTL1.bit.ADCBSY)asm("    nop");
            AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;   //Must clear ADCINT1 flag since INT1CONT = 0
            i16_tmp = AdcResult.ADCRESULT0;                            // A1; SOC0 1st conversation is corrupt see errata
            adc_result[CURRENT_HEATER_1] += AdcResult.ADCRESULT1;    // A1; SOC1
            adc_result[CURRENT_HEATER_2] += AdcResult.ADCRESULT2;    // A2; SOC2
            adc_result[CURRENT_HEATER_3] += AdcResult.ADCRESULT3;    // A3; SOC3
            adc_result[CURRENT_HEATER_4] += AdcResult.ADCRESULT4;    // A4; SOC4
            adc_result[CURRENT_HEATER_5] += AdcResult.ADCRESULT5;    // A6; SOC5
            adc_result[CURRENT_HEATER_6] += AdcResult.ADCRESULT6;    // A7; SOC6

    //        adc_result[0] = AdcResult.ADCRESULT7;

            //Wait for ADCINT2 to trigger, then add ADCRESULT8-15 registers to sum
            while (AdcRegs.ADCINTFLG.bit.ADCINT2 == 0)asm("    nop");
            AdcRegs.ADCINTFLGCLR.bit.ADCINT2 = 1;   //Must clear ADCINT2 flag since INT2CONT = 0
            adc_result[CURRENT_HEATER_7] += AdcResult.ADCRESULT7;    // B0; SOC7
            adc_result[CURRENT_HEATER_8] += AdcResult.ADCRESULT8;    // B1; SOC8
            adc_result[VOLTAGE_24V] += AdcResult.ADCRESULT9;        // B2; SOC9
            adc_result[VOLTAGE_5V] += AdcResult.ADCRESULT10;            // B3; SOC10
            adc_result[CJ125_UR] += AdcResult.ADCRESULT11;            // B4; SOC11
            adc_result[CJ125_UA] += AdcResult.ADCRESULT12;            // B6; SOC12
            adc_result[PRESSURE_SENSOR] += AdcResult.ADCRESULT13;    // B7; SOC13
    //        adc_result[13] = AdcResult.ADCRESULT13;
            ++index;
            AdcRegs.ADCSOCFRC1.all = 0x007F;  // Force Start SOC0-6 to begin ping-pong sampling

  • Hi Franz,

    "AdcRegs.ADCSOCFRC1.all = 0x007F;  // Force Start SOC0-6 to begin ping-pong sampling"

    This has to be before the forever while/ for loop. 

    Example:

    AdcRegs.ADCSOCFRC1.all = 0x1000; // kick start ADC by causing a SOC12 event

    //=================================

    // Forever LOOP
    //=================================

    for(;;) //infinite loop
    {
    AdcResults[0] = AdcResult.ADCRESULT0;
    AdcResults[1] = AdcResult.ADCRESULT1;
    AdcResults[2] = AdcResult.ADCRESULT2;
    AdcResults[3] = 0; // ADC-A3 NOT AVAILABLE on controlSTICK
    AdcResults[4] = AdcResult.ADCRESULT4;
    AdcResults[5] = AdcResult.ADCRESULT5;
    AdcResults[6] = AdcResult.ADCRESULT6;
    AdcResults[7] = 0; // ADC-A7 NOT AVAILABLE on controlSTICK
    AdcResults[8] = AdcResult.ADCRESULT8;
    AdcResults[9] = AdcResult.ADCRESULT9;
    AdcResults[10] = AdcResult.ADCRESULT10;
    AdcResults[11] = 0; // ADC-B3 NOT AVAILABLE on controlSTICK
    AdcResults[12] = AdcResult.ADCRESULT12;
    AdcResults[13] = 0; // ADC-B5 NOT AVAILABLE on controlSTICK
    AdcResults[14] = AdcResult.ADCRESULT14;
    AdcResults[15] = 0; // ADC-B7 NOT AVAILABLE on controlSTICK
    }
    } //END MAIN CODE


    Regards,

    Gautam

  • Franz,

    So this is how I interpret what you are trying to do:

    Setup the ADC so that when desired, the ADC will convert 13 channels of interest (plus one dummy channel as per the errata) 8 times, accumulating the results for each channel.

    Can you clarify your requirements for this?  Do you just want this to work, or do you want to accomplish the above with the absolute minimum possible wasted cycles?  

  • Hello Devin, 1st i want to say thank you for your answer. The application is not time critical. In my case i take 8 samples and make an average (adcresult >>=3;) I want to start the ADC conversation from timer Int. manual by software trigger or with an interrupt trigger.

    best regards

    Franz

  • I think the simplest way to do this is going to be similar to what Guatam has posted. Just use a software trigger in a loop to generate enough samples.  This would look something like the below.  Call doConversions whenever you want to take samples.  Make sure this works for you, and then feel free to come back if you need to optimize this a little bit (there is plenty of room to save sampling time and CPU time).  

    //Warning: may contain syntax and/or logical errors

    void setupADC(void)
    {
        //other adc initializations
        ...

        //configure 14 SOCs with acqps and channel select (trigger is software only, default)
        //configure SOC0 as dummy conversion (as per errata)
       ...

       AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //Set pulse positions to late
       AdcRegs.ADCINTSEL1N2.bit.INT1SEL = 13; //end of SOC13 will set INT1 flag
       AdcRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
    }

    #define NUMBER_SAMPLES 8
    void doConversions(void)
    {
        Uint16 iter;
        Uint16* ptr;

        //initialize sample array to all 0s
        ...

        for(iter = 0; iter < NUMBER_SAMPLES; iter++)
        {
            //start conversions immediately via software
            AdcRegs.ADCSOCFRC1.all = 0x0FFF;

            //wait for end SOC13 to set ADCINT1 flag
            while(AdcRegs.ADCINTFLG.bit.ADCINT1 == 0);
            AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;

            //accumulate samples
            //(no need to actually read SOC0 results to satisfy errata)
            adc_result[CURRENT_HEATER_1] = AdcResult.ADCRESULT1;
            ...
        }

        //downshift accumulated results to accomplish averaging
        ptr = (Uint16*)adc_result; //*EDIT from &AdcResult* 
        for(iter = 0; iter < 14; iter++)
        {
            *ptr++ >>= 3;
        }
    }

  • Hello, thank you for your answer. I have tested the code now and it dose not work. But i think i have found the mistake.

    for(iter = 0; iter < NUMBER_SAMPLES; iter++)
        {
            //start conversions immediately via software
            AdcRegs.ADCSOCFRC1.all = 0x0FFF;     // is only for SOC 0 - 11 but i need SOC 0 - 13

    i changed the value to:

            AdcRegs.ADCSOCFRC1.all = 0x3FFF;     // start SOC 0 - 13

    and the code work now.

    Thank you for your help.

    Franz


  • @Devin,

    Applaud your attempt to far better draw/tease out poster's objective.  IMHO - this method practiced far too little.  (here & other fora)

    In addition - you went on to provide a, "sample solution" - minus "bells/whistles" (which add size/complexity) - often unnecessary or distracting from task.

    Result: Poster's success.   Well done...   (and would hope this approach may be "standardized/modeled...")

  • Franz,

    You are correct, the software force should be 0x3FFF. Glad to hear it worked for you.

    cb1_mobile,

    Thanks!