Paparazzi UAS  v6.2_unstable
Paparazzi is a free software Unmanned Aircraft System.
adc_arch.c File Reference
#include "mcu_periph/adc.h"
#include "mcu_periph/gpio.h"
#include "hal.h"
#include "std.h"
#include "mcu_periph/ram_arch.h"
+ Include dependency graph for adc_arch.c:

Go to the source code of this file.

Macros

#define USE_AD1   1
 
#define ADC_SAMPLE_RATE   ADC_SAMPLE_480
 #endif More...
 
#define ADC_BUF_DEPTH   (MAX_AV_NB_SAMPLE/2)
 

Functions

static IN_DMA_SECTION (adcsample_t adc_samples[ADC_NUM_CHANNELS *MAX_AV_NB_SAMPLE])
 
static void adc_configure (ADCConversionGroup *cfg, uint8_t num_channels, const uint8_t channels[], uint32_t sample_rate, adccallback_t end_cb, adcerrorcallback_t error_cb)
 Configure the ADC conversion group depending on the architecture. More...
 
void adc1callback (ADCDriver *adcp)
 Adc1 callback. More...
 
static void adcerrorcallback (ADCDriver *adcp, adcerror_t err)
 Adc error callback. More...
 
void adc_buf_channel (uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
 Link between ChibiOS ADC drivers and Paparazzi adc_buffers. More...
 
void adc_init (void)
 Adc init. More...
 

Variables

static const uint8_t adc_channel_map [ADC_NUM_CHANNELS]
 
uint8_t adc_error_flag = 0
 
ADCDriver * adcp_err = NULL
 
static ADCConversionGroup adc1_group
 
static struct adc_bufadc1_buffers [ADC_NUM_CHANNELS]
 
static uint32_t adc1_sum_tmp [ADC_NUM_CHANNELS]
 
static uint8_t adc1_samples_tmp [ADC_NUM_CHANNELS]
 

Detailed Description

ADC driver

ADC defines for Lia board (STM32F105) 5 Channels: 1 - ADC1, Channel 13 2 - ADC2, Channel 10 3 - ADC3, Channel 11 4 - ADC4, Channel 14 5 - Temperature sensor, Channel 16

Default buffer depth is equal to MAX_AV_NB_SAMPLE This allows us to always have more or equal samples than the user requires

Note
: With ChibiOS/RT 2.6.2 and STM32F105 chip the channels have to be interleaved, otherwise the current measurement is affected by the previous channel measured. Most likely bug on ChibiOS ADC driver for this particular chip.

For 5 actual channels we have to define (DUMMY stants for 1 dummy channel): CH1 + DUMMY + CH2 + DUMMY + CH3 + DUMMY + CH4 + DUMMY + CH_TEMP = 9 channels Then only every second channel is really read. Might be fixed in next version of ChibiOS

V_ref is 3.3V, ADC has 12bit or 16bit resolution.

Definition in file adc_arch.c.

Macro Definition Documentation

◆ ADC_BUF_DEPTH

#define ADC_BUF_DEPTH   (MAX_AV_NB_SAMPLE/2)

Definition at line 138 of file adc_arch.c.

◆ ADC_SAMPLE_RATE

#define ADC_SAMPLE_RATE   ADC_SAMPLE_480

#endif

Definition at line 76 of file adc_arch.c.

◆ USE_AD1

#define USE_AD1   1

Definition at line 64 of file adc_arch.c.

Function Documentation

◆ adc1callback()

void adc1callback ( ADCDriver *  adcp)

Adc1 callback.

Callback, fired after half of the buffer is filled (i.e. half of the samples is collected). Since we are assuming continuous ADC conversion, the ADC state is never equal to ADC_COMPLETE.

Note
Averaging is done when the modules ask for ADC values
Parameters
[in]adcppointer to a ADCDriver object
[in]bufferpointer to a buffer with samples
[in]nnumber of samples

Definition at line 243 of file adc_arch.c.

References adc1_buffers, adc1_samples_tmp, adc1_sum_tmp, ADC_BUF_DEPTH, ADC_NUM_CHANNELS, adc_buf::av_nb_sample, and adc_buf::sum.

Referenced by adc_init().

+ Here is the caller graph for this function:

◆ adc_buf_channel()

void adc_buf_channel ( uint8_t  adc_channel,
struct adc_buf s,
uint8_t  av_nb_sample 
)

Link between ChibiOS ADC drivers and Paparazzi adc_buffers.

Registers a buffer to be used to store the specified converted channel
Usage:
struct adc_buf channel_buf;
adc_buf_channel(1, &channel_buf, 12);

Registers channel_buf as buffer for ADC channel 1, with max index 12 (12 samples).

Definition at line 312 of file adc_arch.c.

Referenced by adc_generic_init(), airspeed_adc_init(), aoa_adc_init(), electrical_init(), glide_wing_lock_init(), humid_hih_init(), light_solar_init(), light_temt_init(), mf_ptu_init(), sonar_adc_init(), temp_adc_init(), and temp_tcouple_adc_init().

+ Here is the caller graph for this function:

◆ adc_configure()

static void adc_configure ( ADCConversionGroup *  cfg,
uint8_t  num_channels,
const uint8_t  channels[],
uint32_t  sample_rate,
adccallback_t  end_cb,
adcerrorcallback_t  error_cb 
)
static

Configure the ADC conversion group depending on the architecture.

Parameters
cfgThe configuration to be set
num_channelsThe number of channels in the ADC
channelsThe channel mapping to real channels
sample_rateThe sample rate for all channels
end_cbThe callback function at the end of conversion
error_cbThe callback function whenever an error occurs

Definition at line 175 of file adc_arch.c.

References error_cb.

Referenced by adc_init().

+ Here is the caller graph for this function:

◆ adc_init()

void adc_init ( void  )

Adc init.

Starts conversions.

Initialize ADC drivers, buffers and start conversion in the background

Definition at line 332 of file adc_arch.c.

Referenced by mcu_init().

+ Here is the caller graph for this function:

◆ adcerrorcallback()

static void adcerrorcallback ( ADCDriver *  adcp,
adcerror_t  err 
)
static

Adc error callback.

Fired if DMA error happens or ADC overflows

Definition at line 301 of file adc_arch.c.

References adc_error_flag, and adcp_err.

Referenced by adc_init().

+ Here is the caller graph for this function:

◆ IN_DMA_SECTION()

static IN_DMA_SECTION ( adcsample_t  adc_samples[ADC_NUM_CHANNELS *MAX_AV_NB_SAMPLE])
static

Variable Documentation

◆ adc1_buffers

struct adc_buf* adc1_buffers[ADC_NUM_CHANNELS]
static

Definition at line 144 of file adc_arch.c.

Referenced by adc1callback(), adc_buf_channel(), and adc_init().

◆ adc1_group

ADCConversionGroup adc1_group
static

Definition at line 143 of file adc_arch.c.

Referenced by adc_init().

◆ adc1_samples_tmp

uint8_t adc1_samples_tmp[ADC_NUM_CHANNELS]
static

Definition at line 146 of file adc_arch.c.

Referenced by adc1callback().

◆ adc1_sum_tmp

uint32_t adc1_sum_tmp[ADC_NUM_CHANNELS]
static

Definition at line 145 of file adc_arch.c.

Referenced by adc1callback().

◆ adc_channel_map

const uint8_t adc_channel_map[ADC_NUM_CHANNELS]
static

Definition at line 81 of file adc_arch.c.

Referenced by adc_init().

◆ adc_error_flag

uint8_t adc_error_flag = 0

Definition at line 132 of file adc_arch.c.

Referenced by adcerrorcallback().

◆ adcp_err

ADCDriver* adcp_err = NULL

Definition at line 133 of file adc_arch.c.

Referenced by adcerrorcallback().

adc_buf_channel
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Link between ChibiOS ADC drivers and Paparazzi adc_buffers.
Definition: adc_arch.c:312
adc_buf
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53