High level interface for interacting with the analog to digital converter (ADC).
Both single-ended and differential channels are supported. The values returned by the read API are relative to the ADC's voltage range, which is device specific. See the BSP documentation for details.
The following snippet initializes an ADC and one channel. One ADC conversion result is returned corresponding to the input at the specified pin.
API Reference | |
ADC HAL Results | |
ADC specific return codes. | |
Macros | |
#define | MTB_HAL_ADC_BITS 16 |
Number of bits populated with meaningful data by each ADC sample. | |
#define | MTB_HAL_ADC_MAX_VALUE ((1 << MTB_HAL_ADC_BITS) - 1) |
Maximum value that the ADC can return. | |
Functions | |
cy_rslt_t | mtb_hal_adc_setup (mtb_hal_adc_t *obj, const mtb_hal_adc_configurator_t *config, mtb_hal_clock_t *clk, mtb_hal_adc_channel_t **channels) |
Sets up a HAL instance to use the specified hardware resource. More... | |
uint16_t | mtb_hal_adc_read_u16 (const mtb_hal_adc_channel_t *obj) |
Read the value from the ADC pin, represented as an unsigned 16bit value where 0x0000 represents the minimum value in the ADC's range, and 0xFFFF represents the maximum value in the ADC's range. More... | |
bool | mtb_hal_adc_is_conversion_complete (const mtb_hal_adc_channel_t *obj) |
Returns true if the most recently triggered conversion has completed for the specified channel. More... | |
cy_rslt_t | mtb_hal_adc_read_latest (const mtb_hal_adc_channel_t *obj, int32_t *result) |
Reads the result of the most recent scan for the specified channel and writes it to the given result location. More... | |
cy_rslt_t | mtb_hal_adc_read_multiple (mtb_hal_adc_channel_t **channels, uint32_t num_channels, int32_t *result) |
Read the value from the most recent scan for the specified set of ADC channels and writes it to the array specified by result. More... | |
cy_rslt_t | mtb_hal_adc_start_convert (mtb_hal_adc_t *obj) |
Triggers start of conversion for all enabled channels. More... | |
cy_rslt_t mtb_hal_adc_setup | ( | mtb_hal_adc_t * | obj, |
const mtb_hal_adc_configurator_t * | config, | ||
mtb_hal_clock_t * | clk, | ||
mtb_hal_adc_channel_t ** | channels | ||
) |
Sets up a HAL instance to use the specified hardware resource.
This hardware resource must have already been configured via the PDL.
[out] | obj | The HAL driver instance object. The caller must allocate the memory for this object, but the HAL will initialize its contents |
[in] | config | The configurator-generated HAL config structure for this peripheral instance |
[in] | clk | Clock instance that clocks this peripheral |
[in] | channels | Array of channels used by the ADC. Unused channels should be passed as NULL |
uint16_t mtb_hal_adc_read_u16 | ( | const mtb_hal_adc_channel_t * | obj | ) |
Read the value from the ADC pin, represented as an unsigned 16bit value where 0x0000 represents the minimum value in the ADC's range, and 0xFFFF represents the maximum value in the ADC's range.
If continous scanning is disabled, this will block while a conversion is performed on the selected channel, then return the result. Depending on the ADC speed this function may block for some time. If continuous scanning is enabled, this will return the value from the most recent conversion of the specified channel (if called shortly after enabling continuous scanning it may block until at least one conversion has been performed on this channel).
[in] | obj | The ADC object |
bool mtb_hal_adc_is_conversion_complete | ( | const mtb_hal_adc_channel_t * | obj | ) |
Returns true if the most recently triggered conversion has completed for the specified channel.
If continuous conversion is enabled, returns true if at least one conversion has completed.
[in] | obj | The ADC object |
cy_rslt_t mtb_hal_adc_read_latest | ( | const mtb_hal_adc_channel_t * | obj, |
int32_t * | result | ||
) |
Reads the result of the most recent scan for the specified channel and writes it to the given result
location.
This function will return the latest available value.
[in] | obj | The ADC object |
[out] | result | Scanned result |
cy_rslt_t mtb_hal_adc_read_multiple | ( | mtb_hal_adc_channel_t ** | channels, |
uint32_t | num_channels, | ||
int32_t * | result | ||
) |
Read the value from the most recent scan for the specified set of ADC channels and writes it to the array specified by result.
If a conversion has not completed for one or more of the specified channels, it will return error and will not update value to the array. "channels" and "result" list must have "num_channels" space in order to get ADC channels and store the results respectively.
This function will return the latest available value.
[in] | channels | The ADC channels object pointer |
[in] | num_channels | The number of ADC channels |
[out] | result | Scanned result |
cy_rslt_t mtb_hal_adc_start_convert | ( | mtb_hal_adc_t * | obj | ) |
Triggers start of conversion for all enabled channels.
The function returns without waiting for the conversion to complete.
[in] | obj | The ADC object |