Measurement of software execution time in XMC7000 family- KBA234432

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

cross mob
NXTY_Shirakawa
Level 3
Level 3
Distributor - NEXTY (Japan)
10 replies posted 10 likes given 5 likes given

Hi, Can I translate "Measurement of software execution time in XMC7000 family- KBA234432" into Japanese, please confirm to my work??

Regards,

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
NXTY_Shirakawa
Level 3
Level 3
Distributor - NEXTY (Japan)
10 replies posted 10 likes given 5 likes given

Question

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

 

Answer

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

Code 1.     Original “Hello World”

#include <stdio.h>

int main() {

    printf("Hello World");

    return 0;

}

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

  1. TCPWM タイマー開始コマンドと TCPWM タイマー停止コマンドを 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.次に、対応する TCPWM のタイマー値を読み取るコマンドを追加します。 このタイマー値は、クロック数をカウントします。 したがって、ソフトウェアの実行時間は次のように計算できます。

Example:

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

( 1/25MHz)x3,992=40nsX3,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;

    }

 

View solution in original post

0 Likes
3 Replies
IFX_Publisher2
Community Manager
Community Manager
Community Manager
25 likes received 1000 replies posted First like given

Hi, Shirakawa san,

Confirm to work on this KBA

Thanks,
Bindu

0 Likes
lock attach
Attachments are accessible only for community members.
NXTY_Shirakawa
Level 3
Level 3
Distributor - NEXTY (Japan)
10 replies posted 10 likes given 5 likes given

Question

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

 

Answer

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

Code 1.     Original “Hello World”

#include <stdio.h>

int main() {

    printf("Hello World");

    return 0;

}

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

  1. TCPWM タイマー開始コマンドと TCPWM タイマー停止コマンドを 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.次に、対応する TCPWM のタイマー値を読み取るコマンドを追加します。 このタイマー値は、クロック数をカウントします。 したがって、ソフトウェアの実行時間は次のように計算できます。

Example:

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

( 1/25MHz)x3,992=40nsX3,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;

    }

 
0 Likes
IFX_Publisher2
Community Manager
Community Manager
Community Manager
25 likes received 1000 replies posted First like given

Hi,Shirakawa san,

Confirmed to receive this KBA.

Thank you for your contribution.

Thanks,
Bindu

0 Likes