Chapter 14
Onboard Programs
14-24
ni.com
//
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
}
Math Operations
NI-Motion always performs math operations on values stored in onboard
variables, and all math operations set a global condition that the Jump to
Label function uses to determine if the operation jumps to a particular label
in the onboard program.
To load the onboard variables, use the Load Constant function or point the
return vector in the Read functions to the onboard variable where you want
the data to be saved. In the previous example, the ADC channel is read to
onboard variable 2. This value is then multiplied with a scale factor loaded
into variable 1 using the Load Constant function.
You can perform Add, Multiply, Subtract, Divide, AND, OR, XOR, NOT,
and logical shift math operations. The condition code always reflects the
last math operation performed. Less Than implies less than zero, Equal
implies equal to zero, and so on.
Indirect Variables
If you make the read or load functions point to variables 0x81 to 0xF8, the
functions use the value loaded in variables 1 to 0x78 and interpret them as
the address where the value is read or loaded. This creates two levels of
indirection.
Making the return vector of the Read Position function point to 0x81 causes
the position to end up in the address contained in onboard variable 1, as
shown in Figure 14-12.