d_adc.c
Go to the documentation of this file.
1 #include "asf.h"
2 #include "d_adc.h"
3 
4 int adc_init(void)
5 {
6  static bool initialized = false;
7  if (initialized)
8  return 0;
9 
10  //Configure AFEC unit
12  struct afec_config afec_cfg;
13  afec_get_config_defaults(&afec_cfg);
14  afec_init(AFEC0, &afec_cfg);
16 
17  //Configure ADC channel
18  struct afec_ch_config afec_ch_cfg;
19  afec_ch_cfg.diff = false;
20  afec_ch_cfg.gain = AFEC_GAINVALUE_0;
21  afec_ch_set_config(AFEC0, AFEC_CHANNEL_4, &afec_ch_cfg);
22  afec_channel_set_analog_offset(AFEC0, AFEC_CHANNEL_4, 0x200);
23  afec_channel_enable(AFEC0, AFEC_CHANNEL_4);
24 
26 
27  initialized = true;
28 
29  return 0;
30 }
31 
32 
33 float adc_voltage(void)
34 {
35  volatile uint32_t data = afec_channel_get_value(AFEC0, AFEC_CHANNEL_4);
36  return (float)data * ADC_VOLT_REF / ADC_MAX_DIGITAL / 1000.0f;
37 }
float adc_voltage(void)
Definition: d_adc.c:33
Analog-Front-End Controller configuration structure.
void afec_enable(Afec *const afec)
Enable AFEC Module.
Definition: afec.c:576
static void afec_channel_enable(Afec *const afec, const enum afec_channel_num afec_ch)
Enable the specified AFEC channel.
int adc_init(void)
Definition: d_adc.c:4
static void afec_channel_set_analog_offset(Afec *const afec, enum afec_channel_num afec_ch, uint16_t aoffset)
Set analog offset to be used for channel CSEL.
enum afec_gainvalue gain
void afec_get_config_defaults(struct afec_config *const cfg)
Get the AFEC default configurations.
Definition: afec.c:239
#define ADC_MAX_DIGITAL
Definition: d_adc.h:9
#define ADC_VOLT_REF
Definition: d_adc.h:8
#define PIO_PE4_IDX
USBInterfaceDescriptor data
static uint32_t afec_channel_get_value(Afec *const afec, enum afec_channel_num afec_ch)
Read the Converted Data of the selected channel.
static void ioport_set_pin_dir(ioport_pin_t pin, enum ioport_direction dir)
Set direction for a single IOPORT pin.
Definition: ioport.h:263
static void afec_set_trigger(Afec *const afec, const enum afec_trigger trigger)
Configure conversion trigger and free run mode.
#define AFEC0
(AFEC0 ) Base Address
Definition: same70j19.h:509
enum status_code afec_init(Afec *const afec, struct afec_config *config)
Initialize the AFEC Module.
Definition: afec.c:315
Autogenerated API include file for the Atmel Software Framework (ASF)
void afec_ch_set_config(Afec *const afec, const enum afec_channel_num channel, struct afec_ch_config *config)
Configure the AFEC channel.
Definition: afec.c:180


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:57