Announcements
IMPORTANT: Cypress Developer Community is transitioning on October 20th. To learn more and be prepared for this change, check out our latest announcement.
cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable

I want an approximate time in seconds between 2 calls of a routine.

   

I don't need a lot of accuracy and I don't have any UDBs to spare for this trivial function. I have a function that can take from a few seconds to an hour or more of time to complete and want a gross measurement of the time that has passed by.

   

I tried using the clock() and the time() functions in C after including time.h but these functions always return -1 indicating an "error".

   

Is there some way to get these functions to work?

   

Can I use the ARM TICTIMER somehow?

   

 

   

For now I'm using a FF timer which at least doesn't use any UDBs but I would like to just use clock().

0 Likes
10 Replies
ETRO_SSN583
Esteemed Contributor

ARM Systick with an interrupt incing a count variable one solution.

   

 

   

    

   

          http://www.cypress.com/?rID=38267     AN54460

   

 

   

Some DSO scopes have extended time bases to handle long events,

   

so use a pin to trigger start, and its other edge to stop to measure.

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Esteemed Contributor

This might help as well -

   

 

   

    

   

          http://www.cypress.com/?app=forum&id=2233&rID=49587

   

 

   

You could alwyas use a pin and and gate an external period counter.

   

It would have to be a reciprocal counter or have that capability.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 If you have a spare pin. You can sent one pulse on one routine and send 2 pulses on the other. Then you can use a CRO to capture the pulse to check the time between them.  and also check for variation by recording the pulse over a longer time as well.

0 Likes
ETRO_SSN583
Esteemed Contributor

Check your CRO (DSO), most, not all, have max sweep rates < 10 sec/div,

   

therefore cannot measure 1 hour (3600 sec)/360 dvision) events. In that

   

case you would be better off with a datalogger, or use another psoc to

   

measure extended periods. Any PSOC could do that.

   

 

   

If I am not mistaken hli posted a reciprocal frequency counter some time ago

   

on the forum, that could be the basis of a long period measurement system.

   

 

   

Attached info on reciprocal counters.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Silly me. I always think time being task in sub-second range.

0 Likes
Bob_Marlowe
Expert II

Nice documentation, although reading them all took me some time.

   

 

   

Bob

0 Likes
HeLi_263931
Honored Contributor II

You can also use a timer. To clock it at 1 Hz, use a 'global signal' component, which can give you a PPS. Then you can start and stop the timer whenever want, and read the elapsed time in seconds directly.

   

Or you attach a 32 kHz crystal and use the RTC component (but it doesn't have the notion of unix time, so you need to do the calculations on your own).

0 Likes
ETRO_SSN583
Esteemed Contributor

I think he is out of UDBs.........maybe systick if thats not already in use.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Thanks for the answers guys!

   

But I can't seem to find any real documentation on the systick timer.

   

I know it is part of the ARM and there appears to be a few API calls but I can't find the description.

   

http://www.cypress.com/?docID=44506 has a sample project and a few other links to documents like the cy_boot project? But that has exactly 1 reference to systic and does not describe the API at all.

   

Several links bring me http://www.cypress.com/?app=forum&id=2233&rID=49587 but this is another guy trying to get the systic to work... not sure he ever did.

   

The ARM documention on SysTick is:http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0179b/ar01s02s08.html which is good but doesn't give the specifics of how to select the clock and what various things are selected and how to start it.

   

I think I can just read the systick_current register at 0xE000E018 at the start and subtract that from the value at the end. I assume it's a 32-bit number so should have plenty of resolution.

   

I shouldn't need an interrupt to count - I just need this counter running on the 1Khz ILO gives me over 1000 hours. The ILO is -55%/+100% which isn't quite as accurate as I'd like but probably close enough. I could also use the systick interrupt to make a 1 sec interrupt with +/-3% accuracy and then count seconds with that.

   

 

   

I am completely out of UDBs (about to post about that as well) so this needs to be a 100% CPU function. Again, I don't need much accuracy - just a rough wall-clock #.

0 Likes
ETRO_SSN583
Esteemed Contributor

This should help -

   

 

   

     http://www.cypress.com/?app=forum&id=2492&rID=85773         

   

 

   

Regards, Dana.

0 Likes