LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Understanding dig pulse train and measure period example

Hello NIDAQ support,

I am very new to NIDAQmx programming and concepts of 6602. I have inherited some code by previous developer which uses legacy NIDAQ C++ functions.

I am tasked to migrate code to DAQmx. Currently I have setup a simulated PCI 6602 using MAX to familiarize myself with 6602 hardware and DAQmx functions.

I have been trying to get the following 2 examples to work together but I am not successful - most likely because of my lack of understanding of DAQmx function calls and PCI 6602

<ROOT>\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Generate Pulse\Dig Pulse Train-Cont

<ROOT>\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Measure Period or Pulse Width\Buff Semi-Period-Finite

The "Dig Pulse Train-Cont" sample added a note saying I should use Period Measurement example to make sure pulse train is outputed to DAQ device, so I pretty much cut&paste the "Buff Semi-Period-Finite" sample to "Dig Puse Train-Cont" sample.

 In a nut shell,

 - I create a pulse gen task using ctr2

 - I create a period measure task using ctr0

 - I route ctr2internaloutput to ctr0

- I start both task

- I try to get value from ctr0. The value I read back is always 0.

I have been surfing this forum for several days and playing with the DAQmx functions but I am still lost 😞

I hope someone can provide some input as to what I'm doing wrong.

I have attached the following code below.

Thanks,

Geoff


TaskHandle pulseHandle=0;

TaskHandle hReadCtr0;

//Create pulse task

DAQmxErrChk (DAQmxCreateTask("",&pulseHandle));

DAQmxErrChk (DAQmxCreateCOPulseChanFreq(pulseHandle,

"Dev1/ctr2","",DAQmx_Val_Hz,DAQmx_Val_Low,0.0,1.0,0.50));

DAQmxErrChk (DAQmxCfgImplicitTiming(pulseHandle,DAQmx_Val_ContSamps,1000));

//Create period measure task

DAQmxErrChk(DAQmxCreateTask(

"ReadCtr0",&hReadCtr0));

DAQmxErrChk (DAQmxCreateCISemiPeriodChan(hReadCtr0,

"Dev1/ctr0","",0.000000100,0.838860750,DAQmx_Val_Seconds,""));

DAQmxErrChk (DAQmxCfgImplicitTiming(hReadCtr0,DAQmx_Val_ContSamps,1000));

//Route output signal to from ctr2 to ctr0

DAQmxErrChk(DAQmxSetCIPeriodTerm(hReadCtr0,

"/Dev1/Ctr0","/Dev1/ctr2InternalOutput"));

//Start tasks

DAQmxErrChk (DAQmxStartTask(pulseHandle));

DAQmxErrChk (DAQmxStartTask(hReadCtr0));

//Try to verify I am outputing pulse train on DAQ device

while

(1)

{

uInt32 count0;

DAQmxReadCounterScalarU32(hReadCtr0,-1,&count0,0);

if(count0!=0)

printf(

"coutn0=%d\n",count0);

}


 

0 Kudos
Message 1 of 4
(3,248 Views)
Hi Geoff,
Are you using the simulated devices to get the example code to work? You will not be able to see real data with simulated devices.
The example programs are always a great place to start. If you have a 6602 board you should test an example program without modifications. Did you receive any errors when you ran an example program? Make sure you are referencing the correct device and channel. If you are new to DAQmx you should check out this Getting Started with DAQmx Series. I hope this helps.
Regards,

Ima
Applications Engineer
National Instruments
LabVIEW Introduction Course - Six Hours
Getting Started with NI-DAQmx
0 Kudos
Message 2 of 4
(3,220 Views)

Hello Ima,

Thanks very much for your reply. I apoligize in advance for this long message 🙂

I am interested in the 2-Edge buffered measurement, Pulse Width Buffered measurement, and Period Buffered measurement.

<ROOT>\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Measure Period or Pulse Width\Buff Semi-Period-Finite

<ROOT>\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Measure Period or Pulse Width\Pulse Width-Buff-Samp Clk-Cont

<ROOT>\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Measure 2 Edge Separation\Two Edge Separation-Buff-Cont

