Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

increase scan rate

Hi all
 
 I am pretty new to using DAQ card .The card I am using is 6062-E.I need to increase the sampling rate .Currently in the code I am using it is 100k.I need to increase it to probably 500k as this is the max sampling rate of my card.What parameters I need to change in the code.Please have a look at my code. Thanks.Currently the no of sample points in one period are 5000.
#include "nidaqex.h"
#include <stdio.h>

/*
 * Main:
 */
void main(void)
{
    /*
     * Local Variable Declarations:
     */
    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iChan0 = 0;               // using channel 0 for laser signal
 i16 iChan8 = 8;               // using channel 8 for delfection angle signal
    i16 iStartTrig = 0;
    i16 iExtConv = 1;
    i16 iGain = 1;
    u32 ulCount = 10000;         // sample 5000 pts each channel
    f64 dGainAdjust = 1.0;
    f64 dOffset = 0.0;
   
    f64 dScanRate = 100000.0;
    i16 iSampTB = 0;
    u16 uSampInt = 0;
 i16 iScanTB = 0;
 u16 uScanInt = 0;
 i16 iUnits = 0;
    static i16 piBuffer[2][5000] = {0};
    static f64 pdVoltBuffer[2][5000] = {0.0};
    static i16 piChanVect[2] = {0, 8};
 static i16 piGainVect[2] = {1,1};
 i16 iInputMode = 1;
 i16 iInputRange = 10;
 i16 polarityChan0 = 0;
 i16 polarityChan8 = 0;
 i16 driveAIS = 1;
    i16 iNumMUXBrds = 0;
 i16 iNumChans = 2;
 
 i16 iDAQstopped = 0;
    u32 ulRetrieved = 0;
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;
 u32 i=0,j=0,k=0;
 FILE *fp;
    /* Setup Channel 0 */
    iStatus = AI_Configure(iDevice, iChan0, iInputMode,iInputRange, polarityChan0,driveAIS);
 iRetVal = NIDAQErrorHandler(iStatus, "AI_Configure",iIgnoreWarning);
 /* Setup Channel 8 */
 iStatus = AI_Configure(iDevice, iChan8, iInputMode, iInputRange, polarityChan8, driveAIS);
 iRetVal = NIDAQErrorHandler(iStatus, "AI_Configure", iIgnoreWarning);
    /* Setup for external conversions into PFI2 with iExtConv = 1. */
    iStatus = Select_Signal(iDevice, ND_IN_CONVERT, ND_PFI_2,
     ND_LOW_TO_HIGH);
    iRetVal = NIDAQErrorHandler(iStatus, "Select_Signal",
     iIgnoreWarning);
    iStatus = DAQ_Config(iDevice, iStartTrig, iExtConv);
    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_Config",
     iIgnoreWarning);
    /* Instead of calling DAQ_Rate, let iSampTB be 0. */
    /* Acquire data from a single channel */
    /*************************************************************   
 iStatus = DAQ_Start(iDevice, iChan, iGain, piBuffer, ulCount,
     iSampTB, uSampInt);
    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_Start", iIgnoreWarning);
   
    *****************************************************************/
     iStatus = DAQ_Rate(dScanRate, iUnits, &iScanTB, &uScanInt);
     iStatus = SCAN_Setup(iDevice, iNumChans, piChanVect, piGainVect);
   
     iRetVal = NIDAQErrorHandler(iStatus, "SCAN_Setup",
     iIgnoreWarning);
 iStatus = SCAN_Start(iDevice, &piBuffer[0][0], ulCount, iSampTB, uSampInt, iScanTB, uScanInt);
    printf(" Apply your external conversion clock signal to PFI2.\n");
    while ((iDAQstopped != 1) && (iStatus == 0)) {

        /* Loop until all acquisition is complete.  HINT: You can be
         doing other foreground tasks during this time. */
        iStatus = DAQ_Check(iDevice, &iDAQstopped, &ulRetrieved);
       
        iRetVal = NIDAQYield(iYieldON);
    }

    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_Check", iIgnoreWarning);
   
 iStatus = SCAN_Demux(&piBuffer[0][0], ulCount, iNumChans, iNumMUXBrds);
   
    iRetVal = NIDAQErrorHandler(iStatus, "SCAN_Demux",
     iIgnoreWarning);
    iStatus = DAQ_VScale(iDevice, iChan0, iGain, dGainAdjust, dOffset,
     ulCount, &piBuffer[0][0], &pdVoltBuffer[0][0]);
    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_VScale",
     iIgnoreWarning);
    /* CLEANUP - Don't check for errors on purpose. */
    /* Set sample timing back to initial state. */
    iStatus = DAQ_Config(iDevice, 0, 0);
    /* Set PFI line back to initial state. */
    iStatus = Select_Signal(iDevice, ND_IN_CONVERT, ND_INTERNAL_TIMER,
     ND_LOW_TO_HIGH);
    DAQ_Clear(iDevice);
    /* Plot acquired data */
    iRetVal = NIDAQPlotWaveform(pdVoltBuffer, ulCount, WFM_DATA_F64);
   
    printf(" The data is available in 'pdVoltBuffer'.\n");
 fp = fopen("datacalibrate12.dat", "w");
 if(fp==NULL)
 {
       printf("Can't open data.dat!");
    exit(1);
   
 }
   
 for(i=0; i<(ulCount/2);i++)
 {
  fprintf(fp,"%f\t%f\n",pdVoltBuffer[0][i],pdVoltBuffer[1][i]);
 }
    fclose(fp);
 printf("file has been written");
 
}
/* End of program */
0 Kudos
Message 1 of 2
(3,174 Views)

Hi,

If you're new to DAQ, you might want to start with DAQmx anyway. That code you attached is Traditional NI-DAQ (Legacy) code but your card does support both drivers. Your current code is using an external clock, so you're actually going to acquire at whatever rate you input into PFI 2. If you want to use an internal clock, you set the rate with the  "dScanRate = 100000.0;" constant which gets used in the "DAQ_Rate(dScanRate, iUnits, &iScanTB, &uScanInt);" call.

For DAQmx, check out the Acq-Ext Clk example from "C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Acq-Ext Clk".

Performs the same functionality in DAQmx but you would need to add the file I/O.

Hope this helps,

Andrew S

National Instruments

0 Kudos
Message 2 of 2
(3,134 Views)