Ejemplo n.º 1
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iPort = 0;
    i16 iLine = 0;
    i16 iDir = 0;
    i16 iState = 0;
    i16 iIgnoreWarning = 0;

    /* Configure line as input. */

    /* NOTE: Some devices do not support DIG_Line_Config.  Use
     DIG_Prt_Config instead. */

    iStatus = DIG_Line_Config(iDevice, iPort, iLine, iDir);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Line_Config",
     iIgnoreWarning);

    iStatus = DIG_In_Line(iDevice, iPort, iLine, &iState);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_In_Line",
     iIgnoreWarning);

    printf(" The digital state on port %d line %d is %d\n", iPort, iLine, iState);


}
Ejemplo n.º 2
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iChassisID = 1;
    i16 iModuleSlot = 1;
    i16 iPort = 0;
    i16 iChan = 0;
    u32 ulData = 0;
    i16 iIgnoreWarning = 0;

    iStatus = SCXI_Load_Config(iChassisID);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_Load_Config",
     iIgnoreWarning);

    /* Get the state of the digital line.  If you set 'iChan' to -1,
     you can read the entire port. */

    iStatus = SCXI_Get_State(iChassisID, iModuleSlot, iPort, iChan,
     &ulData);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_Get_State",
     iIgnoreWarning);

    printf(" Data at line %d is %lu\n", iChan, ulData);


}
Ejemplo n.º 3
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iChan = 0;
    i16 iOutputPolarity = 0;
    i16 iIntOrExtRef = 0;
    i16 iUpdateModeEXT = 2;
    i16 iUpdateModeINT = 0;
    f64 dRefVolts = 10.0;
    f64 dVoltage = 2.5;
    i16 iIgnoreWarning = 0;

    /* For best results, look at the output with a scope. */

    /* Set output at 0 volts. */

    iStatus = AO_VWrite(iDevice, iChan, 0.0);

    /* Configure for bipolar mode, internal reference, and external
     updates. (The 'dRefVolts' is ignored since this is internally
     referenced.) */

    iStatus = AO_Configure(iDevice, iChan, iOutputPolarity,
     iIntOrExtRef, dRefVolts, iUpdateModeEXT);

    iRetVal = NIDAQErrorHandler(iStatus,
     "AO_Configure/ExternalUpdate", iIgnoreWarning);

    printf(" Apply the 'external update' pulse to output %lf volts and hit any key.\n", dVoltage);

    iStatus = AO_VWrite(iDevice, iChan, dVoltage);

    iRetVal = NIDAQErrorHandler(iStatus, "AO_VWrite", iIgnoreWarning);
    

    iRetVal = NIDAQWaitForKey(0.0);

    printf(" Did you see the voltage appear on analog output channel %d ?\n", iChan);

    /* Don't check for errors on purose. */

    /* Set update mode back to initial state. */

    iStatus = AO_Configure(iDevice, iChan, iOutputPolarity,
     iIntOrExtRef, dRefVolts, iUpdateModeINT);


}
Ejemplo n.º 4
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i32 lTimeout = 180;
    i16 iChan = 1;
    i16 iGain = 1;
    f64 dSampRate = 1000.0;
    u32 ulCount = 1000;
    char* strFilename = "DAQdata.DAT";
    i16 iIgnoreWarning = 0;

    /* This sets a timeout limit (#Sec * 18ticks/Sec) so that if there
     is something wrong, the program won't hang on the DAQ_to_Disk call.
     */

    iStatus = Timeout_Config(iDevice, lTimeout);

    iRetVal = NIDAQErrorHandler(iStatus, "Timeout_Config",
     iIgnoreWarning);

    /* Acquire data from a single channel and store to disk. The data
     is stored in 16-bit little endian binary form. You can make your own
     file I/O calls to read them, or use the WFMfrDisk program to output
     the same data. */

    /* HINT: If you are using a Lab or 1200 series device, replace
     this function with Lab_ISCAN_to_Disk. */

    iStatus = DAQ_to_Disk(iDevice, iChan, iGain, strFilename, ulCount,
     dSampRate, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_to_Disk",
     iIgnoreWarning);

    if (iStatus == 0) {


        printf(" Acquired data successfully stored to file: %s\n", strFilename);

    }


    /* Disable timeouts. */

    iStatus = Timeout_Config(iDevice, -1);


}
Ejemplo n.º 5
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iChassisID = 1;
    i16 iModuleSlot = 1;
    i16 iPort = 0;
    i16 iChan = 0;
    u32 ulDataON = 1;
    u32 ulDataOFF = 0;
    i16 iIgnoreWarning = 0;

    iStatus = SCXI_Load_Config(iChassisID);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_Load_Config",
     iIgnoreWarning);

    /* Toggle the state of the digital line.  If you set 'iChan' to
     -1, you can set the entire port. */

    iStatus = SCXI_Set_State(iChassisID, iModuleSlot, iPort, iChan,
     ulDataON);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_Set_State",
     iIgnoreWarning);

    /* Wait 1 sec (for slower modules). */

    iRetVal = NIDAQDelay(1.0);

    iStatus = SCXI_Set_State(iChassisID, iModuleSlot, iPort, iChan,
     ulDataOFF);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_Set_State",
     iIgnoreWarning);


}
Ejemplo n.º 6
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iChassisID = 1;
    i16 iModuleSlot = 1;
    i16 iChan = 0;
    i16 iOpCode = 0;
    i16 iRangeCode = 6;
    f64 dCurrData1 = 5.0;
    f64 dCurrData2 = 0.0;
    i16 iBinWritten = 0;
    i16 iIgnoreWarning = 0;

    iStatus = SCXI_Load_Config(iChassisID);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_Load_Config",
     iIgnoreWarning);

    /* First, set the current to dCurrData1. */

    iStatus = SCXI_AO_Write(iChassisID, iModuleSlot, iChan, iOpCode,
     iRangeCode, dCurrData1, 0, &iBinWritten);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_AO_Write",
     iIgnoreWarning);

    /* Then, set the current to dCurrData2. */

    iStatus = SCXI_AO_Write(iChassisID, iModuleSlot, iChan, iOpCode,
     iRangeCode, dCurrData2, 0, &iBinWritten);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_AO_Write",
     iIgnoreWarning);


}
Ejemplo n.º 7
0
   int checkError
   (
      short    status,
      char *message,
      bool   warn
   ) 
   {
      if (status)
      {
         return NIDAQErrorHandler(status, message, warn);
      }

      return 0;
   }
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    u32 ulGpctrNum = ND_COUNTER_0;
    u32 ulCount = 0;
    u32 ulArmed = ND_YES;
    u32 ulTCReached = ND_NO;
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/RESET",
     iIgnoreWarning);

    /* The ND_TRIG_PULSE_WIDTH_MSR should be used in the context of a
     continuous pulse train.  The GPCTR_Program function will arm the
     counter at the first 'trigger' edge, in which case if
     ND_GATE_POLARITY is ND_POSITIVE, it will look for the falling edge
     and count the subsequent HIGH pulse, and if it is ND_NEGATIVE, it
     will look for the rising edge and count the subsequent LOW pulse. */
    

    iStatus = GPCTR_Set_Application(iDevice, ulGpctrNum,
     ND_TRIG_PULSE_WIDTH_MSR);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Set_Application",
     iIgnoreWarning);

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_SOURCE,
     ND_INTERNAL_100_KHZ);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/SOURCE", iIgnoreWarning);

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_GATE,
     ND_DEFAULT_PFI_LINE);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/GATE", iIgnoreWarning);

    /* Load initial count. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_INITIAL_COUNT, ulCount);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/INITCOUNT", iIgnoreWarning);

    printf(" Apply your digital pulse to the GATE of our counter now. The first falling edge will arm the counter.\n");

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_PROGRAM);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/PROGRAM",
     iIgnoreWarning);

    /* Loop until 'ulGpctrNum' is no longer armed. */

    do {


        iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_ARMED,
         &ulArmed);

        iRetVal = NIDAQYield(iYieldON);

    } while ((ulArmed == ND_YES) && (iStatus == 0));


    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Watch/ARMED",
     iIgnoreWarning);

    iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_COUNT, &ulCount);
    

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Watch/COUNT",
     iIgnoreWarning);

    iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_TC_REACHED,
     &ulTCReached);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Watch/TC_REACHED",
     iIgnoreWarning);

    if (ulTCReached == ND_YES) {


        printf(" Counter reached terminal count! - The count may be incorrect.\n");

    }
    else {

        printf(" The duration of the HIGH period in 10uSec ticks was %lu\n", ulCount);

    }


    /* CLEANUP - Don't check for errors on purpose. */

    /* Reset GPCTR. */

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);


}
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    u32 ulGpctrNum = ND_CLOCK_0;
    u32 ulGpctrSynchronizationLine = ND_PFI_6;
    u32 ulGpctrGate = ND_PFI_7;
    u32 ulInitialSeconds = 0;
    i16 iIgnoreWarning = 0;
    u32 ulSeconds = 0;
    u32 ulNanoSeconds = 0;
    u32 ulArmed = ND_YES;

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/RESET",
     iIgnoreWarning);

    iStatus = GPCTR_Set_Application(iDevice, ulGpctrNum,
     ND_SINGLE_TIME_MSR);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Set_Application",
     iIgnoreWarning);

    /* To use a different GPCTR gate, change the ulGpctrGate variable
     in the variable declarations. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_GATE,
     ulGpctrGate);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/GATE", iIgnoreWarning);

    /* To change the synchronization line, change the
     ulGpctrSynchronizationLine variable in the variable declarations. */
    

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_SYNCHRONIZATION_LINE, ulGpctrSynchronizationLine);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/SYNCHRONIZATION", iIgnoreWarning);

    /* To use a different GPCTR synchronization method, change the
     last parameter in the following function. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_SYNCHRONIZATION_METHOD, ND_IRIG_B);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/SYNCHRONIZATION_METHOD", iIgnoreWarning);

    /* To use the time previously stored in the real time clock,
     change the ND_INITIAL_SECONDS_ENABLE parameter to ND_NO */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_INITIAL_SECONDS_ENABLE, ND_YES);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/INITIAL_SECONDS_ENABLE", iIgnoreWarning);

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_INITIAL_SECONDS, ulInitialSeconds);

    /* NOTE - It is only necessary to program the initial seconds if
     you are not using IRIG synchronization. In the IRIG synchronization
     case the real time clock will recieve its time information from the
     data stream. */

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/INITIAL_SECONDS", iIgnoreWarning);

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_PROGRAM);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/PROGRAM",
     iIgnoreWarning);

    /* Delay for two seconds to ensure the clock is synchronized. */
    

    NIDAQDelay(2);

    printf(" Time 1 Hardware Event started...\n");

    printf(" Apply your gating pulse to PFI 7 now.\n");

    do {


        iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_ARMED,
         &ulArmed);

        iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Watch/ARMED",
         iIgnoreWarning);

    } while ((ulArmed == ND_YES) && (iStatus == 0));


    /* print the resulting time */

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_SNAPSHOT);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/SNAPSHOT",
     iIgnoreWarning);

    iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_SECONDS,
     &ulSeconds);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/SECONDS",
     iIgnoreWarning);

    iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_NANO_SECONDS,
     &ulNanoSeconds);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/NANO_SECONDS",
     iIgnoreWarning);

    printf(" Hardware trigger occurred at time %lu seconds and %lu nanoseconds.\n", ulSeconds, ulNanoSeconds);

    /* CLEANUP - Don't check for errors on purpose. */

    /* Reset GPCTR. */

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    printf(" Time 1 Event with Hardware Precision done!\n");


}
Ejemplo n.º 10
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iDBmodeON = 1;
    i16 iDBmodeOFF = 0;
    i16 iPGmodeOn = 1;
    u32 ulCount = 1000;
    u32 ulHalfCount = 500;
    i16 iLoopCount = 0;
    i16 iLineCount = 0;
    i16 iHalfBufsToRead = 20;
    i16 iGroupSize = 1;
    i16 iPort = 0;
    i16 iNumLines = 8;
    i16 iRegenAllowed = 0;
    i16 iNoRegen = 1;
    i16 iPartialTransferAllowed = 1;
    i16 iNoPartialTransfer = 0;
    i16 iIgnoreWarning = 0;
    i32 lTimeout = 180;
    i16 iYieldON = 1;
    i16 iAIChan = 0;
    i16 iGain = 1;
    f64 dSampRate = 1000;
    i16 iAIUnits = 0;
    i16 iSampTB = 0;
    u16 uSampInt = 0;
    static i16 piAIBuffer[1000] = {0};
    static i16 piAIHalfBuffer[500] = {0};
    i16 iHalfReady = 0;
    i16 iDAQStopped = 0;
    u32 ulPtsTfr = 0;
    static i16 iDIBuffer[500] = {0};
    static i16 iDIHalfBuffer[250] = {0};
    i16 iDIGroup = 1;
    i16 iDIReqSource = 9;
    i16 iInLineDirection = 4;
    i16 iInGroupDirection = 0;
    i16 iDIEdge = 0;

    /* This sets a timeout limit (#Sec * 18ticks/Sec) so that if there
     is something wrong, the program won't hang on the DAQ_DB_Transfer or
     DIG_DB_Transfer call. */

    iStatus = Timeout_Config(iDevice, lTimeout);

    iRetVal = NIDAQErrorHandler(iStatus, "Timeout_Config",
     iIgnoreWarning);

    /* Configure the digital lines for the correct direction., CONST
     */

    while (iLineCount < iNumLines) {


        iStatus = DIG_Line_Config(iDevice, iPort, iLineCount,
         iInLineDirection);

        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Line_Config",
         iIgnoreWarning);

        ++iLineCount;

    }


    /* Configure Digital Input */

    iStatus = DIG_Grp_Config(iDevice, iDIGroup, iGroupSize, iPort,
     iInGroupDirection);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Config",
     iIgnoreWarning);

    iStatus = DIG_Grp_Mode(iDevice, iDIGroup, 0, iDIEdge, 0, 0, 0);
    

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Mode",
     iIgnoreWarning);

    /* Correlate the input to the Analog Input Scan Clock. */

    iStatus = DIG_Block_PG_Config(iDevice, iDIGroup, iPGmodeOn,
     iDIReqSource, 0, 0, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Block_PG_Config",
     iIgnoreWarning);

    iStatus = DIG_DB_Config(iDevice, iDIGroup, iDBmodeON, iNoRegen,
     iNoPartialTransfer);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_DB_Config",
     iIgnoreWarning);

    /* Configure Analog Input */

    iStatus = DAQ_Rate(dSampRate, iAIUnits, &iSampTB, &uSampInt);

    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_Rate", iIgnoreWarning);
    

    iStatus = DAQ_DB_Config(iDevice, iDBmodeON);

    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_DB_Config",
     iIgnoreWarning);

    /* Start acquiring data. */

    iStatus = DIG_Block_In(iDevice, iDIGroup, iDIBuffer, ulCount);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_In",
     iIgnoreWarning);

    iStatus = DAQ_Start(iDevice, iAIChan, iGain, piAIBuffer, ulCount,
     iSampTB, uSampInt);

    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_Start", iIgnoreWarning);
    

    printf(" Continuous acquisitions have started.\n");

    /* Loop until 'iHalfBufsToRead' half buffers are acquired. HINT:
     You can be doing other foreground tasks during this time. */
    

    printf(" HINT: You can add your own graphing calls in the while loop.\n");

    while ((iLoopCount < iHalfBufsToRead) && (iStatus == 0)) {

        

        iStatus = DAQ_DB_HalfReady(iDevice, &iHalfReady,
         &iDAQStopped);

        if ((iHalfReady == 1) && (iStatus == 0)) {


            iStatus = DAQ_DB_Transfer(iDevice, piAIHalfBuffer,
             &ulPtsTfr, &iDAQStopped);

            iRetVal = NIDAQErrorHandler(iStatus, "DAQ_DB_Transfer",
             0);

            ++iLoopCount;;

            printf(" %d Half buffers acquired.\n", iLoopCount);

        }
        else {

            iRetVal = NIDAQErrorHandler(iStatus, "DAQ_DB_HalfReady",
             0);

        }


        iStatus = DIG_DB_HalfReady(iDevice, iDIGroup, &iHalfReady);
        

        if ((iHalfReady == 1) && (iStatus == 0)) {


            iStatus = DIG_DB_Transfer(iDevice, iDIGroup,
             iDIHalfBuffer, ulHalfCount);

            iRetVal = NIDAQErrorHandler(iStatus, "DIG_DB_Transfer",
             0);

        }
        else {

            iRetVal = NIDAQErrorHandler(iStatus, "DIG_DB_HalfReady",
             0);

        }


        iRetVal = NIDAQYield(iYieldON);

    }


    printf(" Continuous acquisitions are done.\n");

    /* Clear all operations and reset the board to its default state
     */

    iStatus = DAQ_Clear(iDevice);

    iStatus = DAQ_DB_Config(iDevice, iDBmodeOFF);

    iStatus = DIG_Grp_Config(iDevice, iDIGroup, 0, 0, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Grp_Config",
     iIgnoreWarning);

    /* Disable timeouts */

    iStatus = Timeout_Config(iDevice, -1);


}
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    u32 ulGpctrNum = ND_COUNTER_0;
    u32 ulCount = 0;
    u32 ulZIndexCount = 0;
    u32 ulInitCount = 0;
    i32 ulTCReached = ND_NO;
    u32 iLoopCount = 100;
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/RESET",
     iIgnoreWarning);

    /* Setup for a position measurement application. */

    /* NOTE: If you want to measure speed at the same time, you must
     timestamp each reading at the exact moment you take a quadrature
     encoded position measurement. By determining the position change from
     the previous measurement and the time difference since the previous
     measurement, you can calculate the speed. */
    

    iStatus = GPCTR_Set_Application(iDevice, ulGpctrNum,
     ND_POSITION_MSR);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Set_Application",
     iIgnoreWarning);

    /* Setup the encoder type for Quadrature Encoder (X1) measurement.
     You can change this to X2 or X4 if you wish. */

    GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_ENCODER_TYPE,
     ND_QUADRATURE_ENCODER_X1);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/QUADRATURE_ENCODER_X1", iIgnoreWarning);

    /* Activate a Z-index pulse to reset the counter to an initial
     value, specified by 'ulCount' later. */

    GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_Z_INDEX_ACTIVE,
     ND_YES);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/Z_INDEX_PULSE", iIgnoreWarning);

    /* Specify the value that gets loaded when a Z-index pulse
     arrives. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_Z_INDEX_VALUE, ulZIndexCount);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/Z-INDEX_COUNT", iIgnoreWarning);

    /* Load initial count. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_INITIAL_COUNT, ulInitCount);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/INITCOUNT", iIgnoreWarning);

    /* Signals from quadrature encoders often have noise and glitches
     that result in measurement errors. Setup 5 usec filtering on each
     input from the quadrature encoder. */

    /* Setup filter for Channel A. */

    iStatus = Line_Change_Attribute(iDevice, ND_PFI_39,
     ND_LINE_FILTER, ND_5_MICROSECONDS);

    iRetVal = NIDAQErrorHandler(iStatus,
     "Line_Change_Attribute/ND_PFI_39", iIgnoreWarning);

    /* Setup filter for Channel B. */

    iStatus = Line_Change_Attribute(iDevice, ND_PFI_37,
     ND_LINE_FILTER, ND_5_MICROSECONDS);

    iRetVal = NIDAQErrorHandler(iStatus,
     "Line_Change_Attribute/ND_PFI_37", iIgnoreWarning);

    /* Setup filter for Z-index Channel. */

    iStatus = Line_Change_Attribute(iDevice, ND_PFI_38,
     ND_LINE_FILTER, ND_5_MICROSECONDS);

    iRetVal = NIDAQErrorHandler(iStatus,
     "Line_Change_Attribute/ND_PFI_38", iIgnoreWarning);

    printf(" Connect the encoder Channel A signal to PFI 39.\n");

    printf(" Connect the encoder Channel B signal to PFI 37.\n");

    printf(" Connect the Z-index signal to PFI 38.\n");

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_PROGRAM);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/PROGRAM",
     iIgnoreWarning);

    /* Loop 100 times. */

    do {


        iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_COUNT,
         &ulCount);

        iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Watch/COUNT",
         iIgnoreWarning);

        if (iStatus == 0) {


            printf(" Current encoder position is at %ld\n", ulCount);

        }


        --iLoopCount;

        iRetVal = NIDAQYield(iYieldON);

    } while ((iLoopCount > 0) && (iStatus == 0));


    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Watch",
     iIgnoreWarning);

    /* CLEANUP - Don't check for errors on purpose. */

    /* Clear filter settings. */

    iStatus = Line_Change_Attribute(iDevice, ND_PFI_39,
     ND_LINE_FILTER, ND_NONE);

    iStatus = Line_Change_Attribute(iDevice, ND_PFI_37,
     ND_LINE_FILTER, ND_NONE);

    iStatus = Line_Change_Attribute(iDevice, ND_PFI_38,
     ND_LINE_FILTER, ND_NONE);

    /* Reset GPCTR. */

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    printf(" Done with quadrature encoded position measurement!\n");


}
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iDBmodeON = 1;
    i16 iDBmodeOFF = 0;
    i16 iPGmodeOn = 1;
    u32 ulCount = 1000;
    i16 iLineCount = 0;
    i16 iGroupSize = 1;
    i16 iPort = 0;
    i16 iNumLines = 8;
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;
    static i16 iDOBuffer[500] = {0};
    i16 iDOGroup = 2;
    i16 iDOReqSource = 1;
    i16 iOutLineDirection = 5;
    i16 iOutGroupDirection = 1;
    i16 iDOEdge = 0;
    u32 ulRemaining = 1;

    /* Configure the digital lines for the correct direction. */

    while (iLineCount < iNumLines) {


        iStatus = DIG_Line_Config(iDevice, iPort, iLineCount,
         iOutLineDirection);

        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Line_Config",
         iIgnoreWarning);

        ++iLineCount;

    }


    /* Configure Digital Output */

    /* Create a sawtooth waveform. */

    iStatus = NIDAQMakeBuffer(iDOBuffer, ulCount, WFM_DATA_U8);

    iRetVal = NIDAQErrorHandler(iStatus, "NIDAQMakeBuffer",
     iIgnoreWarning);

    iStatus = DIG_Grp_Config(iDevice, iDOGroup, iGroupSize, iPort,
     iOutGroupDirection);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Config",
     iIgnoreWarning);

    iStatus = DIG_Grp_Mode(iDevice, iDOGroup, 0, iDOEdge, 0, 0, 0);
    

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Mode",
     iIgnoreWarning);

    /* Correlate the output to the external clock.  Note, you will not
     be able to use GPCTR0 for pulse train generation when using an
     external clock. */

    iStatus = DIG_Block_PG_Config(iDevice, iDOGroup, iPGmodeOn,
     iDOReqSource, 0, 0, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Block_PG_Config",
     iIgnoreWarning);

    /* Start generating data. */

    iStatus = DIG_Block_Out(iDevice, iDOGroup, iDOBuffer, ulCount);
    

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_Out",
     iIgnoreWarning);

    while ((ulRemaining > 0) && (iStatus == 0)) {


        /* Wait until the data is finished outputting. */

        iStatus = DIG_Block_Check(iDevice, iDOGroup, &ulRemaining);
        

        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_Check",
         iIgnoreWarning);

        iRetVal = NIDAQYield(iYieldON);

    }


    /* Clear all operations and reset the board to its default state
     */

    iStatus = DIG_Grp_Config(iDevice, iDOGroup, 0, 0, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Grp_Config",
     iIgnoreWarning);


}
Ejemplo n.º 13
0
void main(void)
{
    /*
     * Local Variable Declarations:
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    u32 ulCount = 100;
    u32 ulLoopCount = 0;
    i16 iLineCount = 0;
    i16 iGroupSize = 1;
    i16 iPort = 0;
    i16 iNumLines = 8;
    i16 iIgnoreWarning = 0;
    i16 iReady = 0;
    i16 iDOGroup = 2;
    i16 iOutLineDirection = 5;
    i16 iOutGroupDirection = 1;
    i16 iDOEdge = 0;
    i16 iDataPoint = 0;

    /* Configure the digital lines for the correct direction. */

    while (iLineCount < iNumLines) {


        iStatus = DIG_Line_Config(iDevice, iPort, iLineCount,
                                  iOutLineDirection);

        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Line_Config",
                                    iIgnoreWarning);

        ++iLineCount;

    }


    /* Configure Digital Output */

    iStatus = DIG_Grp_Config(iDevice, iDOGroup, iGroupSize, iPort,
                             iOutGroupDirection);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Config",
                                iIgnoreWarning);

    iStatus = DIG_Grp_Mode(iDevice, iDOGroup, 0, iDOEdge, 0, 0, 0);


    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Mode",
                                iIgnoreWarning);

    /* Call the DIG_Grp_Status function to enable digital operations.
     */

    iStatus = DIG_Grp_Status(iDevice, iDOGroup, &iReady);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Grp_Status", 0);

    /* Output ulCount number of points. */

    while ((ulLoopCount < ulCount) && (iStatus == 0)) {


        iStatus = DIG_Out_Grp(iDevice, iDOGroup, iDataPoint);

        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Out_Grp", 0);


        ++ulLoopCount;;

        ++iDataPoint;

        iStatus = NIDAQDelay(0.1);

    }


    /* Clear all operations and reset the board to its default state
     */

    iStatus = DIG_Grp_Config(iDevice, iDOGroup, 0, 0, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Grp_Config",
                                iIgnoreWarning);


}
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    u32 ulGpctrNum = ND_COUNTER_0;
    u32 ulZIndexCount = 0;
    static u32 pulBuffer[100] = {0};
    static u32 pulReadBuf[50] = {0};
    u32 ulCount = 100;
    u32 ulReadCount = 50;
    i16 iLoopCount = 10;
    u32 ulInitCount = 0;
    u32 ulNumPtsToRead = 50;
    u32 ulNumPtsRead = 0;
    u32 ulReadOffset = 0;
    u32 ulTimeOut = 5;
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/RESET",
     iIgnoreWarning);

    /* Setup for a buffered position measurement application. */

    iStatus = GPCTR_Set_Application(iDevice, ulGpctrNum,
     ND_BUFFERED_POSITION_MSR);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Set_Application",
     iIgnoreWarning);

    /* Setup the encoder type for Quadrature Encoder (X1) measurement.
     You can change this to X2 or X4 if you wish. */

    GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_ENCODER_TYPE,
     ND_QUADRATURE_ENCODER_X1);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/QUADRATURE_ENCODER_X1", iIgnoreWarning);

    /* Activate a Z-index pulse to reset the counter to an initial
     value, specified by 'ulZIndexCount' later. */

    GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_Z_INDEX_ACTIVE,
     ND_YES);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/Z_INDEX_PULSE", iIgnoreWarning);

    /* Specify the value that gets loaded when a Z-index pulse
     arrives. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_Z_INDEX_VALUE, ulZIndexCount);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/Z-INDEX_COUNT", iIgnoreWarning);

    /* Load initial count. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_INITIAL_COUNT, ulInitCount);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/INITCOUNT", iIgnoreWarning);

    /* Signals from quadrature encoders often have noise and glitches
     that result in measurement errors. Setup 5 usec filtering on each
     input from the quadrature encoder. */

    /* Setup filter for Channel A. */

    iStatus = Line_Change_Attribute(iDevice, ND_PFI_39,
     ND_LINE_FILTER, ND_5_MICROSECONDS);

    iRetVal = NIDAQErrorHandler(iStatus,
     "Line_Change_Attribute/ND_PFI_39", iIgnoreWarning);

    /* Setup filter for Channel B. */

    iStatus = Line_Change_Attribute(iDevice, ND_PFI_37,
     ND_LINE_FILTER, ND_5_MICROSECONDS);

    iRetVal = NIDAQErrorHandler(iStatus,
     "Line_Change_Attribute/ND_PFI_37", iIgnoreWarning);

    /* Setup filter for Z-index Channel. */

    iStatus = Line_Change_Attribute(iDevice, ND_PFI_38,
     ND_LINE_FILTER, ND_5_MICROSECONDS);

    iRetVal = NIDAQErrorHandler(iStatus,
     "Line_Change_Attribute/ND_PFI_38", iIgnoreWarning);

    /* Each time a pulse arrives in the gate, a new value will be
     latched into the counter and sent to the data buffer. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_GATE,
     ND_PFI_34);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/GATE", iIgnoreWarning);

    /* Enable double-buffer mode. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_BUFFER_MODE, ND_DOUBLE);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/BUFFERMODE", iIgnoreWarning);

    iStatus = GPCTR_Config_Buffer(iDevice, ulGpctrNum, 0, ulCount,
     pulBuffer);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Config_Buffer",
     iIgnoreWarning);

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_PROGRAM);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/PROGRAM",
     iIgnoreWarning);

    printf(" Connect the encoder Channel A signal to PFI 39.\n");

    printf(" Connect the encoder Channel B signal to PFI 37.\n");

    printf(" Connect the Z-index signal to PFI 38.\n");

    printf(" Apply your gating pulse train to PFI 34.\n");

    /* Loop 10 times. */

    do {


        iStatus = GPCTR_Read_Buffer(iDevice, ulGpctrNum, ND_READ_MARK,
         ulReadOffset, ulNumPtsToRead, ulTimeOut, &ulNumPtsRead, pulReadBuf);
        

        --iLoopCount;

        printf(" %lu points read into buffer 'pulReadBuf' (loop count %d ).\n", ulNumPtsRead, iLoopCount);

        /* Print out the firt point in the buffer. */

        printf(" Current encoder position is at %ld\n", pulReadBuf[0]);

        iRetVal = NIDAQYield(iYieldON);

    } while ((iLoopCount > 0) && (iStatus >= 0));


    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Read_Buffer",
     iIgnoreWarning);

    /* CLEANUP - Don't check for errors on purpose. */

    /* Clear filter settings. */

    iStatus = Line_Change_Attribute(iDevice, ND_PFI_39,
     ND_LINE_FILTER, ND_NONE);

    iStatus = Line_Change_Attribute(iDevice, ND_PFI_37,
     ND_LINE_FILTER, ND_NONE);

    iStatus = Line_Change_Attribute(iDevice, ND_PFI_38,
     ND_LINE_FILTER, ND_NONE);

    /* Reset GPCTR. */

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    printf(" Done with circular buffered position measurement!\n");


}
Ejemplo n.º 15
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iOnDevChan = 0;
    i16 iOnDevGain = 1;
    i16 iReading = 0;
    i16 iChassisID = 1;
    i16 iModuleSlot = 1;
    i16 iModuleChan = 0;
    f64 dSCXIgain = 1.0;
    f64 dTermBlockGain = 1.0;
    f64 dSCXIvoltage = 0.0;
    i16 iIgnoreWarning = 0;

    iStatus = SCXI_Load_Config(iChassisID);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_Load_Config",
     iIgnoreWarning);

    /* Specify SCXI module and channel to sample. */

    iStatus = SCXI_Single_Chan_Setup(iChassisID, iModuleSlot,
     iModuleChan, iDevice);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_Single_Chan_Setup",
     iIgnoreWarning);

    /* You can call SCXI_Set_Gain before AI_Read to change the gain on
     the SCXI module or SCXI channel, depending on what the module allows.
      Otherwise, SCXIgain is assumed to be 1.0. */

    /* Some modules require that you call SCXI_Get_Status after
     changing gain but before taking a reading to make sure the gain has
     switched.  The delay call below should then be replaced with
     SCXI_Get_Status. */

    iRetVal = NIDAQDelay(1.0);

    /* If you are using an SCXI-1140 module, call
     SCXI_Track_Hold_Control to put the module in 'Hold' mode at this
     point. */

    iStatus = AI_Read(iDevice, iOnDevChan, iOnDevGain, &iReading);

    iRetVal = NIDAQErrorHandler(iStatus, "AI_Read", iIgnoreWarning);
    

    /* If you are using an SCXI-1140 module, call
     SCXI_Track_Hold_Control to put the module in 'Track' mode at this
     point. */

    /* If you call SCXI_Set_Gain before AI_Read, make sure to change
     the 'dSCXIgain' in SCXI_Scale. */

    iStatus = SCXI_Scale(iChassisID, iModuleSlot, iModuleChan,
     dSCXIgain, dTermBlockGain, iDevice, iOnDevChan, iOnDevGain, 1,
     &iReading, &dSCXIvoltage);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_Scale",
     iIgnoreWarning);

    printf(" The SCXI voltage is %lf volts.\n", dSCXIvoltage);


}
Ejemplo n.º 16
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iChassisID = 1;
    i16 iNumModules = 1;
    static i16 piModuleList[1] = {1};
    i16 iModuleSlot = 1;
    i16 iNumDevChans = 1;
    static i16 piNumChans[1] = {4};
    i16 iNumSCXIChans = 4;
    static i16 piStartChans[1] = {0};
    i16 iDevice = 1;
    i16 lTimeout = 180;
    i16 iMuxCtrON = 1;
    i16 iMuxCtrOFF = 0;
    i16 iScanDiv = 1;
    u16 uCtrValue = 4;
    i16 iOnDevChan = 0;
    i16 iOnDevGain = 1;
    static i16 piOnDevChan[1] = {0};
    static i16 piOnDevGain[1] = {1};
    static i16 piBuffer[100] = {0};
    i16 ulCount = 100;
    f64 dSampRate = 10000.0;
    f64 dScanRate = 1000.0;
    f64 dSCXIgain = 1.0;
    f64 dTermBlockGain = 1.0;
    static f64 pdVoltBuffer[100] = {0.0};
    i16 iIgnoreWarning = 0;

    iStatus = SCXI_Load_Config(iChassisID);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_Load_Config",
     iIgnoreWarning);

    /* Setup hardware scanning on SCXI module. */

    /* NOTE: If you are using the SCXI-1140 module, you can call
     SCXI_Track_Hold_Setup at this point to setup the track-and-hold
     circuitry. */

    iStatus = SCXI_SCAN_Setup(iChassisID, iNumModules, piModuleList,
     piNumChans, piStartChans, iDevice, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_SCAN_Setup",
     iIgnoreWarning);

    /* This sets a timeout limit (#Sec * 18ticks/Sec) so that if there
     is something wrong, the program won't hang on the SCAN_Op call. */
    

    iStatus = Timeout_Config(iDevice, lTimeout);

    iRetVal = NIDAQErrorHandler(iStatus, "Timeout_Config",
     iIgnoreWarning);

    iStatus = SCXI_MuxCtr_Setup(iDevice, iMuxCtrON, iScanDiv,
     uCtrValue);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_MuxCtr_Setup",
     iIgnoreWarning);

    /* Scan_Op is called to perform 'interval scanning'. You must use
     a DAQ device that has a 'scan clock'. Some devices may require you to
     use Lab_ISCAN_Op instead. */

    iStatus = SCAN_Op(iDevice, iNumDevChans, piOnDevChan, piOnDevGain,
     piBuffer, ulCount, dSampRate, dScanRate);

    iRetVal = NIDAQErrorHandler(iStatus, "SCAN_Op", iIgnoreWarning);
    

    /* NOTE: If you are using the SCXI-1140 module, you can call
     SCXI_Track_Hold_Setup at this point to disable the track-and-hold
     circuitry. */

    iStatus = SCAN_Demux(piBuffer, ulCount, iNumSCXIChans, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "SCAN_Demux",
     iIgnoreWarning);

    /* Since all channels have the same gain, the SCXI_Scale is called
     for all channels.  If you have set different gains for different
     channels, then scale them one channel at a time. */

    iStatus = SCXI_Scale(iChassisID, iModuleSlot, 0, dSCXIgain,
     dTermBlockGain, iDevice, iOnDevChan, iOnDevGain, ulCount, piBuffer,
     pdVoltBuffer);

    iRetVal = NIDAQErrorHandler(iStatus, "SCXI_Scale",
     iIgnoreWarning);

    iStatus = SCXI_MuxCtr_Setup(iDevice, iMuxCtrOFF, 0, 0);

    iRetVal = NIDAQPlotWaveform(pdVoltBuffer, ulCount, WFM_DATA_F64);
    

    printf(" The data is available in 'pdVoltBuffer'.\n");

    /* Disable timeouts. */

    iStatus = Timeout_Config(iDevice, -1);


}
Ejemplo n.º 17
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    u32 ulGpctrNum = ND_COUNTER_0;
    u32 ulCount = 0;
    i32 ulTCReached = ND_NO;
    u32 iLoopCount = 10;
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/RESET",
     iIgnoreWarning);

    iStatus = GPCTR_Set_Application(iDevice, ulGpctrNum,
     ND_SIMPLE_EVENT_CNT);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Set_Application",
     iIgnoreWarning);

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_SOURCE,
     ND_DEFAULT_PFI_LINE);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/SOURCE", iIgnoreWarning);

    /* Load initial count. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_INITIAL_COUNT, ulCount);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/INITCOUNT", iIgnoreWarning);

    printf(" Apply your digital pulse train to the SOURCE of your counter.\n");

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_PROGRAM);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/PROGRAM",
     iIgnoreWarning);

    /* Loop 10 times. */

    do {


        iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_COUNT,
         &ulCount);

        iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Watch/COUNT",
         iIgnoreWarning);

        printf(" The current count is %lu\n", ulCount);

        --iLoopCount;

        iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_TC_REACHED,
         &ulTCReached);

        if (ulTCReached == ND_YES) {


            printf(" Counter reached terminal count! - The count may be incorrect.\n");

        }


        iRetVal = NIDAQDelay(1.0);

        iRetVal = NIDAQYield(iYieldON);

    } while ((iLoopCount > 0) && (iStatus == 0));


    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Watch",
     iIgnoreWarning);

    /* CLEANUP - Don't check for errors on purpose. */

    /* Reset GPCTR. */

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    printf(" Done with event counting!\n");


}
Ejemplo n.º 18
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iGroup = 1;
    i16 iNumChans = 1;
    i16 iChan = 0;
    static i16 piChanVect[1] = {0};
    i16 iDBmodeON = 1;
    i16 iDBmodeOFF = 0;
    i16 iOldDataStop = 1;
    i16 iPartialTransferStop = 0;
    static f64 pdBuffer[32768] = {0};
    static i16 piBuffer[32768] = {0};
    u32 ulCount = 32768;
    u32 ulHalfCount = 16384;
    u32 ulIterations = 0;
    i16 iFIFOMode = 0;
    f64 dUpdateRate = 10000.0;
    i16 iUnits = 0;
    i16 iUpdateTB = 0;
    u32 ulUpdateInt = 0;
    i16 iWhichClock = 0;
    i16 iDelayMode = 0;
    i16 iOpSTART = 1;
    i16 iOpCLEAR = 0;
    i16 iHalfReady = 0;
    i16 iLoopCount = 0;
    i16 iHalfBufsToWrite = 10;
    i16 iIgnoreWarning = 0;
    i32 lTimeout = 180;
    i16 iWFMstopped = 0;
    u32 ulItersDone = 0;
    u32 ulPtsDone = 0;
    i16 iYieldON = 1;

    /* This sets a timeout limit (#Sec * 18ticks/Sec) so that if there
     is something wrong, the program won't hang on the WFM_DB_Transfer
     call. */

    iStatus = Timeout_Config(iDevice, lTimeout);

    iRetVal = NIDAQErrorHandler(iStatus, "Timeout_Config",
     iIgnoreWarning);

    iStatus = NIDAQMakeBuffer(pdBuffer, ulCount, WFM_DATA_F64);

    if (iStatus == 0) {


        /* If buffer was made correctly, then output it. */

        iStatus = WFM_DB_Config(iDevice, iNumChans, piChanVect,
         iDBmodeON, iOldDataStop, iPartialTransferStop);

        iRetVal = NIDAQErrorHandler(iStatus, "WFM_DB_Config",
         iIgnoreWarning);

        iStatus = WFM_Group_Setup(iDevice, iNumChans, piChanVect,
         iGroup);

        iRetVal = NIDAQErrorHandler(iStatus, "WFM_Group_Setup",
         iIgnoreWarning);

        iStatus = WFM_Scale(iDevice, iChan, ulCount, 1.0, pdBuffer,
         piBuffer);

        iRetVal = NIDAQErrorHandler(iStatus, "WFM_Scale",
         iIgnoreWarning);

        /* NOTE FOR DSA devices... DSA devices can format samples in a
         left-justified format in 32-bit data words. This means that the most
         significant bits of the data word contain the bits generated by the
         converter. When allocating data buffers, be sure to account for the
         32-bit data width. Even though a number of DAQ/SCAN/WFM functions are
         declared to accept pointers to 16-bit data buffers, you should pass
         pointers to 32-bit data buffers. */
        

        /* Also for DSA devices, remember to call AO_Change_Parameter
         to enable the analog output. */

        iStatus = WFM_Load(iDevice, iNumChans, piChanVect, piBuffer,
         ulCount, ulIterations, iFIFOMode);

        iRetVal = NIDAQErrorHandler(iStatus, "WFM_Load",
         iIgnoreWarning);

        /* NOTE: If you are using a DSA device, call WFM_Set_Clock
         instead.  Refer to NI-DAQ Function Reference Manual for details. */
        

        iStatus = WFM_Rate(dUpdateRate, iUnits, &iUpdateTB,
         &ulUpdateInt);

        iRetVal = NIDAQErrorHandler(iStatus, "WFM_Rate",
         iIgnoreWarning);

        iStatus = WFM_ClockRate(iDevice, iGroup, iWhichClock,
         iUpdateTB, ulUpdateInt, iDelayMode);

        iRetVal = NIDAQErrorHandler(iStatus, "WFM_ClockRate",
         iIgnoreWarning);

        printf(" The waveform should be output at a rate of %lf updates/sec.\n", dUpdateRate);

        iStatus = WFM_Group_Control(iDevice, iGroup, iOpSTART);
        

        iRetVal = NIDAQErrorHandler(iStatus,
         "WFM_Group_Control/START", iIgnoreWarning);

        while ((iLoopCount < iHalfBufsToWrite) && (iStatus == 0)) {

            

            iStatus = WFM_DB_HalfReady(iDevice, iNumChans, piChanVect,
             &iHalfReady);

            if ((iHalfReady == 1) && (iStatus == 0)) {

                

                /* Update next half buffer.  WFM_DB_Transfer will
                 return upon updating the circular buffer, but it does NOT indicate
                 that the actual data has been generated. */
                

                /* HINT: You actually can dynamically change the
                 output buffer here!  This example is reusing the same buffer to
                 ensure simplicity of the source code. */
                

                /* NOTE FOR DSA devices... DSA devices can format
                 samples in a left-justified format in 32-bit data words. This means
                 that the most significant bits of the data word contain the bits
                 generated by the converter. When allocating data buffers, be sure to
                 account for the 32-bit data width. Even though a number of
                 DAQ/SCAN/WFM functions are declared to accept pointers to 16-bit data
                 buffers, you should pass pointers to 32-bit data buffers. */
                
                
                

                /* Also for DSA devices, remember to call
                 AO_Change_Parameter to enable the analog output. */
                

                iStatus = WFM_DB_Transfer(iDevice, iNumChans,
                 piChanVect, piBuffer, ulHalfCount);

                iRetVal = NIDAQErrorHandler(iStatus,
                 "WFM_DB_Transfer", iIgnoreWarning);

                ++iLoopCount;

                printf(" %d Half buffers generated.\n", iLoopCount);

            }
            else {

                iRetVal = NIDAQErrorHandler(iStatus,
                 "WFM_DB_HalfReady", iIgnoreWarning);

            }


            iRetVal = NIDAQYield(iYieldON);

        }


        /* If 'iOldDataStop' is 1, then NI-DAQ will stop the waveform
         generation when the last updated half buffer is actually completed.
         This is to prevent underflow conditions.  Check if 'iWFMstopped' is
         set in WFM_Check to make sure the last half buffer is 'really'
         completed. */

        /* If 'iOldDataStop' is 0, NI-DAQ will keep on outputting the
         last half buffer, so the waveform generation will never stop.  In
         that case, you can forcefully stop it with WFM_Group_Control/CLEAR.
         */

        if (iOldDataStop == 1) {


            do {


                /* When the last half buffer is actually done,
                 WFM_Check will return an underflow error, so don't check for errors
                 on purpose. */

                iStatus = WFM_Check(iDevice, iChan, &iWFMstopped,
                 &ulItersDone, &ulPtsDone);

                iRetVal = NIDAQYield(iYieldON);

            } while (iWFMstopped != 1);


        }


        /* CLEANUP - Don't check for errors on purpose. */

        /* Set WFM group back to initial state. */

        iStatus = WFM_Group_Control(iDevice, iGroup, iOpCLEAR);
        

        /* Set DB mode back to initial state. */

        iStatus = WFM_DB_Config(iDevice, iNumChans, piChanVect,
         iDBmodeOFF, 0, 0);

        /* Set output at 0 volts. */

        iStatus = AO_VWrite(iDevice, iChan, 0.0);

        printf(" The waveform generation is done!\n");

    }
    else {

        printf(" The buffer was not made correctly. Check the parameters for NIDAQMakeBuffer.\n");

    }


    /* Disable timeouts. */

    iStatus = Timeout_Config(iDevice, -1);


}
Ejemplo n.º 19
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iCtr = 1;
    i16 iEdgeMode = 0;
    i16 iGateMode = 1;
    i16 iOutType = 0;
    i16 iOutPolarity = 0;
    i16 iTimeBase = 1;
    i16 iOverFlow = 0;
    u16 uCount = 0;
    i16 iIgnoreWarnings = 0;

    /* Setup counter for counting rising edges with level-HIGH gating.
     */

    iStatus = CTR_Config(iDevice, iCtr, iEdgeMode, iGateMode,
     iOutType, iOutPolarity);

    iRetVal = NIDAQErrorHandler(iStatus, "CTR_Config",
     iIgnoreWarnings);

    /* Setup counter to do period/pulse-width measurement using
     internal 1MHz timebase. */

    iStatus = CTR_Period(iDevice, iCtr, iTimeBase);

    iRetVal = NIDAQErrorHandler(iStatus, "CTR_Period",
     iIgnoreWarnings);

    printf(" Wait 1 sec before reading the count value.\n");

    iRetVal = NIDAQDelay(1.0);

    iStatus = CTR_EvRead(iDevice, iCtr, &iOverFlow, &uCount);

    if ((uCount >= 3) && (iStatus == 0)) {


        printf(" The gate pulse was %u uSec long.\n", uCount);

    }
    else if (iOverFlow == 1) {


        printf(" An overflow occured. You may want to slow down the timebase or your gate pulse.\n");

    }
    else {

        /* 'uCount' must be greater than 3 for valid count. the count
         corresponds to the number of microsecond ticks read by the counter
         while the gate was high. */

        printf(" WARNING- The counter was read prematurely.\n");

    }


    iRetVal = NIDAQErrorHandler(iStatus, "CTR_EvRead",
     iIgnoreWarnings);

    /* CLEANUP - Don't check for errors on purpose. */

    /* Reset counter to initial state. */

    iStatus = CTR_Reset(iDevice, iCtr, 0);


}
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iDBmodeON = 1;
    i16 iDBmodeOFF = 0;
    i16 iPGmodeOn = 1;
    u32 ulCount = 1024;
    u32 ulHalfCount = 512;
    i16 iLoopCount = 0;
    i16 iLineCount = 0;
    i16 iHalfBufsToRead = 20;
    i16 iGroupSize = 1;
    i16 iPort = 0;
    i16 iNumLines = 8;
    i16 iRegenAllowed = 0;
    i16 iNoRegen = 1;
    i16 iPartialTransferAllowed = 1;
    i16 iNoPartialTransfer = 0;
    i16 iIgnoreWarning = 0;
    i32 lTimeout = 180;
    i16 iYieldON = 1;
    i16 iHalfReady = 0;
    static i16 iDIBuffer[512] = {0};
    static i16 iDIHalfBuffer[256] = {0};
    i16 iDIGroup = 1;
    i16 iDIReqSource = 1;
    i16 iInLineDirection = 4;
    i16 iInGroupDirection = 0;
    i16 iDIEdge = 0;
    static i16 iDOBuffer[512] = {0};
    i16 iDOGroup = 2;
    i16 iDOReqSource = 1;
    i16 iOutLineDirection = 5;
    i16 iOutGroupDirection = 1;
    i16 iDOEdge = 0;
    i16 iNumOutputLines = 4;

    /* This sets a timeout limit (#Sec * 18ticks/Sec) so that if there
     is something wrong, the program won't hang on the DIG_DB_Transfer
     call. */

    iStatus = Timeout_Config(iDevice, lTimeout);

    iRetVal = NIDAQErrorHandler(iStatus, "Timeout_Config",
     iIgnoreWarning);

    /* Configure the digital lines for the correct direction.  Lines
     0-3 will be output lines and 4-7 input lines. */

    while (iLineCount < iNumLines) {


        if (iLineCount < iNumOutputLines) {


            iStatus = DIG_Line_Config(iDevice, iPort, iLineCount,
             iOutLineDirection);

        }
        else {

            iStatus = DIG_Line_Config(iDevice, iPort, iLineCount,
             iInLineDirection);

        }


        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Line_Config",
         iIgnoreWarning);

        ++iLineCount;

    }


    /* Configure Digital Output */

    /* Create a sawtooth waveform. */

    iStatus = NIDAQMakeBuffer(iDOBuffer, ulCount, WFM_DATA_U8);

    iRetVal = NIDAQErrorHandler(iStatus, "NIDAQMakeBuffer",
     iIgnoreWarning);

    iStatus = DIG_Grp_Config(iDevice, iDOGroup, iGroupSize, iPort,
     iOutGroupDirection);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Config",
     iIgnoreWarning);

    iStatus = DIG_Grp_Mode(iDevice, iDOGroup, 0, iDOEdge, 0, 0, 0);
    

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Mode",
     iIgnoreWarning);

    /* Correlate the output to the external clock.  By default, the
     external clock is routed across RTSI 0.  If you wish to use another
     line besides RTSI 0, make a second call to the DIG_Block_PG_Config
     function specifying the the desired RTSI line in the reqSource
     parameter.  Also, when using one external clock in this manner, you
     will lose pulse train generation capabilities of GPCTR0. */
    

    iStatus = DIG_Block_PG_Config(iDevice, iDOGroup, iPGmodeOn,
     iDOReqSource, 0, 0, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Block_PG_Config",
     iIgnoreWarning);

    /* The buffer will be written once and then regenerated. */

    iStatus = DIG_DB_Config(iDevice, iDOGroup, iDBmodeON,
     iRegenAllowed, iNoPartialTransfer);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_DB_Config",
     iIgnoreWarning);

    /* Configure Digital Input */

    iStatus = DIG_Grp_Config(iDevice, iDIGroup, iGroupSize, iPort,
     iInGroupDirection);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Config",
     iIgnoreWarning);

    iStatus = DIG_Grp_Mode(iDevice, iDIGroup, 0, iDIEdge, 0, 0, 0);
    

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Mode",
     iIgnoreWarning);

    /* Correlate the input to the external clock.  Note, in this
     example the same clock is used for both input and output.  If you
     want to use 2 seperate external clocks for input and output, you will
     need to route the 2 signals onto seperate RTSI lines through 2 of the
     3 GPCR0 pins (GPCTR0 Out, GPCTR0 Source, GPCTR0 Gate) using the
     Select_Signal function.  You will also need to pass the right
     parameter value for reqSource into the DIG_Block_PG_Config function
     so that the RTSI line used matches the one used in the Select_Signal
     function call.  When using 2 external clocks in this manner, you will
     lose all functionality of GPCTR0. */

    iStatus = DIG_Block_PG_Config(iDevice, iDIGroup, iPGmodeOn,
     iDIReqSource, 0, 0, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Block_PG_Config",
     iIgnoreWarning);

    iStatus = DIG_DB_Config(iDevice, iDIGroup, iDBmodeON, iNoRegen,
     iNoPartialTransfer);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_DB_Config",
     iIgnoreWarning);

    /* Start acquiring and generating data. */

    iStatus = DIG_Block_Out(iDevice, iDOGroup, iDOBuffer, ulCount);
    

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_Out",
     iIgnoreWarning);

    iStatus = DIG_Block_In(iDevice, iDIGroup, iDIBuffer, ulCount);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_In",
     iIgnoreWarning);

    printf(" Apply your external clock signal now.\n");

    /* Loop until 'iHalfBufsToRead' half buffers are acquired. HINT:
     You can be doing other foreground tasks during this time. */
    

    printf(" HINT: You can add your own graphing calls in the while loop.\n");

    while ((iLoopCount < iHalfBufsToRead) && (iStatus == 0)) {

        

        iStatus = DIG_DB_HalfReady(iDevice, iDIGroup, &iHalfReady);
        

        if ((iHalfReady == 1) && (iStatus == 0)) {


            iStatus = DIG_DB_Transfer(iDevice, iDIGroup,
             iDIHalfBuffer, ulHalfCount);

            iRetVal = NIDAQErrorHandler(iStatus, "DIG_DB_Transfer",
             0);

            ++iLoopCount;;

            printf(" %d Half buffers acquired.\n", iLoopCount);

        }
        else {

            iRetVal = NIDAQErrorHandler(iStatus, "DIG_DB_HalfReady",
             0);

        }


        iRetVal = NIDAQYield(iYieldON);

    }


    printf(" Continuous acquisitions are done.\n");

    /* Clear all operations and reset the board to its default state
     */

    iStatus = DIG_Grp_Config(iDevice, iDOGroup, 0, 0, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Grp_Config",
     iIgnoreWarning);

    iStatus = DIG_Grp_Config(iDevice, iDIGroup, 0, 0, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Grp_Config",
     iIgnoreWarning);

    /* Disable timeouts */

    iStatus = Timeout_Config(iDevice, -1);


}
Ejemplo n.º 21
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    u32 ulGpctrNum = ND_COUNTER_0;
    static u32 pulBuffer[100] = {0};
    u32 ulCount = 100;
    u32 ulInitCount = 0;
    u32 ulArmed = ND_YES;
    i16 iGateFasterThanSource = 0;
    u32 ulNumPtsToRead = 100;
    u32 ulNumPtsRead = 0;
    u32 ulReadOffset = 0;
    u32 ulTimeOut = 5;
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/RESET",
     iIgnoreWarning);

    /* Set up for a buffered event counting application. */

    iStatus = GPCTR_Set_Application(iDevice, ulGpctrNum,
     ND_BUFFERED_EVENT_CNT);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Set_Application",
     iIgnoreWarning);

    /* If you want to use a different GPCTR source, change the last
     parameter in the following function. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_SOURCE,
     ND_INTERNAL_100_KHZ);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/SOURCE", iIgnoreWarning);

    /* Each time a pulse arrives in the gate, a new value will be
     latched into the counter and sent to the data buffer. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_GATE,
     ND_DEFAULT_PFI_LINE);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/GATE", iIgnoreWarning);

    /* Load initial count. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_INITIAL_COUNT, ulInitCount);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/INITCOUNT", iIgnoreWarning);

    /* Enable single-buffer mode. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_BUFFER_MODE, ND_SINGLE);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/BUFFERMODE", iIgnoreWarning);

    /* Turn on synchronous counting mode if gate is faster than
     source. */

    if (iGateFasterThanSource == 1) {


        iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
         ND_COUNTING_SYNCHRONOUS, ND_YES);

        iRetVal = NIDAQErrorHandler(iStatus,
         "GPCTR_Change_Parameter/SYNCHRONOUS COUNTING", iIgnoreWarning);
        

    }


    iStatus = GPCTR_Config_Buffer(iDevice, ulGpctrNum, 0, ulCount,
     pulBuffer);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Config_Buffer",
     iIgnoreWarning);

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_PROGRAM);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/PROGRAM",
     iIgnoreWarning);

    printf(" Apply your gating pulse train to the GATE of your counter now.\n");

    /* Loop until counter is no longer armed. */

    /* WARNING... Do NOT watch for ND_COUNT during a buffered
     operation. */

    do {


        iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_ARMED,
         &ulArmed);

        iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Watch/ARMED",
         iIgnoreWarning);

        iRetVal = NIDAQYield(iYieldON);

    } while ((ulArmed == ND_YES) && (iStatus == 0));


    /* After the counter is unarmed, read the buffer from the
     beginning. */

    iStatus = GPCTR_Read_Buffer(iDevice, ulGpctrNum, ND_BUFFER_START,
     ulReadOffset, ulNumPtsToRead, ulTimeOut, &ulNumPtsRead, pulBuffer);
    

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Read_Buffer",
     iIgnoreWarning);

    printf(" %lu points read into buffer 'pulBuffer'.\n", ulNumPtsRead);

    /* CLEANUP - Don't check for errors on purpose. */

    /* Reset GPCTR. */

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    printf(" GPCTR single buffered event counting done!\n");


}
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    u32 ulCount = 500;
    u32 ulLoopCount = 0;
    i16 iLineCount = 0;
    i16 iGroupSize = 1;
    i16 iPort = 0;
    i16 iNumLines = 8;
    i16 iIgnoreWarning = 0;
    i16 iReady = 0;
    i16 iPGmodeOn = 1;
    i16 iDIGroup = 1;
    i16 iDIReqSource = 3;
    i16 iInLineDirection = 4;
    i16 iInGroupDirection = 0;
    i16 iDIEdge = 0;
    i16 iDataPoint = 0;
    u32 ulGpctrNum = ND_COUNTER_0;
    u32 ulGpctrOutput = ND_GPCTR0_OUTPUT;
    u32 ulLOWcount = 500;
    u32 ulHIGHcount = 500;

    /* Configure the digital lines for the correct direction. */

    while (iLineCount < iNumLines) {


        iStatus = DIG_Line_Config(iDevice, iPort, iLineCount,
         iInLineDirection);

        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Line_Config",
         iIgnoreWarning);

        ++iLineCount;

    }


    /* Configure Digital Input */

    iStatus = DIG_Grp_Config(iDevice, iDIGroup, iGroupSize, iPort,
     iInGroupDirection);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Config",
     iIgnoreWarning);

    iStatus = DIG_Grp_Mode(iDevice, iDIGroup, 0, iDIEdge, 0, 0, 0);
    

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Mode",
     iIgnoreWarning);

    /* Correlate the input to the signal coming across the RTSI 0
     line. */

    iStatus = DIG_Block_PG_Config(iDevice, iDIGroup, iPGmodeOn,
     iDIReqSource, 0, 0, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Block_PG_Config",
     iIgnoreWarning);

    /* Route the output of GPCTR0 to RTSI 0 */

    iStatus = Select_Signal(iDevice, ND_RTSI_0, ND_GPCTR0_OUTPUT,
     ND_DONT_CARE);

    iRetVal = NIDAQErrorHandler(iStatus, "Select_Signal",
     iIgnoreWarning);

    /* Setup counter 0 to output a 100 Hz square wave. */

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/RESET",
     iIgnoreWarning);

    iStatus = GPCTR_Set_Application(iDevice, ulGpctrNum,
     ND_PULSE_TRAIN_GNR);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Set_Application",
     iIgnoreWarning);

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_SOURCE,
     ND_INTERNAL_100_KHZ);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/SOURCE", iIgnoreWarning);

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_COUNT_1,
     ulLOWcount);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/COUNT1", iIgnoreWarning);

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_COUNT_2,
     ulHIGHcount);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/COUNT2", iIgnoreWarning);

    /* To output a counter pulse, you must call Select_Signal. */

    iStatus = Select_Signal(iDevice, ulGpctrOutput, ulGpctrOutput,
     ND_LOW_TO_HIGH);

    iRetVal = NIDAQErrorHandler(iStatus, "Select_Signal/GpctrOutput",
     iIgnoreWarning);

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_PROGRAM);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/PROGRAM",
     iIgnoreWarning);

    printf(" Square wave generation started...\n");

    /* Input ulCount number of points. */

    while ((ulLoopCount < ulCount) && (iStatus == 0)) {


        iStatus = DIG_Grp_Status(iDevice, iDIGroup, &iReady);

        if ((iReady == 1) && (iStatus == 0)) {


            iStatus = DIG_In_Grp(iDevice, iDIGroup, &iDataPoint);
            

            iRetVal = NIDAQErrorHandler(iStatus, "DIG_In_Grp", 0);
            

            ++ulLoopCount;;

        }


        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Grp_Status", 0);
        

    }


    /* Reset GPCTR. */

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    /* Disconnect GPCTR0_OUTPUT. */

    iStatus = Select_Signal(iDevice, ND_GPCTR0_OUTPUT, ND_NONE,
     ND_DONT_CARE);

    /* Remove any signal from RTSI 0. */

    iStatus = Select_Signal(iDevice, ND_RTSI_0, ND_NONE,
     ND_DONT_CARE);

    iRetVal = NIDAQErrorHandler(iStatus, "Select_Signal",
     iIgnoreWarning);

    /* Clear all operations and reset the board to its default state
     */

    iStatus = DIG_Grp_Config(iDevice, iDIGroup, 0, 0, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Grp_Config",
     iIgnoreWarning);


}
Ejemplo n.º 23
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iChan = 1;
    i16 iStartTrig = 0;
    i16 iExtScan = 2;
    i16 iGain = 1;
    f64 dSampRate = 1000.0;
    u32 ulCount = 200;
    f64 dGainAdjust = 1.0;
    f64 dOffset = 0.0;
    i16 iUnits = 0;
    i16 iSampTB = 0;
    u16 uSampInt = 0;
    i16 iScanTB = 0;
    u16 uScanInt = 0;
    static i16 piBuffer[200] = {0};
    static f64 pdVoltBuffer[200] = {0.0};
    i16 iDAQstopped = 0;
    u32 ulRetrieved = 0;
    i16 iNumChans = 2;
    static i16 piChanVect[2] = {1, 2};
    static i16 piGainVect[2] = {1, 1};
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;

    /* Setup for external scan timing with iExtScan = 2. */

    iStatus = DAQ_Config(iDevice, iStartTrig, iExtScan);

    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_Config",
     iIgnoreWarning);

    /* Convert sample rate (S/sec) to appropriate timebase and sample
     interval values. (NOT scan interval values) */

    iStatus = DAQ_Rate(dSampRate, iUnits, &iSampTB, &uSampInt);

    iStatus = SCAN_Setup(iDevice, iNumChans, piChanVect, piGainVect);
    

    iRetVal = NIDAQErrorHandler(iStatus, "SCAN_Setup",
     iIgnoreWarning);

    /* Acquire data */

    iStatus = SCAN_Start(iDevice, piBuffer, ulCount, iSampTB,
     uSampInt, iScanTB, uScanInt);

    iRetVal = NIDAQErrorHandler(iStatus, "SCAN_Start",
     iIgnoreWarning);

    printf(" Apply your external scan timing pulses to the 'external scan clock' pin.\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, ulCount, iNumChans, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "SCAN_Demux",
     iIgnoreWarning);

    iStatus = DAQ_VScale(iDevice, iChan, iGain, dGainAdjust, dOffset,
     ulCount, piBuffer, pdVoltBuffer);

    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_VScale",
     iIgnoreWarning);

    /* CLEANUP - Don't check for errors on purpose. */

    /* Set scan timing back to initial state. */

    iStatus = DAQ_Config(iDevice, 0, 0);

    iStatus = DAQ_Clear(iDevice);

    printf(" The plot shows Channel 1 data then Channel 2 data.\n");

    /* Plot acquired data */

    iRetVal = NIDAQPlotWaveform(pdVoltBuffer, ulCount, WFM_DATA_F64);
    

    printf(" The data is available in 'pdVoltBuffer'.\n");


}
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iGroup = 1;
    i16 iGroupSize = 2;
    i16 iPort = 0;
    i16 iDir = 1;
    i16 iPgConfig = 1;
    i16 iReqSource = 0;
    i16 iPgTB = 3;
    i16 iReqInt = 10;
    i16 iExtGate = 0;
    static i16 piBuffer[200] = {0};
    u32 ulCount = 100;
    u32 ulBufferSize = 200;
    i16 iResource = 11;
    u32 ulRemaining = 1;
    u32 ulAlignIndex = 0;
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;

    iStatus = NIDAQMakeBuffer(piBuffer, ulCount, WFM_DATA_I16);

    if (iStatus == 0) {


        /* Configure group of ports as output, with handshaking. */
        

        iStatus = DIG_Grp_Config(iDevice, iGroup, iGroupSize, iPort,
         iDir);

        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Grp_Config",
         iIgnoreWarning);

        /* Configure internally timed pattern generation with timebase
         3, interval 10, and no external gating. */

        iStatus = DIG_Block_PG_Config(iDevice, iGroup, iPgConfig,
         iReqSource, iPgTB, iReqInt, iExtGate);

        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_PG_Config",
         iIgnoreWarning);

        /* Align the DMA buffer so that it does not cross a page
         boundary for AT bus computers. (It is a good idea to keep your
         buffers smaller than 4kBytes in size.) NOTE: If you change 'iGroup'
         or 'iGroupSize', make sure 'iResource' is changed accordingly. */
        

        iStatus = Align_DMA_Buffer(iDevice, iResource, piBuffer,
         ulCount, ulBufferSize, &ulAlignIndex);

        iRetVal = NIDAQErrorHandler(iStatus, "Align_DMA_Buffer",
         iIgnoreWarning);

        /* Start the pattern generation output of 100 "items". */
        

        iStatus = DIG_Block_Out(iDevice, iGroup, piBuffer, ulCount);
        

        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_Out",
         iIgnoreWarning);

        while ((ulRemaining != 0) && (iStatus == 0)) {


            iStatus = DIG_Block_Check(iDevice, iGroup, &ulRemaining);
            

            iRetVal = NIDAQYield(iYieldON);

        }


        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_Check",
         iIgnoreWarning);

        /* CLEANUP - Don't check for errors on purpose. */

        /* Clear the block operation. */

        iStatus = DIG_Block_Clear(iDevice, iGroup);

        /* Unconfigure group. */

        iStatus = DIG_Grp_Config(iDevice, iGroup, 0, 0, 0);

        printf(" Digital pattern generation output is done!\n");

    }
    else {

        printf(" The buffer was not made correctly. Check the parameters for NIDAQMakeBuffer.\n");

    }



}
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iNumChans = 1;
    i16 iChan = 0;
    static i16 piChanVect[1] = {0};
    i16 iGroup = 1;
    static f64 pdBuffer[5000] = {0};
    static i16 piBuffer[5000] = {0};
    u32 ulCount = 5000;
    u32 ulIterations = 1;
    i16 iFIFOMode = 0;
    i16 iDelayMode = 0;
    i16 iUpdateTB = 0;
    u32 ulUpdateInt = 0;
    i16 iWhichClock = 0;
    i16 iUnits = 0;
    i16 iWFMstopped = 0;
    u32 ulItersDone = 0;
    u32 ulPtsDone = 0;
    i16 iOpSTART = 1;
    i16 iOpCLEAR = 0;
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;

    iStatus = NIDAQMakeBuffer(pdBuffer, ulCount, WFM_DATA_F64);

    if (iStatus == 0) {


        /* If buffer was made correctly, then output it. */

        iStatus = WFM_Group_Setup(iDevice, iNumChans, piChanVect,
         iGroup);

        iRetVal = NIDAQErrorHandler(iStatus, "WFM_Group_Setup",
         iIgnoreWarning);

        iStatus = WFM_Scale(iDevice, iChan, ulCount, 1.0, pdBuffer,
         piBuffer);

        iRetVal = NIDAQErrorHandler(iStatus, "WFM_Scale",
         iIgnoreWarning);

        iStatus = WFM_Load(iDevice, iNumChans, piChanVect, piBuffer,
         ulCount, ulIterations, iFIFOMode);

        iRetVal = NIDAQErrorHandler(iStatus, "WFM_Load",
         iIgnoreWarning);

        /* Instead of calling WFM_Rate, just let iUpdateTB be 0 for
         external update timing. */

        iStatus = WFM_ClockRate(iDevice, iGroup, iWhichClock,
         iUpdateTB, ulUpdateInt, iDelayMode);

        iRetVal = NIDAQErrorHandler(iStatus, "WFM_ClockRate",
         iIgnoreWarning);

        /* Setup PFI lines for external updates. (PFI5 is setup by
         default in WFM_ClockRate) */

        iStatus = Select_Signal(iDevice, ND_OUT_UPDATE, ND_PFI_5,
         ND_HIGH_TO_LOW);

        iRetVal = NIDAQErrorHandler(iStatus, "Select_Signal",
         iIgnoreWarning);

        printf(" Apply your external update clock signal to PFI5 to output the waveform.\n");

        iStatus = WFM_Group_Control(iDevice, iGroup, iOpSTART);
        

        iRetVal = NIDAQErrorHandler(iStatus,
         "WFM_Group_Control/START", iIgnoreWarning);

        while ((iWFMstopped == 0) && (iStatus == 0)) {


            iStatus = WFM_Check(iDevice, iChan, &iWFMstopped,
             &ulItersDone, &ulPtsDone);

            iRetVal = NIDAQYield(iYieldON);

        }


        iRetVal = NIDAQErrorHandler(iStatus, "WFM_Check",
         iIgnoreWarning);

        /* CLEANUP - Don't check for errors on purpose. */

        /* Set group back to initial state. */

        iStatus = WFM_Group_Control(iDevice, iGroup, iOpCLEAR);
        

        /* Set output at 0 volts. */

        iStatus = AO_VWrite(iDevice, iChan, 0.0);

        /* Set PFI line back to initial state. */

        iStatus = Select_Signal(iDevice, ND_OUT_UPDATE,
         ND_INTERNAL_TIMER, ND_LOW_TO_HIGH);

        printf(" The waveform generation is done!\n");

    }
    else {

        printf(" The buffer was not made correctly. Check the parameters for NIDAQMakeBuffer.\n");

    }



}
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    u32 ulGpctrNum = ND_COUNTER_0;
    u32 ulGpctrOutput = ND_GPCTR0_OUTPUT;
    u32 ulLOWcount = 100;
    u32 ulHIGHcount = 10000;
    i16 iIgnoreWarning = 0;

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/RESET",
     iIgnoreWarning);

    iStatus = GPCTR_Set_Application(iDevice, ulGpctrNum,
     ND_RETRIG_PULSE_GNR);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Set_Application",
     iIgnoreWarning);

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_SOURCE,
     ND_INTERNAL_100_KHZ);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/SOURCE", iIgnoreWarning);

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_GATE,
     ND_DEFAULT_PFI_LINE);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/GATE", iIgnoreWarning);

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_COUNT_1,
     ulLOWcount);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/COUNT1", iIgnoreWarning);

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_COUNT_2,
     ulHIGHcount);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/COUNT2", iIgnoreWarning);

    /* To output a counter pulse, you must call Select_Signal. */

    iStatus = Select_Signal(iDevice, ulGpctrOutput, ulGpctrOutput,
     ND_LOW_TO_HIGH);

    iRetVal = NIDAQErrorHandler(iStatus, "Select_Signal/GpctrOutput",
     iIgnoreWarning);

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_PROGRAM);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/PROGRAM",
     iIgnoreWarning);

    printf(" Apply trigger pulses to the GATE of your counter and you will see a pulse every time!\n");

    /* HINT: If you don't see pulses at the OUTPUT of your counter,
     check your connections. */

    printf(" Hit any key to stop.\n");

    iRetVal = NIDAQWaitForKey(0.0);

    /* CLEANUP - Don't check for errors on purpose. */

    /* Reset GPCTR. */

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    /* Disconnect GPCTR0_OUTPUT. */

    /* Note that the following Select_Signal call will cause the
     output to be high impedance which will most likely bring the logic
     level HIGH if there is a pull-up resistor on this pin. (Check your
     hardware user manual.)  If you do not want this behavior, comment out
     the next line. */

    iStatus = Select_Signal(iDevice, ND_GPCTR0_OUTPUT, ND_NONE,
     ND_DONT_CARE);

    printf(" Repeated triggered pulse generation done!\n");


}
Ejemplo n.º 27
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    u32 ulGpctrNum = ND_COUNTER_0;
    static u32 pulBuffer[100] = {0};
    u32 ulCount = 100;
    u32 ulInitCount = 0;
    u32 ulArmed = ND_YES;
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/RESET",
     iIgnoreWarning);

    iStatus = GPCTR_Set_Application(iDevice, ulGpctrNum,
     ND_BUFFERED_EVENT_CNT);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Set_Application",
     iIgnoreWarning);

    /* If you want to use a different GPCTR source, change the last
     parameter in this function. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_SOURCE,
     ND_INTERNAL_20_MHZ);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/SOURCE", iIgnoreWarning);

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_GATE,
     ND_DEFAULT_PFI_LINE);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/GATE", iIgnoreWarning);

    /* Load initial count. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_INITIAL_COUNT, ulInitCount);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/INITCOUNT", iIgnoreWarning);

    iStatus = GPCTR_Config_Buffer(iDevice, ulGpctrNum, 0, ulCount,
     pulBuffer);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Config_Buffer",
     iIgnoreWarning);

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_PROGRAM);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/PROGRAM",
     iIgnoreWarning);

    printf(" Apply your gating trigger pulse train to the GATE of your counter now.\n");

    /* Loop until 'ulGpctrNum' is no longer armed. */

    do {


        iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_ARMED,
         &ulArmed);

        iRetVal = NIDAQYield(iYieldON);

    } while ((ulArmed == ND_YES) && (iStatus == 0));


    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Watch/ARMED",
     iIgnoreWarning);

    printf(" Event count data is in 'pulBuffer'.\n");

    /* Plot acquired count data.  For your application, you may want
     to different representation of count data. */

    iRetVal = NIDAQPlotWaveform(pulBuffer, ulCount, WFM_DATA_U32);

    /* CLEANUP - Don't check for errors on purpose. */

    /* Reset GPCTR. */

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    printf(" GPCTR buffered event counting done!\n");


}
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    u32 ulGpctrNum = ND_COUNTER_0;
    u32 ulLineNum = ND_PFI_39;
    u32 ulCount = 0;
    u32 ulPrescale = 0;
    i32 ulTCReached = ND_NO;
    u32 iLoopCount = 100;
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/RESET",
     iIgnoreWarning);

    /* Setup for a simple event counting application. */

    iStatus = GPCTR_Set_Application(iDevice, ulGpctrNum,
     ND_SIMPLE_EVENT_CNT);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Set_Application",
     iIgnoreWarning);

    /* Get the counter's maximum prescaling factor. */

    iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_MAX_PRESCALE,
     &ulPrescale);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Watch/PRESCALE",
     iIgnoreWarning);

    /* Setup the counter's prescaling factor. Besides the max prescale
     factor, you can also use 1 and 2. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_PRESCALE_VALUE, ulPrescale);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/PRESCALE", iIgnoreWarning);

    /* Specify the source input. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum, ND_SOURCE,
     ulLineNum);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/SOURCE", iIgnoreWarning);

    /* Load initial count. */

    iStatus = GPCTR_Change_Parameter(iDevice, ulGpctrNum,
     ND_INITIAL_COUNT, ulCount);

    iRetVal = NIDAQErrorHandler(iStatus,
     "GPCTR_Change_Parameter/INITCOUNT", iIgnoreWarning);

    printf(" Apply your digital pulse train to PFI 39.\n");

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_PROGRAM);

    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Control/PROGRAM",
     iIgnoreWarning);

    /* Loop 100 times. */

    do {


        iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_COUNT,
         &ulCount);

        iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Watch/COUNT",
         iIgnoreWarning);

        printf(" The current count is %lu x %lu\n", ulCount, ulPrescale);

        --iLoopCount;

        iStatus = GPCTR_Watch(iDevice, ulGpctrNum, ND_TC_REACHED,
         &ulTCReached);

        if (ulTCReached == ND_YES) {


            printf(" Counter reached terminal count! - The count may be incorrect.\n");

        }


        iRetVal = NIDAQYield(iYieldON);

    } while ((iLoopCount > 0) && (iStatus == 0));


    iRetVal = NIDAQErrorHandler(iStatus, "GPCTR_Watch",
     iIgnoreWarning);

    /* CLEANUP - Don't check for errors on purpose. */

    /* Reset GPCTR. */

    iStatus = GPCTR_Control(iDevice, ulGpctrNum, ND_RESET);

    printf(" Done with event counting with prescaling!!\n");


}
Ejemplo n.º 29
0
void main(void)
{
    /*
     * Local Variable Declarations: 
     */

    i16 iStatus = 0;
    i16 iRetVal = 0;
    i16 iDevice = 1;
    i16 iPGmodeOn = 1;
    u32 ulCount = 1000;
    i16 iLineCount = 0;
    i16 iGroupSize = 1;
    i16 iPort = 0;
    i16 iNumLines = 8;
    i16 iIgnoreWarning = 0;
    i16 iYieldON = 1;
    i16 iAIChan = 0;
    i16 iGain = 1;
    f64 dSampRate = 1000;
    i16 iAIUnits = 0;
    i16 iSampTB = 0;
    u16 uSampInt = 0;
    static i16 piAIBuffer[1000] = {0};
    static f64 pdAIVoltBuffer[1000] = {0};
    i16 iDAQStopped = 0;
    u32 ulPtsTfr = 0;
    f64 dGainAdjust = 1.0;
    f64 dOffset = 0.0;
    static i16 iDIBuffer[500] = {0};
    i16 iDIGroup = 1;
    i16 iDIReqSource = 9;
    i16 iInLineDirection = 4;
    i16 iInGroupDirection = 0;
    i16 iDIEdge = 0;

    /* Configure the digital lines for the correct direction. */

    while (iLineCount < iNumLines) {


        iStatus = DIG_Line_Config(iDevice, iPort, iLineCount,
         iInLineDirection);

        iRetVal = NIDAQErrorHandler(iStatus, "DIG_Line_Config",
         iIgnoreWarning);

        ++iLineCount;

    }


    /* Configure Digital Input */

    iStatus = DIG_Grp_Config(iDevice, iDIGroup, iGroupSize, iPort,
     iInGroupDirection);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Config",
     iIgnoreWarning);

    iStatus = DIG_Grp_Mode(iDevice, iDIGroup, 0, iDIEdge, 0, 0, 0);
    

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Grp_Mode",
     iIgnoreWarning);

    /* Correlate the input to the Analog Input Scan Clock. */

    iStatus = DIG_Block_PG_Config(iDevice, iDIGroup, iPGmodeOn,
     iDIReqSource, 0, 0, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "Dig_Block_PG_Config",
     iIgnoreWarning);

    /* Configure Analog Input */

    iStatus = DAQ_Rate(dSampRate, iAIUnits, &iSampTB, &uSampInt);

    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_Rate", iIgnoreWarning);
    

    /* Start acquiring data. */

    iStatus = DIG_Block_In(iDevice, iDIGroup, iDIBuffer, ulCount);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Block_In",
     iIgnoreWarning);

    iStatus = DAQ_Start(iDevice, iAIChan, iGain, piAIBuffer, ulCount,
     iSampTB, uSampInt);

    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_Start", iIgnoreWarning);
    

    while ((iDAQStopped != 1) && (iStatus == 0)) {


        /* Loop until the acquisition is complete.  HINT: You can be
         doing other foreground tasks during this time. */

        iStatus = DAQ_Check(iDevice, &iDAQStopped, &ulPtsTfr);

        iRetVal = NIDAQYield(iYieldON);

    }


    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_Check", iIgnoreWarning);
    

    iStatus = DAQ_VScale(iDevice, iAIChan, iGain, dGainAdjust,
     dOffset, ulCount, piAIBuffer, pdAIVoltBuffer);

    iRetVal = NIDAQErrorHandler(iStatus, "DAQ_VScale",
     iIgnoreWarning);

    /* Clear all operations and reset the board to its default state
     */

    iStatus = DAQ_Clear(iDevice);

    iStatus = DIG_Grp_Config(iDevice, iDIGroup, 0, 0, 0);

    iRetVal = NIDAQErrorHandler(iStatus, "DIG_Grp_Config",
     iIgnoreWarning);

    printf(" Digital data available in iDIBuffer.\n");

    printf(" Analog data available in pdAIVoltBuffer.\n");

    iRetVal = NIDAQPlotWaveform(pdAIVoltBuffer, ulCount,
     WFM_DATA_F64);


}