And Yes. I just realize I should use the actual 6602 hardware and not simulated but when I try running any of the buffered examples I am always getting DAQ error -200279, indicating that the buffer is being overwritten before I have a chance to read the data. Note: no modification to provided samples.

As for referencing the correct channels, I am still trying to figure out the right DAQmx functions.  I have added sample DAQ legacy code below and have been trying to figure out the DAQmx equivilent function. Can you help me figure out the equivilent DAQmx functions from sample code below?

NOTE: The program that I am trying port from legacy DAQ to new DAQmx measures data signals from monitors ( e.g. LCD, DFP, CRT, etc ...). User tells program what type of buffered measurement ( 2 edge, pulse, or period ) to use and what lines to connect ( SRC1, GATE1, etc...) to the counter.

Any insight would be appreicated.

Thanks in advance.

Geoff

 

SAMPLE CODE:

==============================================

#define

CLK_80MHZ ND_INTERNAL_MAX_TIMEBASE

#define SRC_3 ND_PFI_27

#define

GATE_3 ND_PFI_26

#define

AUX_3 ND_PFI_25

//... other defines for every pin

...

// Reset the counter

pGPCTR_Control( device, timerId, ND_RESET ) ; // what DAQmx  equivilent of this function?

// Period measurement

pGPCTR_Set_Application( device, timerId, ND_BUFFERED_PULSE_WIDTH_MSR ); // = DAQmxCreateCIPulseWidthChan()

pGPCTR_Change_Parameter( device, timerId, ND_GATE, GATE_3 ) ; // what is DAQmx equivlent of this function? is it DAQmxConnectTerms()?

 pGPCTR_Change_Parameter( device, timerId, ND_GATE_POLARITY, ND_POSITIVE ) ; // what is DAQmx equivlent of this function?

// Select source input/polarity

pGPCTR_Change_Parameter( device, timerId, ND_SOURCE, CLK_80MHZ ) ; // what is DAQmx equivlent of this function? is it DAQmxConnectTerms()?

pGPCTR_Change_Parameter( device, timerId, ND_SOURCE_POLARITY, ND_POSITIVE ) ; // what is DAQmx equivlent of this function

 

//Select trigger

pSelect_Signal( device, ND_START_TRIGGER, GATE_4, ND_POSITIVE); // what is DAQmx equivlent of this function?

 

// Select Synchronous Mode if applicable to the Counter

pGPCTR_Change_Parameter( device, timerId, ND_COUNTING_SYNCHRONOUS, ND_YES ) // what is DAQmx equivlent of this function?

 

//Configure the buffer to store the periods

pGPCTR_Change_Parameter( device, timerId, ND_BUFFER_MODE, ND_SINGLE  ); // what is DAQmx equivlent of this function?

 

// Set triggering mode (by hardware signal or automatically)

if( m_triggered )

 pGPCTR_Change_Parameter( device, timerId, ND_START_TRIGGER, ND_ENABLED ) ; // what is DAQmx equivlent of this function?

else

 pGPCTR_Change_Parameter( device, timerId, ND_START_TRIGGER, ND_AUTOMATIC  ); // what is DAQmx equivlent of this function?

 

0 Kudos
Message 3 of 4
(3,204 Views)
Hi Geoff,

To transition from Traditional DAQ to DAQmx is not always the most straight forward task. There is not always an exact equivalent function call that translates from TDAQ to DAQmx and DAQmx is more powerful. I will gave to go thru your code line by line and figure out what it is doing to understand how to translate it to DAQmx. I don't have much experience in Traditional DAQ so my suggestion is to start with DAQmx example code that does what you are looking to do. You can find examples in the following default directory location: C:\Program Files\National Instruments\MeasurementStudio70\VCNET\Examples\DAQmx or C:\Program Files\National Instruments\MeasurementStudioVS2003\VCNET\Examples\DAQmx. Double-click the .vcproj file to open the project.
Regards,

Ima
Applications Engineer
National Instruments
LabVIEW Introduction Course - Six Hours
Getting Started with NI-DAQmx
0 Kudos
Message 4 of 4
(3,184 Views)