Measurement of software execution time in XMC7000 family

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

cross mob
NXTY_hayashi
Level 5
Level 5
Distributor - NEXTY (Japan)
25 solutions authored 50 replies posted 25 likes received

Hi,

I want to translate the following article into Japanese, please confirm to my work.
URL:https://community.infineon.com/t5/Knowledge-Base-Articles/Measurement-of-software-execution-time-in-...

Best Regards,
Kazunari Hayashi

0 Likes
1 Solution
NXTY_hayashi
Level 5
Level 5
Distributor - NEXTY (Japan)
25 solutions authored 50 replies posted 25 likes received

Q: プログラム一部の処理時間を知りたい。デバッガを使わずに実行時間を測定する方法はありますか?

A: ハードウェアタイマ(TCPWM)を使用して、ソフトウェアのおおよその処理時間を測定することができます。以下は、"Hello World "のコード例です。

コード1 オリジナルのコード

#include <stdio.h>

int main() {

    printf("Hello World");

    return 0;

}

 

プログラムの処理時間を測定するために、「Hello World」のコードを以下のように修正する。
printf ("Hello World")の前後にTCPWMタイマースタートコマンドとTCPWMタイマーストップコマンドを追加する。

コード2 TCPWMタイマーで処理時間を計測する

#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;

}

 

次に、対応するTCPWMのタイマ値を読み出すコマンドを追加します。このタイマ値は、クロック数をカウントしています。プログラムの処理時間は、次のように計算できます。

例)クロック周波数25MHz、TimerCountの値0x0F98 (10進数で3992)
         計算式 ( 1/25MHz ) x 3,992 = 40ns x 3,992 = 159.680us

測定の精度をより上げるには、

  1. クロック速度を上げる
  2. タイマ処理に必要な時間をオフセットとして引く

ことが有効です。以下はその例です。

#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;

}

 

TCPWM_TIME.zip

View solution in original post

0 Likes
3 Replies
IFX_Publisher2
Community Manager
Community Manager
Community Manager
1000 replies posted First like given 750 replies posted

Hi Kazunari Hayashi san,

Confirm to work on this KBA.

Thanks,
Bindu

0 Likes
NXTY_hayashi
Level 5
Level 5
Distributor - NEXTY (Japan)
25 solutions authored 50 replies posted 25 likes received

Q: プログラム一部の処理時間を知りたい。デバッガを使わずに実行時間を測定する方法はありますか?

A: ハードウェアタイマ(TCPWM)を使用して、ソフトウェアのおおよその処理時間を測定することができます。以下は、"Hello World "のコード例です。

コード1 オリジナルのコード

#include <stdio.h>

int main() {

    printf("Hello World");

    return 0;

}

 

プログラムの処理時間を測定するために、「Hello World」のコードを以下のように修正する。
printf ("Hello World")の前後にTCPWMタイマースタートコマンドとTCPWMタイマーストップコマンドを追加する。

コード2 TCPWMタイマーで処理時間を計測する

#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;

}

 

次に、対応するTCPWMのタイマ値を読み出すコマンドを追加します。このタイマ値は、クロック数をカウントしています。プログラムの処理時間は、次のように計算できます。

例)クロック周波数25MHz、TimerCountの値0x0F98 (10進数で3992)
         計算式 ( 1/25MHz ) x 3,992 = 40ns x 3,992 = 159.680us

測定の精度をより上げるには、

  1. クロック速度を上げる
  2. タイマ処理に必要な時間をオフセットとして引く

ことが有効です。以下はその例です。

#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;

}

 

TCPWM_TIME.zip

0 Likes
IFX_Publisher2
Community Manager
Community Manager
Community Manager
1000 replies posted First like given 750 replies posted

Hi, Kazunari Hayashi -san

Confirmed to receive this KBA.

Thank you for your contribution.

Thanks,
Bindu

0 Likes