4 Replies Latest reply on Jul 7, 2017 12:15 PM by anllc_2271821

    Systick support

      I need Systick support with milliseconds counter and fraction microseconds value.    Is there any support provided with setup and functions/macros like getMillis and getVal ?     Do I need to build my own?    

        • 1. Re: Systick support

          CyLib.h defines the following:


          void CySysTickStart(void);
          void CySysTickInit(void);
          void CySysTickEnable(void);
          void CySysTickStop(void);
          void CySysTickEnableInterrupt(void);
          void CySysTickDisableInterrupt(void);
          void CySysTickSetReload(uint32 value);
          uint32 CySysTickGetReload(void);
          uint32 CySysTickGetValue(void);
          cySysTickCallback CySysTickSetCallback(uint32 number, cySysTickCallback function);
          cySysTickCallback CySysTickGetCallback(uint32 number);


          You can look at the implementation in CyLib.c


          I believe this infrastructure starts a 1ms tick and allows on to register one's own call-backs to be called every ms. There is a note that some components may rely on this functionality so disrupting it will affect their operation. You can also access the SysTick API directly through through the ARM CMSIS API. See, for example core_cm0.h on the PSoC4 and the ARM reference manual for the CortexM0.




          #include "core_cm0_psoc4.h"


          int main(void)
              /* Place your initialization/startup code here (e.g. MyInst_Start()) */
             // SysTick Timer counts down on each tick of 24MHz CPU clock
              SysTick->LOAD = 0x00ffffff;
              SysTick->VAL = 0;
              SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;


          I have not enabled interrupts, I was just using this for timing


           uint32_t   startTick = SysTick->VAL;
          uint32_t    stopTick1 = SysTick->VAL;
          uint32_t    timeDiff = (startTick - stopTick1) & 0xffffffu; // counter is 24-bit; correct for counter wrap-around.


          You can also use a TCPWM module to generate periodic interrupts.





          • 2. Re: Systick support

            From Help->System Reference Guides->cy_boot_component


            For API Details.





            • 3. Re: Systick support

              When needing microseconds resolution I would suggest to set up a timer fed with 1MHz and a divisor of 1000. At interrupt increase a volatile uint64 countervalue. So at any time you can get a tick value with µs accuracy. Use CyEnterCriticalSection() when retrieving timer and counter parts.





              1 of 1 people found this helpful
              • 4. Re: Systick support

                Roger, thank you.   That is what I was looking for, and is plenty lapse time measurement in code segments.


                Bob,  I think for a timing application you are right.    I should have explained I need it just for development environment.   I find having to add/remove a component is a hassle.    I can hide debug code with comments or even defines if I wanted to enable/disable easily.


                Thank you both.