ADC
Functions for using analog-to-digital (ADC) conversion peripheral. More...
Modules | |
Types | |
Hardware ADC data types. | |
Functions | |
zos_result_t | zn_adc_init (zos_gpio_t gpio) |
Initialize GPIO's ADC function. More... | |
zos_result_t | zn_adc_sample (zos_gpio_t gpio, uint16_t *value_ptr, zos_adc_sample_t type) |
Take an ADC sample from the specified GPIO. More... | |
zos_result_t | zn_adc_direct_init (zos_adc_t adc, const zos_adc_config_t *config) |
Initialize the ADC peripheral. More... | |
zos_result_t | zn_adc_direct_sample (zos_adc_t adc, uint16_t *value_ptr) |
Take single 16bit ADC reading and store to given pointer. More... | |
zos_result_t | zn_adc_sample_stream (zos_adc_t adc, uint16_t *buffer, uint16_t sample_count) |
Take multiple 16bit ADC readings and store to given buffer. More... | |
zos_result_t | zn_adc_gpio_to_peripheral (zos_gpio_t gpio, zos_adc_t *adc_peripheral) |
Attempt to retrieve the ADC peripheral value from GPIO. More... | |
zos_result_t | zn_adc_safe_sample (zos_adc_t adc, uint8_t gain, uint32_t *value) |
Safely take a 16bit ADC reading and store to given buffer. More... | |
zos_result_t | zn_adc_add_lut (uint32_t adc_mask, const char *filename, zos_adc_lut_t *lut_ptr) |
Add Lookup Table (LUT) to ADC. More... | |
zos_result_t | zn_adc_remove_lut (zos_adc_lut_t *lut) |
Cleanup the memory used by a Lookup Table (LUT) More... | |
zos_result_t | zn_adc_sample_and_convert (zos_adc_t adc, uint8_t gain, fpi_word_t *conv_value) |
Table ADC sample and convert to corresponding value in Lookup Table. More... | |
Detailed Description
Functions for using analog-to-digital (ADC) conversion peripheral.
Function Documentation
zos_result_t zn_adc_add_lut | ( | uint32_t | adc_mask, |
const char * | filename, |
||
zos_adc_lut_t * | lut_ptr |
||
) |
Add Lookup Table (LUT) to ADC.
This reads a LUT file and prepares a table to be used to convert raw ADC readings into a corresponding value.
Use zn_adc_sample_and_convert() to get a converted value. Use zn_adc_remove_lut() to cleanup the LUT from memory.
- Parameters
-
[in] adc_mask
Bitmask corresponding to the ADCs to associate with LUT filename
the filename of the LUT lut_ptr
Pointer to allocated lut
- Returns
- zos_result_t result of api call
- Examples:
- basic/adc/adc.c.
zos_result_t zn_adc_direct_init | ( | zos_adc_t | adc, |
const zos_adc_config_t * | config |
||
) |
Initialize the ADC peripheral.
This bypasses ZentriOS and directly initializes the ADC peripheral.
- Parameters
-
[in] adc
The ADC to initialize [in] config
ADC peripheral configuration, zos_adc_config_t
- Returns
- zos_result_t result of api call
- Examples:
- basic/adc/adc.c.
zos_result_t zn_adc_direct_sample | ( | zos_adc_t | adc, |
uint16_t * | value_ptr |
||
) |
Take single 16bit ADC reading and store to given pointer.
This bypasses ZentriOS and directly samples the ADC peripheral.
- Note
- zn_adc_init() or zn_adc_init_with_config() MUST be called first.
- Parameters
-
[in] adc
The ADC to read [out] value_ptr
Pointer to hold 16bit raw ADC reading
- Returns
- zos_result_t result of api call
- Examples:
- basic/adc/adc.c.
zos_result_t zn_adc_gpio_to_peripheral | ( | zos_gpio_t | gpio, |
zos_adc_t * | adc_peripheral |
||
) |
Attempt to retrieve the ADC peripheral value from GPIO.
- Parameters
-
[in] gpio
GPIO of corresponding ADC [out] adc_peripheral
Pointer to hold ADC number of corresponding GPIO
- Returns
- zos_result_t result of api call
- Examples:
- basic/adc/adc.c.
zos_result_t zn_adc_init | ( | zos_gpio_t | gpio | ) |
Initialize GPIO's ADC function.
See ZentriOS Command API documentation: adc_take_sample
- Note
- This does not support the Lookup Table (LUT) feature. Refer to zn_adc_add_lut() for this functionality.
- Parameters
-
[in] gpio
The GPIO to initialize for ADC
- Returns
- zos_result_t result of api call
zos_result_t zn_adc_remove_lut | ( | zos_adc_lut_t * | lut | ) |
Cleanup the memory used by a Lookup Table (LUT)
- Parameters
-
lut
Lookup Table reference
- Returns
- zos_result_t result of api call
- Examples:
- basic/adc/adc.c.
zos_result_t zn_adc_safe_sample | ( | zos_adc_t | adc, |
uint8_t | gain, |
||
uint32_t * | value |
||
) |
Safely take a 16bit ADC reading and store to given buffer.
This ensures the ADC can safely be read without interfering with other GPIO operations.
- Note
- This is mainly a concern on the AMx06 boards which share the serial flash SPI signals with the ADC GPIOs.
It also automatically initializes the ADC peripheral.
- Parameters
-
[in] adc
The ADC to read sample [in] gain
The gain of ADC hardware (only used for AMW004 boards) [out] value
Pointer to hold ADC reading
- Returns
- zos_result_t result of api call
zos_result_t zn_adc_sample | ( | zos_gpio_t | gpio, |
uint16_t * | value_ptr, |
||
zos_adc_sample_t | type |
||
) |
Take an ADC sample from the specified GPIO.
See ZentriOS Command API documentation: adc_take_sample
- Note
- This does not support the Lookup Table (LUT) feature. Refer to zn_adc_add_lut() for this functionality.
- Parameters
-
[in] gpio
The GPIO to take reading [out] value_ptr
Holds ADC reading value [in] type
The type of ADC reading, zos_adc_sample_t
- Returns
- zos_result_t result of api call
zos_result_t zn_adc_sample_and_convert | ( | zos_adc_t | adc, |
uint8_t | gain, |
||
fpi_word_t * | conv_value |
||
) |
Table ADC sample and convert to corresponding value in Lookup Table.
Call zn_adc_add_lut() first to associate a LUT with the ADC.
The returned value is a Fixed Point Integer (FPI), refer to fpi_to_str_with_padding() for printing this value.
- Parameters
-
[in] adc
The ADC to sample [in] gain
The gain of ADC hardware (only used for AMW004 boards) [out] conv_value
The converted ADC sample as a Fixed Point Integer (FPI)
- Returns
- zos_result_t result of api call
- Examples:
- basic/adc/adc.c.
zos_result_t zn_adc_sample_stream | ( | zos_adc_t | adc, |
uint16_t * | buffer, |
||
uint16_t | sample_count |
||
) |
Take multiple 16bit ADC readings and store to given buffer.
- Note
- zn_adc_init() or zn_adc_init_with_config() MUST be called first.
- Parameters
-
[in] adc
The ADC to read samples [out] buffer
Buffer to hold sample_count 16bit raw ADC readings [in] sample_count
Number of ADC samples to take
- Returns
- zos_result_t result of api call