Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

synchronization between current channel and voltage channel in compactDAQ

Hi,

 

I am new to this forum and relatively new to National Instrument.

 

I have started using Visual Studio for ANSI C a few week ago. I am using NI cDAQ-9178 equipment, NI9227 module for current measurement, and NI9239 module for voltage measurement. I am trying to get synchronization work for 2 current channels in NI9227 (cDAQMod1/ai0: cDAQMod1/ai1) and 2 voltage channels in NI9239 (cDAQMod2/ai0: cDAQMod2/ai1).

 

Question 1:

How to synchronize these 4 channels together? Is there any synchronization sample code available for compactDAQ?

 

I started by looking at the example code in: National Instruments/NI-DAQ/Examples/DAQmx ANSI C/Synchronization/Multi-Device.

The example code list synchronization example for E & S Series, M Series sharing reference clock for PCI Devices, M Series sharing reference clock for PXI Device, DSA sharing sample clock, reference clock 10 synchronization for DSA devices. However, these example code does not apply on my case, since I am using compactDAQ.



Question 2:

How to measure 2 voltage channels (cDAQMod2/ai2: cDAQMod2/ai3) in NI9239 simultaneously?

 

I have wire connected between channel cDAQMod2/ai2 and cDAQMod2/ai3, a wire connection between cDAQMod2/ai2+ and cDAQMod2/ai3+, and a wire connection between cDAQMod2/ai2- and cDAQMod2/ai3-. So the voltage signal shall be the same between two channels.

I have tried to synchronize 2 voltage channels (cDAQMod2/ai2: cDAQMod2/ai3) in NI9239, and I am using the following function:

 

DAQmxCreateAIVoltageChan(taskHandle,"cDAQMod2/ai2:cDAQMod2/ai3","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL)

 

However, when I read voltage data out, the voltage number measured between these two channels are not the same. Is it not scan two channel simultaneously? Is it scan the two channel sequentially, how much of time period between each scan?

 

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

Hi JaneGuo123,

 

I am looking at the ContAcq-IntClk-AnlgStart example.

 

There is the code snippet:

/*********************************************/
// DAQmx Configure Code
/*********************************************/
SetWaitCursor(1);
DAQmxErrChk (DAQmxCreateTask("",&gTaskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(gTaskHandle,chan,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(gTaskHandle,"",rate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,sampsPerChan));
DAQmxErrChk (DAQmxCfgAnlgEdgeStartTrig(gTaskHandle,triggerSource,triggerSlope,triggerLevel));
DAQmxErrChk (DAQmxSetTrigAttribute (gTaskHandle, DAQmx_AnlgEdge_StartTrig_Hyst,triggerHyst));
DAQmxErrChk (DAQmxGetTaskAttribute(gTaskHandle,DAQmx_Task_NumChans,&gNumChannels));

if( (gData=malloc(sampsPerChan*gNumChannels*sizeof(float64)))==NULL ) {
MessagePopup("Error","Not enough memory");
goto Error;
}

DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(gTaskHandle,DAQmx_Val_Acquired_Into_Buffer,sampsPerChan,0,EveryNCallback,NULL));
DAQmxErrChk (DAQmxRegisterDoneEvent(gTaskHandle,0,DoneCallback,NULL));

 

We want to pay attention to the DAQmx Create Channel function. In order to do all the things you want, all you need to do is add more channels to the task. Make sure the task handle is the same for all of them.

 

For example, it will look like this:

DAQmxErrChk (DAQmxCreateAIVoltageChan(gTaskHandle,chan,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCreateAIVoltageChan(gTaskHandle,chan2,"",DAQmx_Val_Cfg_Default,min2,max2,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCreateAICurrentChan (gTaskHandle, chan3, "", DAQmx_Val_Cfg_Default, min3, max3, DAQmx_Val_Amps, DAQmx_Val_Default, 249.0, ""));
DAQmxErrChk (DAQmxCreateAICurrentChan (gTaskHandle, chan4, "", DAQmx_Val_Cfg_Default, min4, max4, DAQmx_Val_Amps, DAQmx_Val_Default, 249.0, ""));

 

You will have to modify this code to match the channels you want specifically, but this should help.

 

It is called "channel expansion"

 

When you call the DAQmx read it will read all of them simultaneously.

 

 

Michael Bilyk
Former NI Software Engineer (IT)
0 Kudos
Message 2 of 4
(4,992 Views)

Hi,

Thanks a lot.

How should I setup Trigger Source? Or may be there's no Analog trigger source for this chasis.

I tried "PFI0" and "PFI1", it doesn't seem to work.

 

Here's the error message:

"DAQmx Error: An Attempt has been made to use an invalid analog trigger source.

Ensure that the trigger source you specify matches the name if the virtual channel in the task or matches the name of a non-scannable terminal that the device can use as an analog trigger source."

0 Kudos
Message 3 of 4
(4,988 Views)

You need to analog trigger off of an analog line.

Michael Bilyk
Former NI Software Engineer (IT)
0 Kudos
Message 4 of 4
(4,978 Views)