Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

Measurement of software execution time in XMC7000 family- KBA234432

Measurement of software execution time in XMC7000 family- KBA234432

LinglingG_46
Moderator
Moderator
Moderator
10 questions asked 5 questions asked 250 sign-ins

Measurement of software execution time in XMC7000 family- KBA234432

Question

I want to know the execution time of some software. Is there a method to measure the execution time without using a debugger?

 

Answer

You can measure the approximate software execution time using the hardware timer (TCPWM). Here is the code snippet for "Hello World".

Code 1.     Original “Hello World”

#include <stdio.h>

int main() {

    printf("Hello World");

    return 0;

}

To measure software execution time, make the following modifications to the “Hello World” code:

  1. Add the TCPWM timer start command and the TCPWM timer stop command before and after printf ("Hello World").

Code 2 Adding TCPWM Timer Start and Timer Stop Commands

#include <stdio.h>

int main() {

// Initialize Clock Divider and TCPWM (For more details, please see Technical Reference Manual)

  :

// If you need, please Enter Critical section to avoid any interrupt during measurement.

    uint32_t saveIntrEnabled = Cy_SysLib_EnterCriticalSection();    // Interrupt Disable & Save Current Status

  :

// Timer Stop/Clear/Start (Please use INLINE function to reduce software offset like below)

    Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_CNT_NUM);  // Timer Stop Command (If Timer is Starting)

    Cy_TCPWM_PWM_SetCounter(TCPWM0, MY_TCPWM_CNT_NUM,0);            // Timer Counter Clear Command

    Cy_TCPWM_TriggerStart_Single(TCPWM0, MY_TCPWM_CNT_NUM);     // Timer Start Command

    printf("Hello World");

// Timer Stop (Please use INLINE function to reduce software offset like below)

    Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_CNT_NUM);      // Timer Stop Command

// Read and Save the counter value

    uint32_t TimerCount = Cy_TCPWM_PWM_GetCounter(TCPWM0, MY_TCPWM_CNT_NUM);

  :

// If you need, restore interrupt status

    Cy_SysLib_ExitCriticalSection(saveIntrEnabled);           // Interrupt Restore Previous Status

    return 0;

}

       2.Then, add a command to read the timer value of the corresponding TCPWM. This timer value counts the number of clocks. Therefore, the software execution time can be calculated as:

Example:

Clock Frequency = 25 MHz, Value of TimerCount = 0x0F98 (0d3992)

( 1/25MHz)x3,992=40nsX3,992=159.680us

To make the measurement time more accurate, take the following measures.

  1. Increase clock speed.
  2. Measure the time from starting the counter to stopping it. Then, subtract from the count value. Here is an example:

    #include <stdio.h>

    int main() {

      :

     

    // Timer Stop/Clear/Start (Please use INLINE function to reduce software offset like below)

        Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_CNT_NUM);  // Timer Stop Command (If Timer is Starting)

        Cy_TCPWM_PWM_SetCounter(TCPWM0, MY_TCPWM_CNT_NUM,0);            // Timer Counter Clear Command

        Cy_TCPWM_TriggerStart_Single(TCPWM0, MY_TCPWM_CNT_NUM);     // Timer Start Command

        printf("Hello World");

    // Timer Stop (Please use INLINE function to reduce software offset like below)

        Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_CNT_NUM);      // Timer Stop Command

    // Read and Save the counter value

        uint32_t TimerCount = Cy_TCPWM_PWM_GetCounter(TCPWM0, MY_TCPWM_CNT_NUM);

      :

    // Measure the time from starting the counter to stopping

        Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_CNT_NUM);  // Timer Stop Command (If Timer is Starting)

        Cy_TCPWM_PWM_SetCounter(TCPWM0, MY_TCPWM_CNT_NUM,0);            // Timer Counter Clear Command

        Cy_TCPWM_TriggerStart_Single(TCPWM0, MY_TCPWM_CNT_NUM);     // Timer Start Command

        uint32_t SwOffsetCount = Cy_TCPWM_PWM_GetCounter(TCPWM0, MY_TCPWM_CNT_NUM);

        uint32_t TimerCountDuringHelloWorld = TimerCount – SwOffsetCount;

        return 0;

    }

Attachments
0 Likes
77 Views