I create a 1ms period task in the MQX. I want to check whether the period is 1ms
at the beginning of the task. How can I measure the period by software method?
Hi Robin,
Please look at this post:
There is elapsed time in microseconds function call too.
Regards,
David
Hi,
You could use _time_get_ticks() to get two timestamps (one for previous run and one for current run) and use _time_diff_milliseconds() to return the difference in mS, or _time_diff_microseconds() to get uS.
int ms;
boolean ms_overflow;
MQX_TICK_STRUCT ticks_last, ticks_cur;
_time_get_ticks(&ticks_last);
////
_time_get_ticks(&ticks_cur);
ms = _time_diff_milliseconds(&ticks_cur, &ticks_last, &ms_overflow);
For your 1mS task period, I remember that on MQX37 the system tick used for scheduling was set to 5mS by default (can be changed in BSP config), so a _time_delay(1); was sleeping for 5mS instead of 1mS. Take care of that with your task.
Thank you very much. I still have some questions.
1), If the system tick is set as 5ms, is it possible to call _time_diff_microseconds() to get uS?
2), After the task calls the function “_time_delay”,the task will
be blocked until the time is out.Is it right?
3), Is it possible to set the system tick as 1 us? If yes, how to set it?
4), What will happen if I set the task period as 1ms but I set
the time delay as 2ms in the task?