ADC Design - PalouseRobosub/SUBLIBinal GitHub Wiki

ADC Design

This wiki page discusses the general functional design that the ADC follows for processing data. Please refer to the following list to be redirected to the appropriate documentation

Design


Background Process

The ADC background process is a function that should be placed in the continually executing loop in the main program. This process will continually remove node elements from the result buffer. When it removes an element successfully, it will invoke that nodes callback function and supply the node itself as a parameter to that callback function. This means that a background process may take a long time to return to main program execution, as it can continually remove nodes and call their respective functions. The background process is done separately than ADC processing so that an interrupt driven design is not held back through additional processing. Placing node callback functions within the ADC completion interrupt could potentially block other system-critical interrupts. This is why node callback data processing was moved towards a non-interrupt driven model. Nodes are handled when the main processor is idling in the main embedded loop.

top


Buffers

The ADC is one of many peripheral libraries to utilize buffers in its initialization. A buffer should simply be arrays of memory for use by the ADC. Buffers are used for storing ADC_Node structures internally so that they may go out of scope in the main program. When an read is called on an ADC node, the contents of the node are copied into the work buffer of the ADC. When the ADC has time to process the node, it will begin sampling and conversion of the node and remove it from the work buffer. When it completes conversion, it will place the node into the results buffer and will place the conversion data into the node structure. The results buffer will then simply hold results until called by the background process. Due to the functionality of these buffers, they must remain as allocated memory for use by the ADC during the entire time that the ADC is in use. These buffers must also be explicitly different sections in memory. That is, you may not supply the same parameters for the work and the result buffers.

top


Callback Functions

The ADC is one of the peripheral libraries within SUBLIBinal to utilize a unique callback function format. ADC callback functions operate differently than most other process callbacks. The ADC callback functions that are most important reside in the ADC_Node structure callbacks. The callback provided during the ADC initialization is not crucial for ADC functionality. These node callback functions are different in that they should accept a single argument of an ADC_Node data type. The reason behind this is that these callback functions are intended for processing of the results. By accepting a single ADC_Node parameter, these functions can be handed information about an ADC read. By utilizing the ID located within the node, different types of data can be handled in different ways by the callback function. When the node is received in the callback function, the data parameter in the node has been updated with the results from the ADC for use by the user.

Because the callback function is not embedded within an interrupt, other functions can be implemented within the callback such as UART transmission.

Please view the example below for a sample ADC callback function

void callback_ADC(ADC_Node node) {
    //... Process the ADC node here
}

top