08-13-2007 08:44 AM
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){
DAQmxReadCounterScalarU32(hReadCtr0,-1,&count0,0); if(count0!=0)uInt32 count0;
"coutn0=%d\n",count0);printf(
}
08-14-2007 05:42 PM
08-15-2007 09:04 AM
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?
08-17-2007 02:43 AM