Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting Traditional to NIDAQmx C++ Code

 

I am trying to upgrade my C++ code from Traditional to NIDAQmx, and I am having hard time finding equivalent terms between the 2 drivers at times, but here is the hardware configuration and the NIDAQmx code I have. Can any one let me know if this is the right code and provide suggestions if possible?  (for 16-MIO E series boards)

 

- I would like to use an Encoder hooked to PFI7 as external Sampling Clock source (Ctr0)

- I would like to use PFI4 as Once Per Revolution Counter (Ctr1)

- I have 8 Analog Channels

- I need Buffered Edge Counting and continuous sampling

- I expect to read 48000 S/s per channel and 384,000 S/s per 8 channels and this is within range of the advertised 500,000 S/s

 

SamplingRate = 500,000/NumberOfChannels;

 

//////////PFI7 - Ctr0          

DAQmxErrChk(pDAQmxCreateCICountEdgesChan(m_taskHandle,"Dev1/ctr1","Time Counter",DAQmx_Val_Falling,Initial_Count,DAQmx_Val_CountUp));            

DAQmxErrChk(pDAQmxSetCICountEdgesTerm(m_taskHandle,"Dev1/Ctr1","/Dev1/20MHzTimebase");     

DAQmxErrChk(pDAQmxCfgSampClkTiming(m_taskHandle,"/Dev1/PFI7",Rate,DAQmx_Val_Falling,DAQmx_Val_ContSamps,m_NIBufferSize/NumberOfChannels)); // using PFI7

 DAQmxErrChk(pDAQmxStartTask(m_taskHandle));

         

  

////////////PFI4 – Ctr1        

 DAQmxErrChk(pDAQmxCreateCICountEdgesChan(m_taskHandle1,"Dev1/ctr0","Revolution Counter",DAQmx_Val_Falling,Initial_Count,DAQmx_Val_CountUp));            

DAQmxErrChk(pDAQmxSetCICountEdgesTerm(m_taskHandle1,"Dev1/Ctr0","/Dev1/20MHzTimebase");

DAQmxErrChk(pDAQmxCfgSampClkTiming(m_taskHandle1,"/Dev1/PFI4",Rate,DAQmx_Val_Falling,DAQmx_Val_ContSamps,m_NIRevsToAverage)); // using PFI4

DAQmxErrChk(pDAQmxStartTask(m_taskHandle1));

   

////////////////// Analog – 2 channels in this case            

DAQmxErrChk(pDAQmxCreateAIVoltageChan(m_taskHandle2,"Dev1/ai0:1","Pressure Channels",DAQmx_Val_RSE,m_MinVal,m_MaxVal,DAQmx_Val_Volts,NULL));

DAQmxErrChk(pDAQmxCfgSampClkTiming(m_taskHandle2,"/Dev1/PFI7",Rate,DAQmx_Val_Falling,DAQmx_Val_ContSamps,m_NIBufferSize/m_NIChannelArray.GetSize()));

//DAQmxErrChk(pDAQmxSetChanAttribute(m_taskHandle2,"Dev1/ai0:1",DAQmx_AI_Gain,2));  

//DAQmxErrChk(pDAQmxSetAIConvRate(m_taskHandle2,ConvertClock)); // A/D interchannel time scan intervals, 5 usec default

DAQmxErrChk(pDAQmxSetAIConvSrc(m_taskHandle2,ConvertClkTimeBase));

DAQmxErrChk(pDAQmxRegisterEveryNSamplesEvent(m_taskHandle2,DAQmx_Val_Acquired_Into_Buffer,m_NIBufferSize/m_NIChannelArray.GetSize(),0, &CCommunication::EveryNCallback,this));

DAQmxErrChk (pDAQmxCfgInputBuffer(m_taskHandle2,m_BufferSize*2));

DAQmxErrChk(pDAQmxStartTask(m_taskHandle2)); 

   

///////////////////////READ////////////

/// Read Analog  

pDAQmxReadBinaryI16 (m_taskHandle2,m_NIBufferSize/NumberOfChannels,0.000012, DAQmx_Val_GroupByScanNumber ,HoldBuffer,m_NIBufferSize,&PointsCollected, NULL);

/// Read Counter 

pDAQmxReadCounterU32(m_taskHandle,m_NIBufferSize/NumberOfChannels,0.000012,TimeBuffer,m_NIBufferSize,&NumberReadOnTimeCounter,NULL);

pDAQmxReadCounterU32(m_taskHandle1,m_NIBufferSize/NumberOfChannels,0.000012,TimeBuffer,m_NIBufferSize,&NumberReadOnTimeCounter,NULL);

 

 

//////////// Stop and Clear Tasks /////////////////

                 

 

                 
0 Kudos
Message 1 of 2
(6,145 Views)
I would recommend you take a look at the example code that ships with the DAQmx driver.  It is located under Start»Programs»National Instruments»DAQ»Text Based Code Support.  There are a lot of good example that show edge counting, analog input, so on and so forth.  The best way to see if the code will work as well is to just run it and see what happens.  I would probably start piecemeal as well, get the encoder working, then analog input, etc.  A cursory glance and comparison with examples looked pretty good to me.
Doug Farrell
Solutions Marketing - Automotive
National Instruments

National Instruments Automotive Solutions
0 Kudos
Message 2 of 2
(6,114 Views)