Measuring cycles using DTW on PSoC 6(M4)

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

cross mob
lock attach
Attachments are accessible only for community members.
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi,

If the debug tool does not have the feature for counting the number of cycles (for example, PSoC Creator and ModusToolbox), there are several ways to measure with the timer as follows

  • GPIO output + oscilloscope

GPIO is output as High / Low and measured with an oscilloscope. It is effective when measuring a long time.

  • Systick timer

It is effective when simply measuring the number of cycles, but it may be used in other time-related APIs.

  • DWT (data watchpoint and trace)

It is an ARM emulation function for cortex M3/M4 and can be used when the debugger is not using it.

  • Peripheral timer (Clk_timer)

Slower than CPU frequency.

  • CP15 time stamp counter

Available on ARM Cortex A and R, but not Cortex M.

In this time, I attached a sample of Cycle measurement using DWT which would be not used often. Please use it if you are interested.

Note: DWT can only be measured from Debugging of PSoC Creator.

SampleCode:

The program just calls the DWT counter value for the function you want to measure in main_cm4.c based on the sample program of "CE223001-PSoC 6 MCU UART printf" and calculates the difference. the key points of this program as below.

DWT registers

#define DWT_CTRL          0xE0001000

#define DWT_CYCLE_COUNT   0xE0001004

DWT setting

(*(int*)DWT_CTRL) |= 0x1; // Counter enable

(*(int*)DWT_CYCLE_COUNT) = 0; // Set counter to Zero

Call DWT counter

SysCntVal = (*(int*)DWT_CYCLE_COUNT);

CyDelay(10); // API to be measured

SysCntVal = (*(int*)DWT_CYCLE_COUNT) - SysCntVal;

I checked this program on PSoC 6 BLE Pioneer Kit CY8CKIT-062-BLE.

Thanks,

Kenshow

4 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

NoTa,

Does it going to work on PSoC5 and PSoC4?

/odissey1

0 Likes
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi odissey1,

This feature is on ARM Cortex M3 and M4.

Unfortunately, PSoC 4 is not available.

I am not sure  about PSoC 5 because I don't have the board.

I would be grateful if someone could confirm with PSoC 5.

Thanks,
Kenshow

0 Likes
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi,

Originally, DWT is a function used by the debug tool. It is used for cycle measurement between breakpoints and profiling functions, and is used by third party debug tools.

I hope Modus Toolbox and PSoC Creator will be able to display cycle counts using this feature.

Thanks,

Kenshow

0 Likes
Takashi_M
Moderator
Moderator
Moderator
1000 replies posted 500 solutions authored 750 replies posted

Dear Kenshow-san,

We appreciate your contribution for this.

Best regards.