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.

EK-TM4C123GXL: Maximum speed of SysTick interrupt

Part Number: EK-TM4C123GXL

Is there a maximum speed to the SysTick interrupt on a  EK-TM4C123GXL clocked at 16MHz?

Whats odd is at 400Hz, it seems to work fine. When I up the rate to 800Hz I get odd behaviour.

Specifically I've configured the SysTick via:

    // set up the SysTick
    SysTickDisable(); // make sure we are down
    //    SysTickPeriodSet(15999999); // 1s at 16MHz clock
    //SysTickPeriodSet(159999); // 100Hz at 16MHz clock - works
    SysTickPeriodSet(39999); // 400Hz at 16MHz clock  - works
    SysTickIntEnable(); // enable the interupt
    SysTickIntRegister(SysTickIntHandler); // interup calls this function
    SysTickEnable(); // and we are go

The function SysTickIntHandler is:

void
SysTickIntHandler(void)
{
    //
    // Update the Systick interrupt counter.
    //
    g_ui32Counter++;
    double PhItmp=PhI*dPhI-PhQ*dPhQ;
    PhQ=PhQ*dPhI+PhI*dPhQ;
    PhI=PhItmp;
}

Now worried that the double precision phasor couldn't be performed quickly enough, commented that out - but still erratic behaviour.

I'm monitoring whats going on in the main loop:

    while(1)
    {
        //
        // Check to see if systick interrupt count changed, and if so then
        // print a message with the count.
        //
      if(ui32PrevCount != (int)g_ui32Counter/1000)
        {
            //
            // Print the interrupt counter.
            //
            UARTprintf("Number of interrupts: %d\tI=%i\tQ=%i\n",
               g_ui32Counter,(int)(PhI*65536.0),(int)(PhQ*65536.0));
            ui32PrevCount = g_ui32Counter/1000;
        }
    }

So every 1000 interrupts, it prints out where we are - this means that these prints are under 1Hz rate.

Now at 400Hz interrupt - I can see the interrupt count increasing by counts of 1000 - and that is reliable.

At 800Hz interrupt - the count stalls on 3000, and doesn't increase. Half wonder, is that the the UARTprintf can't be performed at 800Hz, and is interrupted by the SysTick? If so - shouldn't this be clean, e.g. when the interrupt complete, does the cpu go back to the UARTprintf and complete it?

Any ideas? I was hoping to increase the interrupt to 10kHz. Where I want that done at accurate 100us intervals, hence why using an interrupt ...

  • And yes it was the UARTfprintf - chaing that to just print the count and Q, and I can clock up at 10kHz.

    Guess the lesson is UARTprintf is slow, maybe I should switch to LED as heartbeat - but hard to get information there (like is Q drifting ...)

  • Hi David,

    Yes the UART output is slow overall and UARTprintf adds extra overhead too.

    At 800Hz interrupt - the count stalls on 3000, and doesn't increase. Half wonder, is that the the UARTprintf can't be performed at 800Hz, and is interrupted by the SysTick? If so - shouldn't this be clean, e.g. when the interrupt complete, does the cpu go back to the UARTprintf and complete it?

    Yeah the UART should continue processing after the interrupt resolves.

    Looking at your Int Handler code, it looks like you have some FPU calculations going on, so I wonder if those are taking enough cycle times that it stalls the UART that way.

    Maybe comment out one or two of those and see the UART goes further. If so, that'd indicate the root cause of the issue?

    Best Regards,

    Ralph Jacobi

  • Yes - I used the UART, to do debugging. Like you, I know that float/double FPU have a huge load - so with interrupt at 10kHz wasn't sure if I could use double but with libm, calculating sine and cosine needed doubles. But yes if this is to slow at 10kHz, then I can either use the single float, and change to the CPU-FPU to do calculations, or change to integer arithmetic.

    I hesitated to do integer arithmetic, as the code am writing I could only do sin and cos at particular angles (if code needs to be very fast) rather than the 3.6 deg that I need to generate the frequency I need.

    With printing just little information on the UART, I managed to get the interrupt working at 10kHz and it helps to do IntPrioritySet(FAULT_SYSTICK,0); so SysTick has good timing.

    So I've managed to keep developing the code, whilst running at 10kHz, and just printing out very little info, which means I can see there is no drift on the sine wave I'm generating.

    I did originally try commenting out the floating point operations in the interrupt, but with  the UART printing a lot of info, it still died. So solution was print out very little information.

    Am just about to move onto the code, that will display information on the LEDs (the gain on my sine wave generation).

    At the moment I'm sticking with doubles, as taking care with the UART, I can see that double are working at 10kHz. When code is finished, I'll probably back out the UART, to take out the overhead.

    Out of interest, is there a fast UART output, like fputc? If so some quick code to print info via fputc would keep thing fast?