One cycle of main (time)

A catchall for PSoC Mixed-Signal Array (microcontroller) discussions not captured by the other forums.

Moderator: ericb

One cycle of main (time)

Postby Mipo01 » Thu Jan 09, 2014 7:06 am

Hi guys,

I know that my chip is running on 24 MHz that means execution of one instruction takes cca 42ns. But how could I figure out what is the time needed to run one main while loop? I dont think count number of instruction is the right way :-P or is it???
Mipo01
Bite-Size Cheese
Bite-Size Cheese
 
Posts: 16
Joined: Wed Oct 30, 2013 5:41 am

Re: One cycle of main (time)

Postby bobmarlowe » Thu Jan 09, 2014 7:13 am

You could measure the time with a logic analyzer when you toggle an output pin each run of the main-loop.


Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: One cycle of main (time)

Postby Mr_E » Thu Jan 09, 2014 8:37 am

Mipo01 - keep in mind that on the PSOC1 core, instructions take a minimum of 4 clock cycles to execute. This varies by instruction, see "Instruction Set Summary" on p122 of "Assembly Language User Guide" for specific clock cycles. If you figure an average of 6 cycles per instruction, then at 24Mhz you are effectively getting 4MIPS (million instructions per second).

As Bob says, toggling an output pin once for each pass through the main loop will give you an idea of how busy the processor is. Look for the longest delay between edge transitions on your scope or logic analyzer - this is your worst case delay. Is that acceptable? If not, look at using an interrupt to service time sensitive functions. Keep in mind interrupts will slow down your main run loop slightly and will cause variable delays in the main run loop. Most functions are not timing sensitive, so this isn't a problem.

For us, I have found that as long as the main run loop stays below 10ms, everyone is happy. I shoot for 1ms so I can guarantee the 10ms.
Watch out for blocking functions, such as those that write to UARTs, I2C, and LCD drivers. A lot of times these functions will sit and spin until they are done, stopping the processor from doing other useful work. I frequently recode these functions to poll the status instead (takes a little longer for them to complete), or code them in interrupts.

-Mr_E
User avatar
Mr_E
The Big Cheese
The Big Cheese
 
Posts: 297
Joined: Wed Aug 11, 2004 7:08 am
Website: http://www.microframecorp.com
Location: Oklahoma, USA

Re: One cycle of main (time)

Postby Mipo01 » Fri Jan 10, 2014 1:21 am

Thank you guys for very helpful explanation ;)
I will try it with a pin :-)
:wink:
Mipo01
Bite-Size Cheese
Bite-Size Cheese
 
Posts: 16
Joined: Wed Oct 30, 2013 5:41 am

Re: One cycle of main (time)

Postby danadak » Sun Jan 12, 2014 5:36 pm

If you need a precise time you can look at the .lst file, and count instruction
cycles to get exact time, including and code inside of main(). Note that
becomes more involved if you are calling functions inside main().

Regards, Dana.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 2008
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire


Return to “%s” PSoC1 General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest