Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Adding time stamp for my thread executions

Posted by Nobody/Anonymous on April 26, 2005

I need to add some time stamps for my sampling, for this I have used following code:

xLastWakeTime = xTaskGetTickCount();

portTickType old_wake_time = xLastWakeTime;
// Wait for the next cycle.
vTaskDelayUntil( &xLastWakeTime, xFrequency );

double millisec=(double)((xLastWakeTime-old_wake_time)/portTICK_RATE_MS);
char data[40];
sprintf(data, " X =%d; Y =%d; Z =%d\r\n", millisek, acc[1], acc[2]);

Im getting strange values... Why doesn't this work?


RE: Adding time stamp for my thread executions

Posted by Richard on April 26, 2005

Which port and compiler are you using?

A couple of points:

char data[40] - do you have enough stack space to allocate 40 bytes? Maybe static char data[40] would help. sprintf will use lots of stack also.

In the sprintf you are using %d (int format) to print a double.

Lastly - I presume you are wanting a time stamp in milliseconds? portTICK_RATE_MS is the time in MS between each tick. If you have a tick rate of 500hz (for example) then portTICK_RATE_MS will be 2. Then, if 10 ticks have passed between xLastWakeTime and old_wake_time this is 10 * 2 milliseconds. 10 / 2 will give you 5ms, which I presume is not what you want.


RE: Adding time stamp for my thread execution

Posted by Nobody/Anonymous on April 27, 2005

Thank you for helping med with my bloopers, problem solved!


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner