LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

delay less than 1 milli second

I don't believe there's a software solution under Windows. It's not a real-time operating system and it's multi-tasking will mess up any attempt through software to create a PWM signal at that speed.
You need a hardware solution: something like NI PCI-6534
or for up to 100 MHz, look here.
0 Kudos
Message 11 of 18
(2,822 Views)
Hello,

I like to put in a weird idea:
Assuming that the PWM does not need to be updated interactive with each pulse,
will it work for your application if you create a small buffer with a 44.1 kHz waveform and use the Windows SDK audio playback to generate a continuous loop for playback ? And this waveform would be a block pulse with the correct duty cycle with a resolution of 0.02 ms. And windows will probably accept even higher sample frequencies. And if the pulse width has to be changed, generate a new wave form and insert it in the buffer ?

I am not familiar with audio (besides being a listener) but I have looked sometime ago for audio playback of a (non-audio) measured waveform. I found information in the CVI/SDK help:
CVI Help --> Windows SDK --> DirectSound --> C/C++ tutorial
IDirectSound_CreateSoundBuffer(lpds, &dsbdesc, &lpdsb, NULL);
IDirectSoundBuffer_Play(lpdsb, 0, 0, DSBPLAY_LOOPING);


Good luck, Jos
0 Kudos
Message 12 of 18
(2,478 Views)
Sub millisecond timing is easy using Windows Performance counters:

partial code:
LARGE_INTEGER clock_rate, start_tick,current_tick; // Large_integer defined in Windows API Winnt.h
QueryPerformanceFrequency(&clock_rate);
freq = (double)clock_rate.u.LowPart / 1000000.0; // convert to us
tick_count = (int)(time you want to wait in us) * freq;

QueryPerformanceCounter(&start_tick);// Get start time
do {
QueryPerformanceCounter(&current_tick);// check start time
ticks_passed = current_tick.u.LowPart - start_tick.u.LowPart;
if (ticks_passed & 0x80000000) {
ticks_passed = -ticks_passed;// rolled over 32 bit
}
} while (ticks_passed < tick_count);// wait for minimum time

It will generate the desired delay most of the time except during Windows interrupts. Just watch for clock rollover, or use 64 bit integers.
Message 13 of 18
(2,437 Views)
A delay of less than 1mS is certainly possible. It requires that you define a function with a timeing loop.

eg:
void myDelay(int loops)
{
while(loops > 0)
{
loops--;
}

}
For a PC with uP speeds in the gigaHerts, this should yeild the ability to get a delay of much less than one uS. Caution: It will loop at different speeds in debug than for release runs. You must characterize the speed of your application by entering different values for the integer "loop", and taking note of the response time. I would suggest using large and varying values of "loops" in both run modes (release and debug) to assign typical durations per cycle, . Use the precompilor defines to check _CVI_DEBUG_ to set the duration. I used code similar to this to program a EEPROM, which required specific timing.

See attached project for example... (if the attachment does not come through, let me know and I will sent it to you another way)

Hope this helps
0 Kudos
Message 14 of 18
(2,428 Views)
I'd like to try the QueryPerformanceCounter as shown in the example in this thread.
 
Simply adding  include "winnt.h"  causes several syntax and redeclaration errors in winnt.h and basetsd.h
 
I'm using XP Pro and CVI  6.0.
 
Compatibility issue perhaps?
 
Any insights are appreciated.
 
Thanks,
 
Scott T.
0 Kudos
Message 15 of 18
(2,323 Views)

Forget Winnt.h

Simply add to the top of the program
#include <Windows.h>  and things should work.

wfc

0 Kudos
Message 16 of 18
(2,315 Views)
Thank you wfc. That did the trick.
0 Kudos
Message 17 of 18
(2,312 Views)

Well,

  If you aren't using PXI or one of the other NI technologies that can natively handle PWM, there are industrial PWM controllers available--catalogs full of stuff like this--for all different voltages.  If your hardware isn't designed for PWM, using Windows and CVI to artificially do it is just spinning your wheels.  It isn't even worth your time to try to program something like this, and it isn't worth your money to get a realtime kernel that will run in parallel with a Windows kernel--and there are some available... $$$

Orlan

0 Kudos
Message 18 of 18
(2,310 Views)