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:
// your function here
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.
1 of 1 people found this helpful
I just posted the following.
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
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.