High-Speed Capture C/C++ Code
The following section includes C/C++ code for executing a high-speed capture, as well as using RTSI to execute a high-speed capture. The following example code is not necessarily complete, and may not compile if copied exactly. Refer to the examples folder on the NI-Motion CD for files that are complete and compile as is.
// Main function void main(void) { u8 boardID; // Board identification number u8 axis; // Axis number u16 csr = 0; // Communication status register u16 axisStatus; // Axis status i32 capturedPositions[6]; // Array to store the captured positions i32 i; // Variables for modal error handling u16 commandID; // The commandID of the function u16 resourceID; // The resource ID i32 errorCode; // Error code /////////////////////////////// // Set the board ID boardID = 1; // Set the axis number axis = 1; //////////////////////////////// // Route breakpoint 1 to RTSI line 1 err = flex_select_signal (boardID, NIMC_HS_CAPTURE1 /*destination*/, NIMC_RTSI1/*source*/); CheckError; // Configure High Speed Capture err = flex_configure_hs_capture(boardID, axis, NIMC_HS_LOW_TO_HIGH_EDGE, 0); CheckError; for(i=0; i<6; i++){ // Enable the high speed capture on axis err = flex_enable_hs_capture(boardID, axis, NIMC_TRUE); CheckError; do { // Check the high speed capture status err = flex_read_axis_status_rtn(boardID, axis, &axisStatus); CheckError; // Read the communication status register and check the modal errors err = flex_read_csr_rtn(boardID, &csr); CheckError; // Check the modal errors if (csr & NIMC_MODAL_ERROR_MSG) { err = csr & NIMC_MODAL_ERROR_MSG; CheckError; } Sleep (10); // Check every 10 ms }while (!(axisStatus & NIMC_HIGH_SPEED_CAPTURE_BIT));// Wait for high speed capture to be triggered err = flex_read_cap_pos_rtn(boardID, axis, &capturedPositions[i]); CheckError; } return; // Exit the Application ///////////////////////////////////////////////////////////////////////// // Error Handling // nimcHandleError; //NIMCCATCHTHIS: // Check to see if there were any Modal Errors if (csr & NIMC_MODAL_ERROR_MSG){ do{ // Get the command ID, resource and the error code of the modal // error from the error stack on the board flex_read_error_msg_rtn(boardID,&commandID,&resourceID,&errorCode); nimcDisplayError(errorCode,commandID,resourceID); // Read the Communication Status Register flex_read_csr_rtn(boardID,&csr); }while(csr & NIMC_MODAL_ERROR_MSG); } else // Display regular error nimcDisplayError(err,0,0); return; // Exit the Application }