3 Replies Latest reply on Apr 19, 2020 6:38 PM by MoTa_728816

    1 full cycle time

    eeEn_4618901

      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.

        • 1. Re: 1 full cycle time
          BoTa_264741

          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/107756

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

           

           

          StopWatch_P5_01d_demo_A.png

          StopWatch_P5_01d_demo_B.png

          • 2. Re: 1 full cycle time
            MoTa_728816

            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

            1 of 1 people found this helpful
            • 3. Re: 1 full cycle time
              BoTa_264741

              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