Measure time consumption of programme

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

 

I'd like to check the "time consumption / time measurement" of the different parts/functions of my programme - how long it takes:
- to process one complete run through the programme (the "infinite" loop)
- function for sending/receicing data from/to USART
- write data to a LCD display
- and so on

 

and right now I do it the "simple" way - there's 1ms timer (time base) and I use different counters to monitor how long it takes to process a function etc.
Is there a FOC programme (I'm neither Mr. B. Gates nor Mr. M. Zuckerberg wink) which could be used to do this "time consumption monitoring" in a more professional manner?

I use the AVR Studio 4.18 Build 716, avr-gcc 4.3.3, programming language is C for my ATMega8

 

Thanks in advance

 

best regards

 

Hero_123

This topic has a solution.
Last Edited: Mon. Sep 16, 2019 - 09:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't know what kind of tools there are but I would look i the generated code, and run it with the simulator (it's clk accurate ) and set break points different places.

 

That way you should get a good picture of that's happening and how long it takes especially it you wrote the code.

 

Other ways is simply in the real program have some variables that read a free running timer (probably slow to avoid overflow) , and then log the values (probably only once with a start trigger ) and then dump them on the UART later on.

 

Have in mind that for some things you want to know worst case, and not AVG speed (like a function that 1% of the times take 10 times longer than normal can destroy the hole thing),

but I assume that you know that since you asked the question :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello sparrow2

 

Thanks a lot for your reply yes

 

I've never used the simulator and so I'm not at all familiar with that kind of tool...

 

sparrow2 wrote:
Other ways is simply in the real program have some variables that read a free running timer (probably slow to avoid overflow) , and then log the values (probably only once with a start trigger ) and then dump them on the UART later on.

 

That's exactly what I do in the moment. I store the longest value of each interesting function etc and dump them on the USART=> worst case consideration.

 

best regards

 

Hero_123

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simulator works fine for lots of things, but when you have complex external hardware, such as a microSD card, it does not help much. In some such cases, the external hardware can drag things out for a LONG time and it would never show in simulation.

 

Been there, done that!

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sun. Sep 15, 2019 - 10:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd like to check the "time consumption / time measurement" of the different parts/functions of my programme 

What kind of timing res do you want--seconds?  (it takes about 5 seconds for the light to come on), milliseconds, or down to the microsecond?

You can often use a scope (or logic analyzer)...set a pin in the different sections you want to measure (clear upon exiting the section/function)and measure the pulse width.  Easy & effective.

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I also opened recently a topic on the same subject, maybe they could be joined?

You can use a very fast timer to measure the exec time and cpu load and then send it or save it.

But also the pin toggling method is very nice, as you can eliminate some possible SW factor from the calculation.

I don't know what is the pin commuting time for ATMELs, but it should be fast enough to guarantee a good precision.

At least for me for a very short routine, I measured multiple times with the oscilloscope the same code and the result was 125us+-10us at 16MHz clock.

I never used the simulator, this would look like a nice method for designing and checking the executing time for routines that are really time critical, like some ISRs,

so that you don't have ugly surprises after writing the code.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello  ka7ehk, hello avrcandies, hello bbogdanmircea

 

Thanks a lot for your replies yes

 

Yeah, I'll do it the "old fashioned way" (use  a timer and counter, read continously, dumb the max value to the USART).

I haven't got an oszilloscope (sad, I know) and that method with using a pin - well, unfortunately I've used all the pins on my ATMega8 already (use right now Port expanders to increase the number of available ports).

 

In the end I was on the right track (timer/counter/ USART for indication), I only thought there'd be a better solution wink

 

best regards

 

Hero_123

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe there are better ways ... but I can recommend the osci method for sure, it gives such a good insight on how the "tasks" are running into the code.
I am using one of the pins used by the app which I can easily scope, after I am sure all the tasks are running ok I will decide it to its original purpose.
But if you have only a few pins then that could be a problem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

I haven't got an oszilloscope 

That's ridiculous to be involved in micros and not have one....at least get a $15 USB logic analyzer.

 

Be careful of using the system to measure its own time...since the time measurement will be affected by the system clock.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I haven't got an oszilloscope

???

 

Banggood Electronics has this "Toy" O'scope for $12 USD, (ARM Cortex M3 and a 2.4" color TFT display, Single Channel, 1 MSamples / Sec, 0 - 200 kHz BW...).

 

This is a cheap toy O'socpe, low bandwidth, single channel, etc.

But it is so incredibly inexpensive and useful.

You can also use it as an Arm development board, if one was so inclined.

 

As mentioned above, I routinely use a pin and set it high when entering a routine, low when exiting, to see the ISR or routine's timing.

 

One can easily set a pin high within the ISR's and see what % of time is spent within the ISRs vs is available for the Main Loop processing.

 

Out of pins...  Bummer.

There are several ways to free up a pin, (but not once your board is made!).

 

For your current board do you have any I/O pins driving an LED, or a Piezo, or a rarely used / needed switch, etc.

If so, simply temporarily use that pin for your timing, and change the code to skip using that item.

 

Recall that most compilers will have a number of Register saving and restoring (Push and Pop) instructions at the start and end of ISRs, so the "Pin High" duration of an ISR is actually a little bit shorter that the real ISR.

ISR:

Save registers

Set pin high

ISR code

Set pin low

Restore registers

 

But that is only a few clock cycles, and unless one needs the EXACT timing, it is immaterial.

 

JC 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
There are several ways to free up a pin, (but not once your board is made!).
other than by patches though do need sufficient I/O; sometimes a pin can be shared by current division.

A proof-of-concept may begin with your preferred PCBA that's shy a function or few.

I create defects (design, implementation, layout, test); therefore, I patch (software patches, firmware patches, hardware patches)

0.8mm thick copper clad FR4 can be cut with scissors (1.6mm by metal shears)

What’s All This Pease Prototype Stuff, Anyhow? | Electronic Design

Digging through boxes of the prototype circuits that Bob Pease had amassed over the years proved to be a fun time for all involved.

Paul Rako | Aug 16, 2019

[after photo 7]

...

On the top was another prototyping technique I had not seen. Pease cut copper-clad board material into long narrow strips. He then soldered three of those strips to other boards, spaced out so he could solder components in between. I could see the strips carrying positive and negative power, as well as a ground strip in the middle. You could use the other sides of the copper-clad to interconnect intermediate circuit nodes. Pease was clever in everything he did.

 

...

The back of the board showed how Pease hacked in a few discrete components (Fig. 17).

...

17. The backside of one of the prototype Philbrick cards, showing some cuts, jumps, and added components.

...

add diodes, transistors, op amps, comparators, glue digital logic (small parts) (add functions or enhance reduce EOS)

SchmartPatch - Schmartboard, Inc.

 

edit : strikethru

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Mon. Sep 16, 2019 - 06:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Hero_123 wrote:
use right now Port expanders to increase the number of available ports

Are these SPI or I2C?

If SPI, you can wiggle the data line all you like as long as the clock line is not wiggled!

Same for I2C, you can wiggle the data line as long as the clock line is held high.

Button inputs can be used for temporary outputs, just don't use the button while debugging.

 

Lots of ways to find a temp spare debug pin.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

May I ask what the trouble is to use the 1ms timer ?

 

Just to be sure : Have a timer interrupt that fires 1x per second and counts the ticks since startup (uint32), just as the Arduino has millis();

Before the testroutine, use t1=millis();

After the testroutine, use t2=millis();

Later duration=t2-t1;