Chapter 14 Onboard Programs
NI-Motion User Manual 14-18 ni.com
err = flex_read_adc16(boardID, NIMC_ADC1, 2);
CheckError;
//Multiply variable 2 (ADC value) with variable 1
(constant)
// Save the result in variable 3
err = flex_mult_vars(boardID, 1, 2, 3);
CheckError;
//Subtract value in variable 3 from variable 4. The
result is //unimportant, you just want to set the
condition on board.
err = flex_sub_vars(boardID, 3, 4, 0);
CheckError;
// Jump to label 1 as the subtraction above set the
condition to //"equal to zero", which implies that
the values in variable 3 and //4 are the same
err = flex_jump_on_event (boardID, 0,
NIMC_CONDITION_EQUAL, 0, 0, NIMC_MATCH_ALL, 1/*label
number*/);
// Set the velocity for the move (in counts/sec) by
loading the //value from variable 3, which is (adc
value * constant)
err = flex_load_velocity(boardID, axis, 0, 3);
CheckError;
// Start the move to update the velocity
err = flex_start(boardID, axis, 0);
CheckError;
// Save the value in variable 3 to variable 4 for use
in next cycle
err = flex_read_var(boardID, 3, 4);
CheckError;
// Jump back to label 1 unconditionally
err = flex_jump_on_event (boardID, 0,
NIMC_CONDITION_TRUE, 0, 0, NIMC_MATCH_ALL, 1/*label
number*/);
CheckError;
// End Program Storage
err = flex_end_store(boardID, 1);
// To execute this program use the Run Program
function
return;// Exit the Application