PDA

View Full Version : QTimer resolution in Windows



Lakshmi Dhanaraj
7th February 2018, 11:03
Hi,

I am using Qt 5.9.1 with MinGW 32bit compiler in Embedded Windows 64-bit platform.I need to use five timers for my application.
The main timer should fire for every 31.25ms for reading the data,which means that I have to get 32 counts for one second.After reading 32 values,I need to pack data,send the data,log the data and display the data.For this four functionalities created four timers should fire for every 1000ms with 32msec intervals between the successive timers.

The problem is,

1.In Windows the timer does not times out at exact 1sec.The resolution of the timer is varying ~16ms(i.e.,In Qt Timer Class it is mentioned that the resolution of the timer depends upon the operating System).So it entirely changes the acquisiton timing,Obviously changes the all the other timings also.How to get the exact 1sec times out in Windows system?

2.The Qtimer has taking the interval in integers.But I have to trigger it for every 31.25ms.

3.Synchronization between the timers.It should be times out in the below order.

Acquistion_timer -->Pack Timer --> send Timer --> Log Timer -->Display Timer.

4.How the implement a nanosecond precision QTimer in Windows?

So please kindly help me out to solve this problems as soon as possible.

high_flyer
8th February 2018, 12:38
1.In Windows the timer does not times out at exact 1sec.The resolution of the timer is varying ~16ms(i.e.,In Qt Timer Class it is mentioned that the resolution of the timer depends upon the operating System).So it entirely changes the acquisiton timing,Obviously changes the all the other timings also.How to get the exact 1sec times out in Windows system?
Yes, timer resolution depends on OS and underlying HW, and you have to take these limitation in account.
Generally need to define/know the target system requirements, and use a system that meets these requirements.
If you use a system that does not meet them, there should not be a surpize if the software deos not run as intended.


2.The Qtimer has taking the interval in integers.But I have to trigger it for every 31.25ms.
Amm... time is measured in discrete units, therefore int is fully sufficient.
31.25 ms is 312.5 micro secs, and 3125 nano secs. - so you can represent your interval as an int.
What you need is a timer with nano second resolution, and I am no sure your regular hardware can do that.
Have a look at this MSDN documentation on how to determine the timer resolution your system can offer you.
https://msdn.microsoft.com/en-us/library/windows/desktop/dd757633(v=vs.85).aspx
This also looks like it has some good information you could use:
https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx