Skip to content
Ryan Summers edited this page Dec 31, 2015 · 4 revisions

ADC Functions

This page contains information describing the use of functions relating to the ADC SUBLIBinal peripheral library. Please refer to the list below to be redirected to the appropriate documentation.

Functions:


initialize_ADC

Definition

ADC_Data* initialize_ADC(ADC_Config config);

Description
The initialize_ADC function is used for configuring and initializing an ADC. This function will configure analog pins specified in the config structure and will set the ADC to sample for 15 cycles utilizing the ADC clock. Results will be returned as 16-bit unsigned integers.

Parameters

  • ADC_Config config: This parameter is a completely filled out ADC_Config structure. Please note, the callback function is NOT necessary for the ADC to properly operate. Callback functions for handling data once it has been processed should be placed in the ADC_Node for use in the background process. Please refer to ADC Design documentation for more information.

Return Value
This function returns a pointer to an ADC_Data structure. This structure is described in the ADC Structures documentation. This is meant to hand a pointer to the structure for querying ADC status. This structure should not be modified by the user. It is acceptable to not maintain a pointer to the structure in your main program. If you do not keep the pointer returned by this function, the ADC will still function normally.

top


read_ADC

Definition

int read_ADC(ADC_Node node);

Description
The read_ADC function will place an ADC Node on the work queue of the ADC for read processing. When a node is placed on the queue, it will begin sampling and conversion of the node as soon as the ADC is able to. This function will copy all contents specified in the node parameter, so it may leave scope in user defined functions. Please note, node callback function should be specified so that proper data handling can occur. The function pointer will be executed during the ADC background process when the node has been moved to the result buffer.

Parameters

  • ADC_Node node: This function accepts a completely filled out ADC_Node structure. All parameters of the structure should be filled out. The callback function specified within this node should accept a single ADC_Node data type as an input parameter and should not return any values. This function will be called when a node has finished processing and will be called from the background process. When nodes have completed a read, they are moved from the work buffer to the result buffer.

Return
This function will return an ERROR enumeration based upon a node insertion into the work queue. The only case that this will return an error is if the queue does not have sufficient space for copying the node into it.

top


bg_process_ADC

Definition

void bg_process_ADC(void);

Description
The ADC background process should be placed in the main embedded system loop for processing of elements completed by the ADC when the processor is not busy. The reason behind doing processing in a background process is to ensure that the microcontroller can successfully handle interrupts during processing of individual node elements. The function of the background process is to simply dequeue nodes from the ADC results queue and then call those nodes' callback functions. These callback functions are unique in that the background process will call them with a single input parameter. Nodes callback functions will be called and provided a Node_Data data type that is the node itself. This is so that the end user can access the converted ADC data and unique ID associated with a node.

Parameters
This function accepts no parameters and returns no parameters. This function should always be placed within the main embedded loop when the ADC is implemented in a program.

top


setup_ADC_pins

Definition

void setup_ADC_pins(uint16 channels);

Description
This function is a function provided for configuring the tristate and analog state of pins. This function will take in a 16-bit value and then decode this value to determine which ADC channels should be configured. It will then set the tristate as an input and tell analog selection that this is an analog pin. This function does NOT need to be called by the end user if they have called initialize_ADC and have not reconfigured analog and tristate variables, as the initialize_ADC function invokes this function internally.

Parameters

  • uint16channels: This is a 16-bitfield value that enumerates which channels should be configured. The input of this variable should be specified using the ADC_Channel enumeration. An example of a value provided to this function would be (1<<ADC_CH_2)|(1<<ADC_CH_4)|(1<<ADC_CH_9). This would tell the program to initialize pins AN2, AN4, and AN9 as analog inputs.

top

Clone this wiki locally