Time to process a command in PSoc 5LP

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
LaHa_4843721
Level 1
Level 1
5 likes given First like received First like given

Hello everyone,

As the title i would love to know how long does it take for PSoC 5LP to process a command?

Thanks,

Hai Lai

0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Hai Lai,

That can be a complex question.

A 'command' or opcode will will execute depending on your BUS_CLK frequency.   On the PSoC5LP this can be a maximum of 80MHz.

Depending if an opcode needs to read or write to EEPROM or peripheral device could slow down the execution speed.

Ultimately, what are you trying to determine?   If you're just trying to determine how long it takes to execute a function, there are better methods.   One method is to place a framing pulse using a GPIO pin before and after the function.

For example:

main()

{

...

Pin_0_0_Write(1);     // Turn on the GPIO pin

function_2_time();     // This is the function to time

Pin_0_0_Write(0);     // Turn off the GPIO pin

...

}

Use an scope to determine the timing of the pulse width.  This is the timing of the function.

Len

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

8 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Hai Lai,

That can be a complex question.

A 'command' or opcode will will execute depending on your BUS_CLK frequency.   On the PSoC5LP this can be a maximum of 80MHz.

Depending if an opcode needs to read or write to EEPROM or peripheral device could slow down the execution speed.

Ultimately, what are you trying to determine?   If you're just trying to determine how long it takes to execute a function, there are better methods.   One method is to place a framing pulse using a GPIO pin before and after the function.

For example:

main()

{

...

Pin_0_0_Write(1);     // Turn on the GPIO pin

function_2_time();     // This is the function to time

Pin_0_0_Write(0);     // Turn off the GPIO pin

...

}

Use an scope to determine the timing of the pulse width.  This is the timing of the function.

Len

Len
"Engineering is an Art. The Art of Compromise."
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

LaHa,

Using pin method has some drawbacks. Pin_Write/Read call execution is very slow and takes about 40-60 BUS_CLK cycles each, depending on debug/release mode. It requires o-scope and consumes a hardware pin. This approach works fine if microsecond resolution is sufficient.

If single BUS_CLK resolution is required using system counters provides an alternative solution, see here:

Calculating Function Run Time

/odissey1

/odissey1,

You are correct the pin method has it's drawbacks.  (I did realize that it could take 40-60 BUSCLK cycles.   I knew that the _Write function has to do some bit shifting and AND'ing.   I suppose you can write directly to the register if you needed less BUS_CLKs).

The method with the least latency is the one where the start event starts a very fast timer and then the end event stops the timer.  Then the SW can go in and read how many counts have occurred.

Len

Len
"Engineering is an Art. The Art of Compromise."

Len,

You can find timing comparison in this video

https://vimeo.com/65092394?ref=em-share

/odissey1

/odissey1,

Thanks for sharing the link.   It's a good tutorial on latencies in code and HW.

Len

Len
"Engineering is an Art. The Art of Compromise."

Hai Lai,

As /odissey1 pointed out there are drawbacks in the pin framing (or toggle) method.  However, there is a way to remove the BUS_CLKs from the framing commands.

  1. Write the following framing code all by itself.  Program the chip.

main() 

... 

Pin_0_0_Write(1);     // Turn on the GPIO pin 

Pin_0_0_Write(0);     // Turn off the GPIO pin 

... 

  1. Using a scope, time the pulse width.  This will equal tframe.
  2. Place the framing around the target function code.  Program the chip.

main() 

... 

Pin_0_0_Write(1);     // Turn on the GPIO pin 

function_2_time();     // This is the function to time 

Pin_0_0_Write(0);     // Turn off the GPIO pin 

... 

  1. Using a scope, time the pulse width.  This will equal tfunction.
  2. Subtract tframe from tfunction.  The remaining time is the time taken to execute the function without the framing time.  You will be accurate to nsecs

Len

Len
"Engineering is an Art. The Art of Compromise."
ViDv_264506
Level 5
Level 5
50 sign-ins 25 sign-ins 5 solutions authored

Hi All,

on the PSoC5LP = Cortex M3 it is possible to use DWT too. DWT_CYCLE_COUNT (0xE0001004) is the 32bit long upcounter counting BUS_CLOCKs. By overclocking the PSoC5LP on CY8CKIT-059 to 100 MHz is the accuracy - precision 1 BUS_CLOCK (10 nanoseconds).

Tested.

You need only to ....

a. enable TRCENA (bit 24) in the Debug Exception and Monitor Control Register (0xE000EDFC) aka enabling the DWT structure

b. clear all 32 bits in the DWT_CYCLE_COUNT (0xE0001004) aka set / reset the DWT counter to zero

c. enable CYCCNTENA (bit 0) in the DWT_CTRL (0xE0001000) aka enabling counting DWT counter

and

d. read the DWT_CYCLE_COUNT (0xE0001004) aka periodically read the DWT counter content on the fly

#define DWT_CTRL                                 0xE0001000

#define DWT_CYCLE_COUNT                0xE0001004

#define CORE_DBG_EXC_MON_CTL    0xE000EDFC

uint32 SysCntVal = 0;

....

    (*(int*)CORE_DBG_EXC_MON_CTL |= 0x01000000);    // = TRCENA

    (*(int*)DWT_CYCLE_COUNT) = 0;                                  // = Set counter to Zero

    (*(int*)DWT_CTRL) |= 0x1;                                               // = DWT Counter enable CYCCNTENA

....

     SysCntVal = (*(int*)DWT_CYCLE_COUNT);

Viktor

Hi ViDv_264506,

It's great if you provide more project samples, because many people like me are beginers.

Thanks you.

Hai Lai

0 Likes