ADC Structures - PalouseRobosub/SUBLIBinal GitHub Wiki
ADC Structures
This page contains information describing the use and parameters of all the structures associated with the ADC functionality implemented within SUBLIBinal. Please select the appropriate structure from the list below to be redirected to documentation.
Structures:
ADC_Data
Declaration
typedef struct ADC_DATA {
Queue Results_queue;
Queue Work_queue;
boolean is_idle;
}ADC_Data;
Description
The ADC_Data structure is generated by the initialize_ADC function. The purpose of this structure is for querying of ADC's current state. This structure is used internally in SUBLIBinal to maintain information about the ADC between ADC reads. The user should not modify the contents of the structure pointer returned by initialize_ADC()
.
Parameters
- Queue Results_queue: This is a queue of the results ADC nodes.
- Queue Work_queue: This is a queue of the ADC Nodes that still need to be processed
- boolean is_idle: This parameter tells you whether the ADC is currently sampling and processing or if it is idle.
ADC_Node
Declaration
typedef struct ADC_NODE {
uint8 device_id;
ADC_Channel channel;
uint16 data;
void (*callback) (struct ADC_NODE);
} ADC_Node;
Description
This structure is an ADC Node. The ADC Node is used for reading a channel on the ADC. An arbitrary ID should be supplied to the node, and this node will be placed onto the ADC work queue for processing. When the node has been completed, it will be placed on the results queue.
Parameters
- uint8 device_id: This is an arbitrary value that is used by the user to be able to differentiate between different types of ADC reads.
- ADC_Channel channel: This specifies which channel should be read by the ADC. A read of channel 0 will result in the reading of pin AN0.
- uint16 data: This parameter is where data will be stored once the ADC has finished conversion.
- void *callback: This callback function breaks normal callback function conventions specified in the callback function documentation. The callback function supplied in an ADC should accept a single argument of an ADC_Node. This callback function will be executed during the ADC background process, and will be handed the node that contains the function pointer (the node itself that is calling the callback function).
ADC_Config
Declaration
typedef struct ADC_CONFIG {
uint16 channels;
uint8 *work_buffer_ptr;
uint work_buffer_size;
uint8 *result_buffer_ptr;
uint result_buffer_size;
void* callback;
} ADC_Config;
Description
This structure is used for configuration of the ADC during the initialize_ADC()
function. The ADC operates using data buffers for the work and result queues, and thus must be handed memory that will remain in scope for the entirety of program execution. Please declare an array either in main or globally and supply a pointer to the array for the result and work buffer pointers. These arrays should not be modified, or the ADC will malfunction.
Parameters
- uint16 channels: This parameter will automatically configure any channels specified as analog channels in the microcontroller. It is a bitfield value. If you would like to configure channels 1 and 4, you would set this parameter equal to
(1<<1)|(1<<4)
. - uint8 *work_buffer_ptr: This parameter is a pointer to an array of data. This data must not go out of scope and must be reserved for use solely by the ADC. It can not be the same data as supplied for the results buffer.
- uint work_buffer_size: This parameter specifies the number of bytes pointed to by
work_buffer_ptr
. Ifwork_buffer_ptr
is an array, you can supplysizeof(work_buffer_ptr)
as the parameter. - uint8 *result_buffer_ptr: This parameter is a pointer to an array of data. This data must not go out of scope and must be reserved for use solely by the ADC. It can not be the same data as supplied to the
work_buffer_ptr
. - uint result_buffer_size: This parameter specifies the number of bytes pointed to by the
result_buffer_ptr
. Ifresult_buffer_ptr
is an array, you can supplysizeof(result_buffer_ptr)
as the parameter. - void *callback: This callback occurs whenever the ADC interrupt occurs. This callback should not be used for getting data back from the ADC! Please see the callback function documentation for more information on callback functions.