September 3, 2016 at 08:20 #15910
I am new to uC/OS-II and trying to find the execution time taken by set of functionalities. If I have function1, function2 and function3 in my application, then I am trying to find exact time taken by each function execution. Could you please advice me whether to use OS Timers or some other hardware timers.
ThanksSeptember 6, 2016 at 16:27 #15959
The software timers in µC/OS-II (and µC/OS-III) have a relatively low resolution in most projects, since they are implemented using the same periodic, or tick, interrupt involved in time delays and timeouts. Through their callback mechanism, the timers provide a means of performing relatively simple operations either periodically or after a specified delay. As an example, a software timer and callback could be used to read an analog-to-digital converter (ADC) roughly once every 100 ms. For some applications, this approach could be preferable to creating a periodic ADC task that would require its own TCB and stack space.
When it comes to measuring task or function execution times, the software timers would not be a good choice. It would be much better to rely on hardware timers for such measurements. Although most MCUs offer a variety of timers that can be used for measuring the duration of events, the simplest choice in a typical µC/OS-II-based project would be the timer that µC/CPU leverages for timestamp measurements. µC/CPU, which is a utility module found in practically every µC/OS-II example project, is expected to provide timestamping capabilities to other Micrium modules, so it normally (through a driver) initializes a hardware timer.
To measure the duration of a particular passage of code, an application could simply call the µC/CPU function CPU_TS_Get32() immediately prior to the passage’s start and then call the function again at the passage’s conclusion. In most ports of Micrium’s newer kernel, µC/OS-III, this approach is used to keep track of tasks’ relative CPU usage. The kernel’s code, which is normally contained in the context-switch hook function, OSTaskSwHook(), uses a macro named OS_TS_GET(), as opposed to a direct call to µC/CPU routines, but the concept is the same. Numerous µC/OS-III examples incorporating this code are available from the Micrium Download Center, while the documentation for µC/CPU and its timestamp routines can be found here.January 30, 2018 at 11:42 #22835
Hi…i am a new user here. As per my knowledge the software timers would not be a good choice. It would be much better to rely on hardware timers for such measurements. Most microcontrollers offer a variety of timers that can be used for measuring the duration of events, the simplest choice in a typical microcontroller based project would be the timer that microcontroller leverages for timestamp measurements.February 11, 2018 at 16:37 #22932
If you need a precise execution time of your function, you will need to use a high resolution hardware 32 bit timer with a frequency at least 1MHz (1us/bit resolution) or greater. You can read the contents of the timer counter at the beginning and end of the function. Of course, you will need take into account the function call overhead, function return overhead and timer counter reads.
You must be logged in to reply to this topic.