Calculating task execution time

ose wrote on Friday, May 18, 2018:

I have been trying to calculate the execution time of a task(led blinking) and i have followed the instructions here and also tried to understand the demo exmaples there and impliment it but i am using a different MCU(arduino uno) so i cant edit the demo for mine. I have also read how to use the vTaskGetRunTimeStats and i have followed the instruction to the best of my undertstanding.

But i have been on this for the past three weeks and i have still not been able to get the task execution time showing in tabular form. I read some more and i think i will have to do some stuffs with ip address and some stuffs that seem to much for me as a beginner.

Please is there another way to get the task execution time or is there a demo for the Atmega328in regards calculating task execution time because i tried searching for but didnt see. Its possible i didnt look in the right place.

Any kind of suggestion will be great.

Below is my main.c++ and Freertosconfig.h, what i have done so far following the instructions and demo examples here

#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"

static void TaskBlinkMainLED(void* pvParameters);


int main()

  xTaskCreate(TaskBlinkGreenLED, (const portCHAR*) "GreenLED", 100, NULL, 1, NULL);
 xTaskCreate(TaskBlinkMainLED, (const portCHAR*) "ExtraLED", 100, NULL, 2, NULL);


  for (;;)

  return 0;

static void TaskBlinkMainLED(void* pvParameters)
char bufptr1[150];
   //set pin 5 of PORTB for output
 DDRB |= _BV(DDB5);

  TickType_t xLastWakeTime = xTaskGetTickCount();

  for(int x = 0; x < 5 ; x++ ){

		  // LED on
    PORTB |= _BV(PORTB5);
    vTaskDelayUntil(&xLastWakeTime, (1000/ portTICK_PERIOD_MS));

    // LED off
    PORTB &= ~_BV(PORTB5);
    vTaskDelayUntil(&xLastWakeTime, (1000 / portTICK_PERIOD_MS));



void vApplicationStackOverflowHook(TaskHandle_t xTask, portCHAR* pcTaskName)
  // main LED on

  DDRB |= _BV(DDB5);

  // die
while (true)
  PORTB &= ~_BV(PORTB5);

void vConfigureTimerForRunTimeStats(void){
	const unsigned long TCR_COUNT_RESET=2, CTCR_CTM_TIMER= 0x00, TCR_COUNT_ENABLE=0x01;

	 EECR|= 0x02UL;
     TCCR1B = (TCCR1B & (~(0x3<<2))) | (0x01 << 2);



	 CLKPR=(configCPU_CLOCK_HZ/10000UL) - 1UL;



#define configUSE_PREEMPTION		1
#define configUSE_IDLE_HOOK			0
#define configUSE_TICK_HOOK			0
#define configCPU_CLOCK_HZ			( ( unsigned long ) 8000000 )
#define configTICK_RATE_HZ			( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES		( 4 )
#define configMINIMAL_STACK_SIZE	( ( unsigned short ) 85 )
#define configTOTAL_HEAP_SIZE		( (size_t ) ( 1500 ) )
#define configMAX_TASK_NAME_LEN		( 8 )
#define configUSE_TRACE_FACILITY	1
#define configUSE_16_BIT_TICKS		1
#define configIDLE_SHOULD_YIELD		1

#define configUSE_MUTEXES 1
#define traceTASK_SWITCHED_OUT()                    \
    log_event( pxCurrentTCB, ulSwitchReason );
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 		1
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */

#define INCLUDE_vTaskPrioritySet		0
#define INCLUDE_uxTaskPriorityGet		0
#define INCLUDE_vTaskDelete				1
#define INCLUDE_vTaskCleanUpResources	0
#define INCLUDE_vTaskSuspend			0
#define INCLUDE_vTaskDelayUntil			1
#define INCLUDE_vTaskDelay				1

extern void vConfigureTimerForRunTimeStats(void);
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()

#endif /* FREERTOS_CONFIG_H */

tlafleur wrote on Friday, May 18, 2018:

You don’t need any network protocol to make it work. Are you sure the high speed clock is working? Serial port working? Tick clock working?

I don’t have my computer here to look at your code

You can also look at execution time by using a scope on the LED pins

Another option you may want to look at is the esp32 it run freeRTOS ver 8.2 natively as it’s pre build in the device.

tlafleur wrote on Friday, May 18, 2018:

You should be able to make it all work, but the resources in the AT328 are severely limited and very impractical to run FreeRTOS for anything useful. You will enjoy the performance improvement and the large amount of ram by moving to a ARM M0 processor.

ose wrote on Saturday, May 26, 2018:

Thank you and sorry for my late reply. I have been caught up with some other stuffs.

The high speed clock should work although i dont know how to check out if its working.
What do you mean by the serial port working? lIke i am pretty sure i can upload the program to the board if that’s what you mean.
yes, the tick clock is working.

That would have been great if you could do that :slight_smile:

I dont want to use a scope because the details will be limited. I find the output of the run time stats more inetresting and would really love to get the task execution time using its method.

I will consider the esp32 if i see i am making the progress.

My other question is, after i upload the code to my microcntroller is the tabular format which shows the task excution time, percentage e.t.c going to just pop up on my laptop?
Because i am really confused with this that’s why i am not usre if there is somehting extra i am supposed to do.

tlafleur wrote on Saturday, May 26, 2018:

To test the high speed clock, toggle an I/o pin in its interrupt code and
use a scope…, same for tick clock…

The serial port need a driver for the AT328 in FreeRTOS to work… it’s
unrelated to the bootstrap loader you use to load code…

A scope or logic analyze can give you lot more detail of what your task are
doing in real time, the stats just give you a snapshot …

If the above items are working, and you have enough ram memory for the heap
and stacks, and you have the display task code per the documentation to
display stats it should send the stats out the serial port to you

You should also turn on asserts in the config file… to test for any

But again an At328 has very limited resources to run anything useful with

tlafleur wrote on Saturday, May 26, 2018:

You may find some help here…

ose wrote on Sunday, June 03, 2018:

Thank you

ose wrote on Sunday, June 03, 2018:

Thanks. I will look into it