ADC

ADC Interface Spec

The ADC peripheral driver allows access to the MCU’s built-in ADC. Each peripheral is opened using a unique port number and mode settings. Once open, any channel from the ADC can be read. Closing the peripheral will disable power to the ADC. More information about accessing hardware is in the Device Interface section.

The following is an example of how to read the ADC in an OS environment:


Details

define I_ADC_GETVERSION

define I_ADC_GETINFO

This requests reads the ADC attributes.

Example:

#include <dev/adc.h>
adc_attr_t attr;
int adc_fd;
...
ioctl(adc_fd, I_ADC_GETINFO, &attr);

define I_ADC_SETATTR

This requests writes the ADC attributes.

Example:

#include <dev/adc.h>
adc_attr_t attr;
int adc_fd;
...
ioctl(adc_fd, I_ADC_SETATTR, &attr);

define I_ADC_SETACTION

enum adc_flag_t
  • ADC_LOC_IS_GROUP Set loc value when reading ADC to read the group)
  • ADC_FLAG_SET_CONVERTER Configure the ADC
  • ADC_FLAG_IS_LEFT_JUSTIFIED Left Align data
  • ADC_FLAG_IS_RIGHT_JUSTIFIED Right align data
  • ADC_FLAG_SET_MASTER Used with MCUs that have more than one ADC that can operate in master/slave mode
  • ADC_FLAG_SET_SLAVE Used with MCUs that have more than one ADC that can operate in master/slave mode
  • ADC_FLAG_IS_TRIGGER_TMR Used to trigger the ADC read on a timer event
  • ADC_FLAG_IS_TRIGGER_EINT Used to trigger the ADC read on a external interrupt
  • ADC_FLAG_SET_CHANNELS Configure the channels withouth changing ADC settings
  • ADC_FLAG_IS_SCAN_MODE ADC will read every enabled channel when reading rather than the channel based on the location value
  • ADC_FLAG_IS_TRIGGER_EINT_EDGE_RISING
  • ADC_FLAG_IS_TRIGGER_EINT_EDGE_FALLING
  • ADC_FLAG_IS_GROUP
  • ADC_FLAG_IS_CONTINOUS_CONVERSION

ADC flags


struct::adc_info_t

ADC info for use with I_ADC_GETINFO.

u32 o_flags

A bitmask for the supported features

u32 o_events

Events supported by this driver

u32 freq

The maximum frequency

u32 maximum

The maximum value returned by the ADC

u32 reference_mv

The reference voltage in millivolts

u8 resolution

The number of bits supported by the ADC

u8 bytes_per_sample

The number of bytes in each sample

u8 resd_align

u32 resd

struct::adc_pin_assignment_t

mcu_pin_t channel

Pins to use with the ADC. If more than 4 are needed, make multiple calls to I_ADC_SETATTR


struct::adc_attr_t

u32 o_flags

The flag bitmask used with the ADC

adc_pin_assignment_t pin_assignment

The pins to assigned to the ADC

u32 freq

Target frequency when setting ADC

mcu_pin_t trigger

Pin or Timer trigger

u8 width

Bit resolution (if variable resolution is supported)

u8 channel_count

Number of channels to convert when ADC_FLAG_IS_SCAN_MODE is set

u16 channel

Channel number when using ADC_FLAG_SET_CHANNELS with ADC_FLAG_IS_GROUP

u32 rank

Rank when using ADC_FLAG_SET_CHANNELS with ADC_FLAG_IS_GROUP

u32 sampling_time

Sampling time (in ADC clock cycles) when using ADC_FLAG_SET_CHANNELS with ADC_FLAG_IS_GROUP

u32 resd

X

Thanks for Coming!

Subscribe to news and updates