Basic ADC Example
Reads and interprets the value of an ADC.
- SDK directory:
apps/basic/adc
- Zentri App Store:
ZENTRI-BAADC
API Features Demonstrated
- Peripherals/ADC API
- Utilities/Fixed Point Integer API
- fpi_to_str - converts a float to a string
Platforms
This app works on:
Requirements and Prerequisites
Requires a ZentriOS evaluation board, such as an AMWx06-E03 (Moray), that includes a thermistor.
Resources
The lookup table, therm_celsius_lut.csv
located in the app resources directory, is downloaded to the device.
Description
This app demonstrates how to read the raw value of an Analog-Digital Converter (ADC) and convert the value into a temperature value using a look up table.
Notes
- For accurate temperature readings, the board should include a thermistor connected to a GPIO with an ADC option.
Usage Instructions
Open a ZentriOS serial terminal to the device. See Getting Started, Opening a ZentriOS Terminal.
This app requires no interaction. It logs results to the ZentriOS terminal.
Implementation
The app runs to completion performing the following steps.
- zn_adc_init configures a GPIO as an ADC
- zn_adc_add_lut initializes a lookup table to convert ADC samples into temperature
- zn_adc_direct_sample gets a raw sample from the ADC
- zn_adc_sample_and_convert converts the raw sample to a temperature. If the lookup fails the value is printed as a floating point number.
- The app exits since
zn_app_idle
returns ZOS_FALSE
Source Code
See: