Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

The problem is to monitor two experimental parameters

The problem is to monitor two experimental parameters (pressure and temperature) using USB -6008. These parameters are converted to voltage by proper sensors.

I use the following sequence of commans:

DAQmxBaseCreateTask("T",&taskHandle);

DAQmxBaseCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Diff,-10,10,DAQmx_Val_Volts,NULL);

DAQmxBaseCreateAIVoltageChan(taskHandle,"Dev1/ai1","",DAQmx_Val_Diff,-1,1,DAQmx_Val_Volts,NULL);

DAQmxBaseStartTask(taskHandle);

Then I read the results every 200 msec. To do this I put into the Timer event handler next code:

{ DAQmxBaseReadAnalogF64(taskHandle,1,timeout,0,data,2,&pointsRead,NULL);
data[0] I convert to pressure;
data[1] I convert to temperature;
}

The program works, but I am not satisfied because of noise. The origin of the noise is electric interference of power network. I know that the best way to reduce electrical interference is to integrate a signal over period of the power network (20 msec in Russia). All high sensitivity digital voltmeters do this integration. The idea is to make, for example, 40 measurements with SampleRate=2000 , ( 0.5 msec * 40 = 20 msec) instead of single measurement. Then calculate the sum of pressure readouts and the sum of temperature readouts. This procedure should be repeated every 200 msec using the Timer event handler.

Therefore I added before DAQmxBaseStartTask(taskHandle);

DAQmxBaseCfgSampClkTiming (taskHandle, source, sampleRate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 40);

and modified Timer event handler:

{ DAQmxBaseReadAnalogF64(taskHandle,40,timeout,0,data,80,&pointsRead,NULL);
data[0] … data[39] I convert to pressure;
data[40] … data[79] I convert to temperature;
}

Testing of the program showed: the program can make only one cycle of measurement. All times I call the DAQmxBaseReadAnalogF64 the results were the same. It looks like USB-6008 make one cycle of measurement (probably at DAQmxBaseStartTask) and puts the results to the buffer. And the DAQmxBaseReadAnalogF64 just read the buffer but can not initiate new measurements.

How the program can initiate new cycle of measurements? Could anybody to help me?
0 Kudos
Message 1 of 8
(4,478 Views)
If you are using a Windows based machine, I would strongly recommend changing to the DAQmx driver.  This site has the Advantages of NI-DAQmx.  It is a much more robust driver and it will be easy to convert your code as most of the functions calls pass the same parameters and the names are the same without Base (ie: DAQmxBaseCreateTask becomes DAQmxCreateTask).
 
You can make the task continuous by changing the parameter DAQmx_Val_FiniteSamps in the DAQmxBaseCfgSampClkTiming to DAQmx_Val_ContSamps and then reading 40 samples at a time.  This will acquire samples until you stop the task.
 
Good luck!
Micaela N
National Instruments
0 Kudos
Message 2 of 8
(4,458 Views)

Dear Micaela,

 

Thank you for advice. I will change driver  to the DAQmx . But it will take time to download 460 M.

Therefore I continued with the old driver.           

I changed DAQmxBaseCfgSampClkTiming to DAQmx_Val_ContSamps and immediately faced with  another problem.   The device began to acquire data continuously, and when I call DAQmxBaseReadAnalogF64 in the timer handler, I got the date that does not correspond to the current time. The data corresponds to the experimental parameters which were 5 minutes ago. I was very surprised until I realized that this huge delay exits!

 

To fix this problem I tried to add DAQmxBaseStartTask and DAQmxBaseStopTask  to the timer handler.

{

     DAQmxBaseStartTask(taskHandle);

     DAQmxBaseReadAnalogF64(taskHandle,40,timeout,0,data,80,&pointsRead,NULL);

     DAQmxBaseStopTask(taskHandle);


    data[0] … data[39] I convert to pressure;
     data[40] … data[79] I convert to temperature;

}

The program did not work. Even did not respond to any action.

 

0 Kudos
Message 3 of 8
(4,438 Views)

Should I add some time delay after     DAQmxBaseStartTask and     DAQmxBaseStopTask ?

Is it  right way to put DAQmxBaseStartTask and     DAQmxBaseStopTask to the timer hanler ?

Or I have to use Triggering possibilities of this device ( for example use one digital input as triggering source, another digital output to generate triggering signal and connect them by wire)?

 

And one more question. Where I can find more examples  how to use NI-DAQmx functions in C? I saw a lot of LabView examples, but I do not want to learn LabView.

 

Thanks in advance.

 

Victor.

0 Kudos
Message 4 of 8
(4,438 Views)
vkhodorchenko ha scritto:

DAQmxBaseCreateTask("T",&taskHandle);
DAQmxBaseCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Diff,-10,10,DAQmx_Val_Volts,NULL);

DAQmxBaseCreateAIVoltageChan(taskHandle,"Dev1/ai1","",DAQmx_Val_Diff,-1,1,DAQmx_Val_Volts,NULL);


I didn't know that it was possibile to call twice
DAQmxBaseCreatAIVoltageChan() for the same task.

Is it possible "join" to one task more
DAQmxBaseCreatAIVoltageChan() istances?

Thanks.

0 Kudos
Message 5 of 8
(4,424 Views)
Frank,

It is possible to add channels by creating new ones with the same task handle. They will be added to the task one by one.

Regards,
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 6 of 8
(4,398 Views)

Hi Frank,

As Ryan stated: you can add channels to an existing task, however, you cannot have multiple analog input tasks running at the same time or you will receive an error. This is because there is only one analog input sample clock and it cannot be used twice at the same time. If all of the channels are in the same task, then only the one sample clock will be used and everything will work great.

I hope that you find this information helpful.

Regards,
Hal L.

0 Kudos
Message 7 of 8
(4,394 Views)
Victor,

You should either use DAQmx_Val_ContSamps OR your StartTask / StopTask event handler. Whenever you specify continuous samples, you will continuously acquire data at 2000 Hz. If you read only 40 samples every 200msec, your data will get older and older, relative to your read time, until the buffer overflows. You could use this method and acquire data every 20msec or less. Alternatively, you could use DAQmx_Val_FiniteSamps and start and stop the task in your read loop.

Programming examples for NI-DAQmx in C can be found in the C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C directory.

Hope this helps,
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 8 of 8
(4,393 Views)