fw has all the information necessary to program the analog input/output (AIO) for the lab exercises in this book. One aspect of the programming, the configuring of the AIO channels, was handled by the provided functions such as Aio_InitCO0(). To understand in more detail how to initialize an AIO channel on any connector on the myRIO, we provide the following details.
Before we can read or write to an AIO, the channel must be configured. An AIO channel can be selected by declaring a struct type MyRio_Aio, defined in the myRIO C library AIO.h header as
typedef struct {
uint32_t val; // AIO value register
uint32_t wght; // AIO weight constant value
uint32_t ofst; // AIO offset constant value
uint32_t set; // AO set register, unused for AI
NiFpga_Bool is_signed; // Is the AIO signed
double scale_weight; // AIO weight scaled value
double scale_offset; // AIO offset scaled value
} MyRio_Aio; So a variable MyRio_Aio AIC0 can be populated with information about a particular AIO. For instance, the C connector analog input (AI) AI0 (see Figure 4.10) can be specified with
MyRio_Aio AIC0;
AIC0.val = AIC_0VAL;
AIC0.wght = AIC_0WGHT;
AIC0.ofst = AIC_0OFST;
AIC0.is_signed = NiFpga_True; // for the C connector The C connector has differential analog inputs, so AIC0.is_signed = NiFpga_True. For connectors A and B, AIC0.is_signed = NiFpga_False.
To configure an output channel like the C connector analog ouput (AO) AO1 use,
MyRio_Aio AOC1;
AOC1.val = AOC_1VAL;
AOC1.wght = AOC_1WGHT;
AOC1.ofst = AOC_1OFST;
AOC1.set = AOSYSGO;
AOC1.is_signed = NiFpga_True; // for the C connectorAs usual, we must open a field-programmable gate array (FPGA) session with the MyRio_Open() function. Afterward, we should initialize the struct with the Aio_Scaling() function from the myRIO C library's AIO.h header. For the AI and AO channels defined here, the calls would be
Aio_Scaling(&AIC0); // initialize AI
Aio_Scaling(&AOC1); // initialize AOThis function ensures the proper scaling of the reading and writing operations. See Section 7.5 for details about reading and writing to AIO channels.
fpgaPersonality6