Internals

The analog I/O module makes extensive use of floating-point arithmetic (additions, multiplications, and divisions). The reason I chose to use floating-point instead of integer arithmetic is that it is very difficult to make a general purpose analog I/O module using integer arithmetic. The analog I/O module can become CPU-intensive unless you have hardware-assisted floating-point (i.e., a math coprocessor). The analog I/O module, however, can be easily modified to make use of integer arithmetic if you have a dedicated application.

Figure 10.12 shows a block diagram of the analog I/O module. You should also refer to Listings 10.1 and 10.2 for the following description. As shown, the analog I/O module consists of a single task (AIOTask ()) that executes at a regular interval (set by AI0_TASK_DLY). AIOTask () can manage as many analog inputs and outputs as your application requires (up to 250 each). The analog I/O module must be initialized by calling AlOInit (). AlOInit () initializes all analog input channels, all analog output channels, the hardware (ADCs and DACs), a semaphore used to ensure exclusive access to the internal data structures used by the analog I/O module, and finally, AlOInit () creates AIOTask ().

AITbl [ ] is a table that contains configuration and run-time information for each analog input channel. An entry in AITbl [ ] is a structure defined in AIO. H and is called AIO. AlUpdate () is charged with reading all of the analog input channels on a regular basis. AlUpdate () calls AIRd () and passes it a logical channel number (0. . AIO_MAX_AI - 1). AIRd () is responsible for selecting the proper analog input through one or more multiplexers (based on the logical channel number), starting and waiting for the proper ADC to convert (if more than one is used), and for returning raw counts to AlUpdate (). AIRd () is the only function that knows about your hardware, and thus AIRd () can easily be adapted to your environment.

AOTbl [ ] is a table that contains configuration and run-time information for each analog output channel. An entry in AOTbl [ ] also uses the AIO structure. AOUpdate () is responsible for updating all of the analog output channels on a regular basis. AOUpdate () calls AOWr () and passes it a logical channel number (0. . AIO_MAX_AO - 1) and the raw DAC counts. AOWr () is responsible for output-ing the raw counts to the proper DAC based on the logical channel. AOWr () is the only function that knows about your hardware, and thus AOWr () can easily be adapted to your environment.

Was this article helpful?

0 0

Post a comment