1 full cycle time

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

cross mob
eeEn_4618901
Level 4
Level 4
5 likes given First like received First like given

Hi, In my project with psoc 5LP, how do I find out how many milliseconds or microseconds 1 cycle is completed? int main() {  } for (;;) { function1 (); function2 (); function3 (); } For example, can I find the completion times of functions 1 2 and 3 in the program? Best Regards.

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I just posted the following.

Measuring time interval using SysTick (CY8CKIT-059/CY8CKIT-044)

Although it is not as good as Odissey-san's implementation,  it is simpler.

Meantime, could you see the URL and hopefully would you reply/attach your stopwatch there, too? > Odissey-san

moto

View solution in original post

3 Replies
lock attach
Attachments are accessible only for community members.
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

eeEn,

There is a custom component available to measure elapsed time (StopWatch). Demo project is attached. Import the component into you project or add it into dependencies (see links below). The StopWatch component will show in the Community/Time tab of the Component Catalog panel. Usage is simple:

StopWatch_Start();

// your function here

StopWatch_Stop();

//....

StopWatch_Cycles      returns number of BUS_CLK cycles elapsed between Start and Stop

StopWatch_Reloads    returns number of SysTick counter reloads between Start and Stop

StopWatch_usec         returns number of microseconds elapsed between Start and Stop

StopWatch_msec        returns number of milliseconds elapsed between Start and Stop

StopWatch_sec           returns number of seconds elapsed between Start and Stop

Note that SysTick is only 24-bit counter with maximum value of 0xFFFFFF, which at BUS_CLK of 48 MHz overloads after about 0.35 sec. Accuracy of the StopWatch in this mode is 1 clock. Typically this is sufficient for code profiling. For processes with long time execution the total counts elapsed is: (StopWatch_Counts + StopWatch_Reloads * 0xFFFFFF). Accuracy here slightly decreases due to few clocks skipped by ISR, loosing about 10 bus clocks per each overload.

This is a Draft version of the component, more testing is required, no datasheet available at this time. Works on PSoC5 and PSoC4.

/odissey1

P.S.

https://www.cypress.com/video-library/PSoC-Software/psoc-creator-tutorial-importing-components/10775...

https://www.cypress.com/video-library/PSoC-Software/psoc-creator-tutorial-adding-library-dependency/...

StopWatch_P5_01d_demo_A.png

StopWatch_P5_01d_demo_B.png

MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I just posted the following.

Measuring time interval using SysTick (CY8CKIT-059/CY8CKIT-044)

Although it is not as good as Odissey-san's implementation,  it is simpler.

Meantime, could you see the URL and hopefully would you reply/attach your stopwatch there, too? > Odissey-san

moto

Motoo,

Thank you for posting your method. It gives me an opportunity to to study a callback function.

The above StopWatch component has never moved beyond the draft version, so there is no stand-alone library, it has to be imported from the above demo project. Yet the component was quite useful for me to understand how processor time is spent performing basic operations. I was mostly interested in amount of clock spent in simple actions (ISR or function call and math procedures: multiply, divide, sine, log, etc.), which are typically complete in <1000 clocks. Here the StopWatch provides accuracy of about 1 bus clock. It can be started in one place (e.g. in interrupt body) and stopped in another one (e.g. main loop or even inside a component library). It is not tested for long periods (>24-bit).

Thank you again.

/odissey1