Reputation: 4614
I have a PIC32MX460F512L running RTOS and I am looking for a way to get the difference in ms between two points in code.
This code below gets the tick time but not the time in ms.
static unsigned long gMSTP_timer_tick = 0 ;
void MSTP_timer_reset() {
gMSTP_timer_tick = xTaskGetTickCount( ) ;
}
FLOAT32 MSTP_timer_differences() {
unsigned long differences = xTaskGetTickCount( ) - gMSTP_timer_tick ;
gMSTP_timer_tick += differences ;
return (FLOAT32) differences ;
}
My question is
In free RTOS is there a way to get the current relative time in ms?
Upvotes: 1
Views: 7063
Reputation: 68
FreeRtos use timer 1 in pic32 port, you can find timer1 register configure in port.c file and calculated exact tick rate time base config_TICK_RATE_HZ in milisecond. and multiply in deferences tick value. Usually base config_TICK_RATE_HZ: 1000HZ~1MS 100HZ~10MS
Upvotes: 0
Reputation: 861
Ticks should have a set frequency. 1000Hz tick -> interrupt and task switch triggered every 1 ms. It won't be exactly that, especially if you have other interrupts. But it should keep that frequency.
I believe you should be able to compare two tick counts and divide by tick rate to end up with the delay.
Another classic trick would be to directly toggle a GPIO pin at the start of a timed interval and again at the end (repeatedly) and then use an oscilloscope to capture the interval. That should give a very precise real-time result.
You might also ask the FreeRTOS list.
Upvotes: 1
Reputation: 59151
According to this related question, there is a configTICK_RATE_HZ
value.
Using this value it should only be a little bit of simple math to determine how many milliseconds a number of ticks corresponds to. Something like:
return (FLOAT32) (differences / configTICK_RATE_HZ / 1000);
There is also a set of timer APIs you might want to look into that supports callbacks into your code on timed intervals. No idea if it would suit your needs or not, but maybe it would be worth a look:
http://www.freertos.org/FreeRTOS-Software-Timer-API-Functions.html
Upvotes: 1