- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have been trying to use clock () function to get the time used by code i have wrote. The code is in the main before infinite for loop.
eg.
volatile clock_t start1,end1,;
volatile float64 c_time;
start1=clock();
//then my code comes here
end1= clock();
c_time =( float) (end1- start1)/ (float)(CLOCKS_PER_SEC);
when i debug the code and looks in the variables start1 and end1, it displays same value .
is there any other way by which I can try to determine the time taken by my code.
Solved! Go to Solution.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ammarshamim,
You can yse ARM built-in SysTick counter to measure amount of CPU cycles taken by a function or operation as shown below. You will be limited by 2^24 CPU ticks only (about 0.25sec @24MHz CPU speed), as SysTick counter on Cortex M0 and M3 can not go beyond SYSTICK_MAXVAL:
#define SYSTICK_MAXVAL 0x00FFFFFF //max allowed SysTick counter value for 24bit
uint32 SysCntVal; // The value of SysTick counter you are trying to retrieve
SysTick_Config(SYSTICK_MAXVAL); //reset counter set to max value, 1-time, will not reload
TCPWM_WritePeriod(); //do something..
SysCntVal = SYSTICK_MAXVAL - (SysTick->VAL); //get elapsed ticks (min offset 3 ticks)
sprintf(strMsg1, "%d, %f\r\n", SysCntVal, x); //report result UART_PutString(strMsg1);
/odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have you setup a timer or counter? What does your function clock() exactly perform? Can you post your complete project, so that we all can have a look at all of your settings? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ammarshamim,
You can yse ARM built-in SysTick counter to measure amount of CPU cycles taken by a function or operation as shown below. You will be limited by 2^24 CPU ticks only (about 0.25sec @24MHz CPU speed), as SysTick counter on Cortex M0 and M3 can not go beyond SYSTICK_MAXVAL:
#define SYSTICK_MAXVAL 0x00FFFFFF //max allowed SysTick counter value for 24bit
uint32 SysCntVal; // The value of SysTick counter you are trying to retrieve
SysTick_Config(SYSTICK_MAXVAL); //reset counter set to max value, 1-time, will not reload
TCPWM_WritePeriod(); //do something..
SysCntVal = SYSTICK_MAXVAL - (SysTick->VAL); //get elapsed ticks (min offset 3 ticks)
sprintf(strMsg1, "%d, %f\r\n", SysCntVal, x); //report result UART_PutString(strMsg1);
/odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Obviously the clock() function would use some internal hardware which must be taken away from the existing resources. This could be a conflict with own projects. So I'm afraid that you'll have to provide an own clock counter as odissey suggested.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have used odissey's function. a simple sin wave output takes about 9000 cycles ( approx 2700 hex) I dont know why it is taking so long. and due to this, I am restricted to 70 hertz frequency for my sin wave that takes 100 samples. I dont know why this simple loop is taking so long. CAn anybody suggests why it is that long?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I do not know what you're counting, but I count something like 32 cycles for the your code snippet (before the loop).
You even could reduce that time by pre-calculating 2*Pi into a float and declaring Signal_Freq as a float, then there will be no conversions.
A PSoC5 is able to handle 10k interrupts per second, so your calculation is not too much stress. You could improve performance by raising the system clock from 24MHz to 48MHz (66MHz is maximum). Compiling in release mode and setting optimization to "speed" will do an additional share (do not forget to set additional library to "m").
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ammarshamim,
1. there is special component to generate sine output from VDAC with no intervention from CPU: WaveDAC.
2. Comments on your code:
(i). do not use float32, using float is enough in your case.
(ii). precalculate frequency of the sine to reduce amount of multiplies:
(float) Omega = 2*Pi*Signal_Freq; //frequency
SignalInstValue= (float)Amp*sin(Omega*Time_Sin);
(iii). "PI" is not 3.14! Use predefined constant in math.h
(iv). Never make comparison of floats! (float32 in this case... - takes forever and not guaranteed to match)
//if( Time_Sin ==Signal_Period) {...} //comment out this code - you dont need it at all! Let Time_Sin increase forever
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have exactly the same problem, with the measure time between code but , sorry, I don't understand well how to follow your instructions.
I need to measure the time between instructions in a code part (I am working with CY8C5868AXI). when I tried with your suggestion it did not work to me.
Some one can help me about it.
Thank you very much.
regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
JaOr,
This is very old thread. Please find updated solutions here
And here
Measuring cycles using DTW on PSoC 6(M4)
/odissey1