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.

Up the priority of ADC interrupt for TM4C1294?

Other Parts Discussed in Thread: EK-TM4C1294XL

In my experiment/study, I acquire data from ADC (via interrupt mode) then send out the data via USB, but when USB transfers the data to PC, it seems the USB interrupt has a higher default priority and is getting in the way of ADC interrupt once a while, causing a random skew in ADC readings.

I recalled that TM4C1294 can move up the priority of interrupt, but I have trouble locating an example. Can anyone give me the pointer?

Thanks!

  • Hello David

    Which ADC module are you using:0 or 1?

    There is an example in TIVAWare 2.1.0 for interrupt priorities that you may refer to.

    C:\ti\TivaWare_C_Series-2.1.0.12573\examples\boards\ek-tm4c1294xl\interrupts

    Regards

    Amit

  • Under the long stable, robust, "StellarisWare" there existed the function, "IntPrioritySet()" - precisely targeting your issue.  I don't know if that function persists under TivaWare - or specifically under your "special" MCU.

    The "variety" of MCU-based libraries and/or MCU-specific functions is not always easily recognized - nor as free from "issue" as vendor hopes...

  • Are you sure you have enough bandwidth and are not dropping interrupts/interrupt overrun? Just something to sanity check:

    If you run the ADC at 1Ms/sec (12 bit samples) and read out 16 bits (closest native data type), that's 16Mbps but the integrated USB OTG port only operates in Full Speed mode (12Mbps max), you would need to add a High Speed phy using ULPI (480Mbps) or send the data out the ethernet port (100Mbps).

    Here is sample code for sending the data out the ethernet port: http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/331374.aspx

  • Hello David

    Interrupt if enabled in the NVIC will not be dropped unless the code clears the interrupt source outside the scope of the respective interrupt handler

    Also the ADC is a 12-bit ADC and not 16-bit. So at 1Ms/sec it will be 12Mbps. Of course the FS mode will still not be sufficient to move it out.

    Regards

    Amit

  • Hi Amit,

    Yes, the NVIC will not drop the interrupt flag once set but if they are not getting serviced at a high enough rate eventually there will be multiple interrupts to the NVIC. I am referring to that latter problem of not servicing interrupts fast enough.

    The ADC is 12-bit but the smallest native data type it fits into is a uint16_t. Yes, bit shifting can pack 4 x 12 bit samples into 3 x 16 bit values or a multiple of that, but in many cases it is faster to just send out 4 unused bits.

    Thanks for your clarifications!

  • Hello David,

    Yes, if more than one interrupt due to the same cause is logged then it will not be maintaining a count

    Yes, to the second one as well. The byte/half word will be used,

    Regards

    Amit

  • Thank you all for the pointers, I will check out all the issues suggested

  • Amit,

    I am using ADC module 0, sequencer 0, and the data rate is only 60K s/s

    I took a quick tour with the example of C:\ti\TivaWare_C_Series-2.1.0.12573\examples\boards\ek-tm4c1294xl\interrupts, but I am not sure if I understand it correctly.

    According to page 170 of the datasheet, it seems the reset priority is 0, so I did the following in hope to alter the default:

    ROM_IntPrioritySet(INT_ADC0SS0, 0x7);

    ROM_IntPrioritySet(INT_USB0, 0);

    but once USB communication is started, I immediately notice the skew, suggesting the USB interrupt  gets  into the ADC's

    Maybe I didn't do it right?

    Thanks in advance for your pointer!

  • Hello David,

    By default all the interrupts have the same priority (other than the interrupt vector table mapping).

    Consider two interrupts as ADC0SS0 and USB0 where the interrupt number of ADC0SS0 is lower than USB0.

    Case-1: Both have same priority and both interrupt occur together: Then ADC0SS0 will be processed first

    Case-2: USB0 has a priority value less than ADC0SS0 as what you have done and both interrupt occur together: Then USB0 will be processed first.

    I hope that adds clarity.

    Regards

    Amit

  • Hi Amit, Thanks for your quick reply!

    I was not so sure if 7 or 0 has the higher priority, so I tried both but anyway the result was the same

    According to the NVIC video on http://www.ti.com/lsds/ti/microcontroller/tiva_arm_cortex/c_series/overview.page, I should be able to up the priority of ADC and allow its handler to come into action while USB's interrupt is being handled. Do I need to do something special to allow such nesting?

    Again, thanks for your help,

  • Hello David,

    Section 2.5.5 of the data sheet for Exception Priorities, is pretty clear

    "When the processor is executing an exception handler, the exception handler is preempted if a
    higher priority exception occurs. If an exception occurs with the same priority as the exception being
    handled, the handler is not preempted, irrespective of the exception number. However, the status
    of the new interrupt changes to pending."

    So basically it should have processed the ADC Interrupt if the priority is 0 and USB has a priority of 7, while USB is being processed. I can surely check this in my system, but would take some time for me to get back to you.

    Regards

    Amit

  • That was what I expected from the beginning, but the test result seemed to suggest otherwise...

  • Amit, I tried the following codes to see if the priority sticks

    IntPrioritySet(INT_ADC0SS0, 7);

    IntPrioritySet(INT_USB0, 0);

    i=IntPriorityGet(INT_USB0);
    if (i!=0){
    while(1);
    }
    i=IntPriorityGet(INT_ADC0SS0);
    if (i!=7){
    while(1);
    }

    and to my surprise, the priority of INT_ADC0SS0 stays at 0 even though I set it to 7, and the codes hangs in the second while loop.

    What did I do wrong?

    (if the priority can't be raised to higher than USB's, it explains why I always see the skew when USB communication is active)

  • Hi,

    Always when in doubt, first reading is driverlib source code. Here it is what it says about priorities:

    //! \b Example: Set priorities for UART 0 and USB interrupts.
    //!
    //! \verbatim
    //! //
    //! // Set the UART 0 interrupt priority to the lowest priority.
    //! //
    //! IntPrioritySet(INT_UART0, 0xE0);
    //!
    //! //
    //! // Set the USB 0 interrupt priority to the highest priority.
    //! //
    //! IntPrioritySet(INT_USB0, 0);

    Passing short parameters like "7" affects only priority grouping, which is not what you need.

    Try to conform with the above example - us only upper 3 bits to setup a prio...

    Petrei

  • Petrei. Thanks for the pointer! 

    I tried to find the source of IntPrioritySet, but CCS points back to interrupts.h and I thought the source was not provided so I didn't track further...

  • Good catch Petrei. The obvious was missed.