On a 32 bit microcontroller , I want to measure exection time of a code for different operating frequencies of microcontroller. First of all I used Periodic timer (PIT), but it did not provide high resolution, because if I operate PIT at high frequency then its counter got overflow. So I shifted to System timer (STM), because it can run at system clock. but at different operating frequencies of microcontroller, STM give same execution time of code. Could any of you help me in this matter. Thanks
0
votes
Does "same execution time" mean that the system timer's counter value counted the same number of ticks? Have you forgotten to divide the counter value by the tick rate to convert to time?
– kkrambo
yes , I mean '' execution time '' the system timer's counter value counted the same number of ticks. At the different operating frequencies, system timer's counter value is same. Yes I didn't divide the counter value. Could you please elaborate more.
– waq
When you change the operating frequency, aren't you also changing the tick rate of the system timer? So n ticks at the original tick rate is a different amount of time than n ticks at the changed tick rate. Your counter counted the same number of ticks but it's a different amount of time, right?
– kkrambo
I think I am getting you. I have this scenerio, Lets operating frequency of microcontroller is ''X'' , for execution of piece of code lets the system timer's value for is ''A'' then I change operating frequency of microcontroller to ''Y'' , but system timer's value for is again ''A'' . You mean that I have to divide ''A'' by the operating frequency. In this way execution time will be different? Right?
– waq
Yes, the timer's counter value represents the number of ticks (i.e., clock pulses). You need to divide the counter value by the timer's tick rate (ticks/second) in order to convert from ticks to seconds. It seems likely to me that the timer's tick rate changed when you changed the system's operating frequency,
– kkrambo
1 Answers
0
votes
I realize this is an old question, but if this doesn't need to be done in the system "real time," I would just toggle a port pin when entering and exiting the function and use an oscilloscope to measure the time. I'm assuming that you just want to do this for software testing.
If you need to do it "real time" (in the application code), then you'll need to multiply your STM timer value by the microcontroller clock's period. The timer value for the function execution should always be the same (with some exceptions) regardless of the micro's clock frequency. (i.e. the timer's speed will change with clock frequency in the same way your code's execution speed will change)