LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

microsecond sleep

Hello !

 

I need a 40 microsecond sleep in my program. I haven't got CVI/Real Time. I tried to make asm tempo but CVI 8.0 dont recognize "_asm"... what can i do ? Is there a specific function?

 

thx

0 Kudos
Message 1 of 5
(4,564 Views)

If you want to inline assembler, you should write your assembler-needing functions in another module, compile it with MS or intel compiler and insert the .obj in your project.

 

Regards,

Nicolas

0 Kudos
Message 2 of 5
(4,551 Views)

a 40 microsecond wait is pretty exotic. i can recommend 2 things:

 

1) if you can make the wait a little step larger, there is a poorly documented call on Windows which allows to set the time quantum of a thread. timeBeginPeriod() (and its counter-part timeEndPeriod()) allows to set a shorter scheduling period for a thread. this way you can have a wait with a resolution of one millisecond. use this function with care as it can push your system down on its knees.

 

2) use a busy loop, using high-resolution counters. QueryPerformanceFrequency() returns the frequency of the high-resolution counter, QueryPerformanceCounter() returns the current system-wide counter value. the resolution of the high performance counter depends on the clock frequency of the processor, but you can expect a resolution down to 50 nanoseconds. poll for the counter until 40 microseconds has elapsed. 

 

you have to keep in mind that running on a standard multitasking OS has a number of drawbacks, one of them is that you have no control at all on the process scheduler: your application may be interrupted at any time and the control handed over to another process, regardless of the time-criticalness of the code you are executing. if the scheduler interrupts your code in the above loop, you will get a jump of at least 15ms, rendering your wait (almost) useless.

 

for time critical processes, use time critical component: you may try a real-time system, but you can also have good results with a PCI card with a programmable counter which triggers an I/O. the choice depends on why you need to wait for a so small time period.

0 Kudos
Message 3 of 5
(4,508 Views)

Hi !

 

Thanks for your replys.

I heard about QueryPerformanceFrequency and QueryPerformanceCounter and i used them in order to create my 40 microdecond sleep. And i saw the problem you said : there are random interupt (due to OS) that destroy my tempo time 😞

 

I need this tempo to send informations to attenuators at regular intervals (with the printer port). Do you think that a 100 microsecond tempo is more realistic ? If i test my software on a more powerfull PC, maybe the ramdom interupt can be less present?

 

Have you some interesting link to the PCI applying to labwindows CVI ? PCI card are expensive ?

 

Thank you for your help.

 

Ps : i heard about increasing priority of the thread linked to QueryPerformanceCounter how can i do that ?

 

 

0 Kudos
Message 4 of 5
(4,460 Views)

a 100 microsecond tempo is no more realistic on Windows. even a 1ms tempo is a bit much. a more powerful pc is also subject to the same kind of interrupt. also there is no (i said NO) way to ensure your thread will not be preempted, even with a higher priority, a reduced time quantum, and the lowest loaded system possible: this is how windows is designed and you can't do anything about this.

 

NI makes some PCI I/O board, see your local NI representative for an price offer. also, a lot of other manufacturers build this kind of hardware.

 

now, looking at your design, i would call it clunky: a parallel port used as an I/O board, a strict time constraint enforced by software on an operating system not designed to do so... this does not look very strong. but if you like this kind of (crap) solutions, why not use your audio card ? output a square waveform on the line out of the audio card. unfortunately, 40µs is 25kHz, which is not a multiple of a standard sampling frequency for audio hardware, but boards with 96kHz output are easy to find these days and are quite cheap. 

0 Kudos
Message 5 of 5
(4,451 Views)