AnsweredAssumed Answered

How do I configure the TWR-K24 for software triggered ADC sampling?

Question asked by Wolfe on Dec 9, 2015
Latest reply on Dec 13, 2015 by xiangjun.rong



I am trying to set up the K24 for single, software triggered ADC sampling.  I have looked through the ADC example in the SDK for this board, as well as a couple other user examples, and tried to adapt them as best I could to what I want to do.  Below is some modified code from the ADC example.


void ADC16_Measure(void)


    // Software trigger the conversion.

    ADC16_DRV_ConfigConvChn(FSL_ADCONV1, ADC16_CHN_GROUP, &adConv1_ChnConfig0);


    // Wait for the conversion to be done.



    // Fetch the conversion value.

    adcValue = ADC16_DRV_GetConvValueSigned(FSL_ADCONV1, ADC16_CHN_GROUP);


    // Show the current temperature value.

    //printf("\r\n ADC converted value: %ld\t", adcValue );

    // Calculates adcValue in 16bit resolution

    // from 12bit resolution in order to convert to temperature.


    adcValue = adcValue << 4;




The actual configuration should be handled by the processor expert, so I deleted the initialization lines.  All of this code runs fine, but when some time after the method returns, the program gets stuck in the default ISR.  Here is a code snippet of my main where I call the ADC sample method, and the assembly routine starting at "read2"


int main(void) {


    /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/



    /*** End of Processor Expert internal initialization.                    ***/

    const uint8_t gateDelay = 5;


    for (;;) {

        ra = gateDelay;    //Load the gate delay into r0, used in StartTiming routine

        __asm("bl StartTiming");

        //Read sample 1 from ADC here


        __asm("bl read2");






    movw r3, #0x1000    // bit mask for GPIO

    str r3, [r2, #8]    // Clears GPIO

    nop                    // Delay 8ns/nop



Basically, I am running an assembly routine, and at several points I need to return to main from the routine to grab an ADC sample.  The program is able to run the ADC code and re-enter the assembly routine at the label "read2" using branch and link, but then a few instructions after "read2" the program gets stuck in the default ISR.  I'm reasonably sure the assembly code has nothing to do with it, since the instruction where it hangs is the first nop.


Here is the config screen for the PE fsl_adc16 module: