Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>Windows XP/NT Embedded or Windows CE/Mobile</h2> <p>You an use the QueryPerformanceCounter() to get the value of a VERY FAST counter before and after your function. Then you substract those 64-bits values and get a delta "ticks". Using QueryPerformanceCounterFrequency() you can convert the "delta ticks" to an actual time unit. You can refer to MSDN documentation about those WIN32 calls.</p> <h2>Other embedded systems</h2> <p>Without operating systems or with only basic OSes you will have to:</p> <ul> <li>program one of the internal CPU timers to run and count freely. </li> <li>configure it to generate an interrupt when the timer overflows, and in this interrupt routine increment a "carry" variable (this is so you can actually measure time longer than the resolution of the timer chosen).</li> <li>before your function you save BOTH the "carry" value and the value of the CPU register holding the running ticks for the counting timer you configured.</li> <li>same after your function</li> <li>substract them to get a delta counter tick.</li> <li>from there it is just a matter of knowing how long a tick means on your CPU/Hardware given the external clock and the de-multiplication you configured while setting up your timer. You multiply that "tick length" by the "delta ticks" you just got.</li> </ul> <p><strong>VERY IMPORTANT</strong> Do not forget to disable before and restore interrupts after getting those timer values (bot the carry and the register value) otherwise you risk saving incorrect values.</p> <p><strong>NOTES</strong></p> <ul> <li>This is very fast because it is only a few assembly instructions to disable interrupts, save two integer values and re-enable interrupts. The actual substraction and conversion to real time units occurs OUTSIDE the zone of time measurement, that is AFTER your function.</li> <li>You may wish to put that code into a function to reuse that code all around but it may slow things a bit because of the function call and the pushing of all the registers to the stack, plus the parameters, then popping them again. In an embedded system this may be significant. It may be better then in C to use MACROS instead or write your own assembly routine saving/restoring only relevant registers.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload