- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
測定の精度をより上げるには、
- クロック速度を上げる
- タイマ処理に必要な時間をオフセットとして引く
ことが有効です。以下はその例です。
#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; } |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Kazunari Hayashi san,
Confirm to work on this KBA.
Thanks,
Bindu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
測定の精度をより上げるには、
- クロック速度を上げる
- タイマ処理に必要な時間をオフセットとして引く
ことが有効です。以下はその例です。
#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; } |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Kazunari Hayashi -san
Confirmed to receive this KBA.
Thank you for your contribution.
Thanks,
Bindu