cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

MarkH_61
Employee
        Often I need to time events or execute periodic code from my main loop, but don't want to use additional hardware or use blocking code like CyDelay(). The Cortex M0 and M3 in the PSoC 4 and PSoC 5LP have a nice little built in timer called SysTick. You can set the interrupt period with a wide range of values and it is very useful as a general purpose timer. The SysTimers component attached this post makes use of this timer to run up to 16 parallel non-blocking timers. It is simple to use and can be configured to have a very small (1 line) ISR so not to take up too many CPU cycles. I have attached a workspace that includes the library, and examples for both PSoC4 and PSoC 5LP. Enjoy, Mark   
26 Replies
Anonymous
Not applicable

0 Likes
Anonymous
Not applicable
        I am fairly new to PSoC. How do I incorporate this component into my project?   
0 Likes
HeLi_263931
Honored Contributor II

From memory:

   

Extract the archive to your disk. Open your project, in the workspace explorer select the 'components' tab.

   

On your project node, right click and then 'import componment item'. Select the saved project from above as source project, the you can select the component to import in your project.

   

It should show up under 'community component' in the component list...

0 Likes
Anonymous
Not applicable

Nice work!

   

I'm looking forward to create my own compnents, too. Does anybody know how I can find a tutorial or something else about this? It´s  difficult for me.

   

Regards,

   

Flo

0 Likes
ETRO_SSN583
Esteemed Contributor

Take a look here, videos, docs -

   

 

   

http://www.cypress.com/?rID=40410

   

 

   

http://www.cypress.com/?id=4&rID=54777

   

 

   

http://www.cypress.com/psoccreator/     Look at the various tabs, documentation.....

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Thank you very much!

   

Regards, Flo

0 Likes
Anonymous
Not applicable

When compiling in RELEASE, i get the following warnings:

   

.\Generated_Source\PSoC5\SysTimers_1.c:352:29: warning: array subscript is above array bounds [-Warray-bounds]
.\Generated_Source\PSoC5\SysTimers_1.c:353:29: warning: array subscript is above array bounds [-Warray-bounds]

   

I think the index range in the for() loop inside _ReleaseAllTimers is incorrect:

   

    for(index = 1; index <= SysTimers_1_TIMERS; index++)

   

Should be:

   

    for(index = 0; index < SysTimers_1_TIMERS; index++)

   

Very helpful component anyway 🙂

   

 

   

Andreas

0 Likes
MarkH_61
Employee

Here is an updated version of SysTimers.  Fixed a couple bugs, added a few more timer resolutions, and updated the data sheet.

   

 

   

Mark

0 Likes
timoc_264486
New Contributor II
        First, thanks for the component. It is just what I needed. Second there is a discrepancy. For the Parameter Information in the Config SysTimers dialog the Number_of_Timers says 1 to 8 but the datasheet and the dropdown agree it is 2 to 16. Just thought you might want to fix this the next time you post an update (if ever).   
0 Likes
StSi_284576
New Contributor II

Hi Mark,

   

I very happily found your SysTimers component. This is exactly what I needed.

   

But because I'm using a PSoC 3, I added a PSoC 3-specific implementation using a Timer component instead of the PSoC 5-native SysTicks feature.

   

I also added some CriticalSection locks which are imho necessary.

   

Please find the updated code attached.

   

Thank you,

   

Best regards,

   

Stefan

0 Likes
StSi_284576
New Contributor II

ok, here is the file hopefully...

0 Likes
RaAl_264636
Contributor II
        Hi, one question about the SysTick clock source. I'm working with PSoC4. The definition for `$INSTANCE_NAME`_SYSTICK_PERIOD uses the definition for HFCLK - shouldn't it be SYSCLK? I couldn't figure out if HFCLK or SYSCLK is the clock provided to the MCU core, but since SYSCLK can be a divided value of HFCLK I'd assume that SYSCLK is the core clock. Now, if SYSCLK is divided the definition for `$INSTANCE_NAME`_SYSTICK_PERIOD might result in wrong values. Is this true? Regards, Ralf   
0 Likes
MarkH_61
Employee

Ralf,

   

You are correct.  Not sure what I was thinking at the time, but here is an updated version.

   

 

   

Mark

RaAl_264636
Contributor II
        Hi Mark, glad that I could help to improve it 🙂 Regards, Ralf   
0 Likes
AnCo_2736831
Contributor

Hello

This demo project works well. Now when I tried to introduce the systimer in another project it does recognize systime. I am not able to install systimer on my topdesign. There is no component systimer exist on my updated psoc creater. Is it a user component? How to transfer the component?

