Tip / ログイン to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

Traveo IIファミリのソフトウェア実行時間の測定 – KBA230552 - Community translated(JA)

Traveo IIファミリのソフトウェア実行時間の測定 – KBA230552 - Community translated(JA)

JennaJo
Moderator
Moderator
Moderator
1000 replies posted 750 replies posted 500 replies posted

Original KBA: Measurement of Software Execution Time in Traveo II Family – KBA230552

Translated by: Kenshow

作者:ShusakuS_56          バージョン:**

質問:

一部のソフトウェアの実行時間を知りたいです。デバッガを使わずに実行時間を測定する方法はありますか?

回答:

ハードウェアタイマ(TCPWM)を使用して、ソフトウェアのおおよその実行時間を測定できます。ここに「HelloWorld」のコードスニペットがあります。

コード1.オリジナルの「HelloWorld

#include <stdio.h>

int main() {

    printf("Hello World");

    return 0;

}

ソフトウェアの実行時間を測定するには、「HelloWorld」コードに次の変更を加えます。

  1. 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)

TCPWM0_GRPx_CNTx_COUNTER->unTR_CMD.stcField.u1STOP = 0x01;        // Timer Stop Command (If Timer is Starting)

TCPWM0_GRPx_CNTx_COUNTER->unCOUNTER.u32Register = 0UL;                // Timer Counter Clear Command

TCPWM0_GRPx_CNTx_COUNTER->unTR_CMD.stcField.u1START = 0x01;      // Timer Start Command

    printf("Hello World");

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

TCPWM0_GRPx_CNTx_COUNTER->unTR_CMD.stcField.u1STOP = 0x01;        // Timer Stop Command

// Read and Save the counter value

    uint32_t TimerCount = Cy_Tcpwm_Counter_GetCounter(TCPWM0_GRPx_CNTx_COUNTER);

  :

// If you need, restore interrupt status

Cy_SysLib_ExitCriticalSection(saveIntrEnabled);                  // Interrupt Restore Previous Status

    return 0;

}

  1. 次に対応するTCPWMのタイマ値を読み取るコマンドを追加します。このタイマ値は、クロック数をカウントします。したがって、ソフトウェアの実行時間は次のように計算できます。

     【例】クロック周波数= 20 MHz、TimerCountの値= 0xF000(0d61440)

測定時間をより正確にするために、以下の対策を講じてください。

  1. クロック速度を上げます。
  2. カウンターを起動してから停止するまでの時間を測定します。次に、カウント値から減算します。次にその例を示します。

#include <stdio.h>

int main() {

  :

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

TCPWM0_GRPx_CNTx_COUNTER->unTR_CMD.stcField.u1STOP = 0x01;        // Timer Stop Command (If Timer is Starting)

TCPWM0_GRPx_CNTx_COUNTER->unCOUNTER.u32Register = 0UL;                // Timer Counter Clear Command

TCPWM0_GRPx_CNTx_COUNTER->unTR_CMD.stcField.u1START = 0x01;      // Timer Start Command

    printf("Hello World");

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

TCPWM0_GRPx_CNTx_COUNTER->unTR_CMD.stcField.u1STOP = 0x01;        // Timer Stop Command

// Read and Save the counter value

    uint32_t TimerCount = Cy_Tcpwm_Counter_GetCounter(TCPWM0_GRPx_CNTx_COUNTER);

  :

// Measure the time from starting the counter to stopping

TCPWM0_GRPx_CNTx_COUNTER->unCOUNTER.u32Register = 0UL;                // Timer Counter Clear Command

TCPWM0_GRPx_CNTx_COUNTER->unTR_CMD.stcField.u1START = 0x01;      // Timer Start Command

TCPWM0_GRPx_CNTx_COUNTER->unTR_CMD.stcField.u1STOP = 0x01;    // Timer Stop Command

    uint32_t SwOffsetCount = Cy_Tcpwm_Counter_GetCounter(TCPWM0_GRPx_CNTx_COUNTER);

    uint32_t TimerCountDuringHelloWorld = TimerCount – SwOffsetCount;

    return 0;

}

:このKBAは、次のTraveo II MCUに適用されます。

  • CYT2Bシリーズ
  • CYT4Bシリーズ
  • CYT4Dシリーズ
0 件の賞賛
668 件の閲覧回数