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 trigger source from software not working

Hi,

I'm trying to run a simple code for an acquisition on ADC of F28027 and I'm not able to trigger the conversion through software.

After doing all the configurations of the ADC I have a task that should be able to trigger the ADC conversion by forcing the start of conversion like this:

ADC_forceConversion(myAdc, ADC_SocNumber_0);

//Wait for end of conversion.
while(ADC_getIntStatus(myAdc, ADC_IntNumber_1) == 0){
GPIO_setLow(myGpio, GPIO_Number_3);
}

GPIO_setHigh(myGpio, GPIO_Number_3);

// Clear ADCINT1
ADC_clearIntFlag(myAdc, ADC_IntNumber_1);

// Get temp sensor sample result from SOC1
saidaADC = ADC_readResult(myAdc, ADC_ResultNumber_0);

I have a LED (GPIO_Number_3) blinking after each conversion, but the task stays stuck inside the while loop, meaning that there is some issue with the conversion.

Could it be the start of conversion order before the while loop that's not running?

I'm sorry by posting a question on what seems to be a simple thing, but I wasn't able to find an example of ADC acquisition with software trigger source.

Thanks in advance,

Mário

  • Hi Mario,

    If execution hangs inside the task, it is probably that ADCINT1 is not configured to be triggered from the end of SOC0.  Check your initializations to see if this setting is enabled.

    You can confirm that the ADC is actually taking a sample by using the debugger to halt the program and then checking the ADCRESULT0 register to see if it is non-zero.  

  • Hi Devin,

    thanks a lot for the answer, perhaps there's some mistake in ADC initializations, but I just can figure it out.. Nothing changes in ADCRESULT0.

    The initializations are as follows:

    // Initialize the ADC
    ADC_enableBandGap(myAdc);
    ADC_enableRefBuffers(myAdc);
    ADC_powerUp(myAdc);
    ADC_enable(myAdc);
    ADC_setVoltRefSrc(myAdc, ADC_VoltageRefSrc_Int);

    // Configure ADC
    //ADCINT1 trips after AdcResults latch
    ADC_setIntPulseGenMode(myAdc, ADC_IntPulseGenMode_During);
    //Enabled ADCINT1
    ADC_enableInt(myAdc, ADC_IntNumber_1);
    //Disable ADCINT1 Continuous mode
    ADC_setIntMode(myAdc, ADC_IntNumber_1, ADC_IntMode_ClearFlag);
    //setup EOC1 to trigger ADCINT1 to fire
    ADC_setIntSrc(myAdc, ADC_IntNumber_1, ADC_IntSrc_EOC0);
    //set SOC0 channel select to ADCINA0
    ADC_setSocChanNumber (myAdc, ADC_SocNumber_0, ADC_SocChanNumber_A0);
    //set SOC0 start trigger on Software for SOC0
    ADC_setSocTrigSrc(myAdc, ADC_SocNumber_0, ADC_SocTrigSrc_Sw);
    //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
    ADC_setSocSampleWindow(myAdc, ADC_SocNumber_0, ADC_SocSampleWindow_7_cycles);

    Shouldn't the C code ADC_forceConversion(myAdc, ADC_SocNumber_0)  turn the flag ADCSOCFRC1 to 1?

    I thought it would, but I've used breakpoints to see the registers in debug mode and nothing changes...

    Regards,

    Mário

  • Mario,

    Do you have this line somewhere too?: CLK_enableAdcClock(myClk);

    The ADCSOCFRC1 register can be written, but reads will always return 0.  This will cause the bits in the ADCSOCFLG1 register to be set, but this will only be for a transient period of time.  As soon as the ADC converter sees that bits are set in the ADCSOCFLG1 register, the ADC will start processing those SOCs.  As the SOCs complete, the ADCSOCFLG1 bits are cleared.  Note that this process happens as long as the clock to the ADC is enabled, even if the CPU is halted.  Because of this, if there is a breakpoint after the SOC force is written, by the time you look at the registers in the expressions window, all the ADCSOCFLG bits will be 0 again since the conversions will have been processed by the ADC.  The best thing to look at is the ADCINT flag, if it is enabled, and the ADC result registers.  

  • Hi Devin,

    thanks a lot for the answer, I was missing the command you have sugested: CLK_enableAdcClock(myClk);

    Best regards,

    Mário

  • Mario,

    Great, glad it is working now!