Thanks

0 Likes
MarkH_61
Employee

To use the SysTimer component in your own project, right click on your project under the workspace window on the left.  Select "Dependencies...".  Under "User Dependencies" select the folder icon then navigate to the location where the library is stored.  The folder will be "SystemTimers.cylib" and inside there will be the file "SystemTimers.cyprj", select it, hit "OK" on the bottom of the Dependencies pop-up window.  You should now see a "Community" tab in the Component Catalog window on the right.  I usually keep all my custom libraries in one common place so they don't get lost.

Mark

AnCo_2736831
Contributor

Thank you. It works.

0 Likes
AnCo_2736831
Contributor

In the example if I want only 2 times to blink, how to stop the loop. The following program did not work.

for(count=1;count<4;count++)

    {

        if( SysTimers_GetTimerStatus(green_timerID))

{

    P02_Green_Write(P02_Green_Read() ? 0 : 1);  // Toggle Green

    }

}

0 Likes
MarkH_61
Employee

The SystemTimer will only tell you if a period has expired.  If you want something to only occur for n periods, you will have to implement that counter yourself.  I have been thinking of adding callback functions, but you want these functions to be very small and quick. The user's callback function would have it's own counter so it would know that it would only occur n times then kill it's own timer.  This way if you just wanted to toggle an LED n times, your callback function would know this and it would do this automatically in the ISR.  Hmmm maybe I will add the callback function as an option, might be more useful than I was thinking.

Mark

0 Likes
AnCo_2736831
Contributor

Thanks Mark. That will be useful.

0 Likes
StSi_284576
New Contributor II

Hi all,

   

here is an important fix for the updated component that I posted in February.

   

Please update the initialization code in Start() to:

   

 

   

(...)

   

#if CY_PSOC3
    #if `$INSTANCE_NAME`_SYSTICK_PERIOD <= 65536
        `$INSTANCE_NAME`_SysTick_Timer_Init();
        `$INSTANCE_NAME`_SysTick_Timer_WritePeriod(`$INSTANCE_NAME`_SYSTICK_PERIOD-1);
        `$INSTANCE_NAME`_SysTick_Timer_Enable();
    #else
        #error SysTimers (instance `$INSTANCE_NAME`): Invalid timer resolution. Use a higher resolution please!
    #endif
#else
    SysTick_Config(`$INSTANCE_NAME`_SYSTICK_PERIOD);
#endif
(...)

   

Best regards,

   

Stefan

0 Likes
MarkH_61
Employee

Attached to the post is version 3.0 of my SysTimers component.  I have added callback functions to the timers as an option.  I find the callbacks handy for simple quick periodic functions I don't want to deal with in my main loop.  For example, blinking an LED at a 2 Hz rate, Blink an LED for 5 times then stop, or scan a button or keypad.  Since these callbacks execute in an ISR they should be kept small.

I have attached two documents, "SysTimers.cylib.zip" which is just the library, and "SysTimersDemo2.zip" that contains a couple examples and the library.  Both the library and the demos were generated with PSoC Creator 4.2.  The demo "SysTimers_PSoC4_RGB_Demo" blinks the RGB LED on the pioneer board without callback functions.  Demo "SysTimers_PSoC4_RGB_Demo_wCB" is the same demo but with the use of callback functions.

Enjoy,

Mark

AlanH_86
Employee

I assume that you know that the systick firmware that comes it PSoC4 has 4 builtin callbacks...

And people can read about the APIs in chapter 12 of the System Reference Guide.

0 Likes
MarkH_61
Employee

Yes I know about the systick APIs in the PSoC library.  When I originally wrote the component, they did not exist.  I now allow the user to replace the standard SysTick ISR or to just put the SysTimer ISR as one of the 4 entries.  The sysTimer component is really for events that occur at a slower rate than SysTick period.  The SysTimer callbacks may only be executed once ever 10 seconds if you want.  In the Fast mode it just handles the math for you with very little overhead at the SysTick ISR. 

It was never meant as a replacement for the SysTick APIs.  I use SysTimer Component for my own non-RTOS based projects and thought that other people might have a use for it as well.

Mark

0 Likes
GeEd_1216226
New Contributor II

I have been trying to use this with PSoC 6, and the cytypes.h is a problem.  I am not a greatly experienced Cypress dude, so is this component/library suitable for PSoC 6 or do I need to make major modifications? 

0 Likes
AjBa_3976296
New Contributor II

Thanks Mark!

0 Likes