Paparazzi UAS  v5.18.0_stable
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_BUF_DEPTH   (MAX_AV_NB_SAMPLE/2)
 

Functions

static IN_DMA_SECTION (adcsample_t adc_samples[ADC_NUM_CHANNELS *ADC_BUF_DEPTH])
 
static void adc_regular_sequence (uint32_t *sqr1, uint32_t *sqr2, uint32_t *sqr3, uint8_t length, const uint8_t channel[])
 
static void adc_sample_time_on_all_channels (uint32_t *smpr1, uint32_t *smpr2, uint8_t time)
 
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]
 #endif More...
 
uint8_t adc_error_flag = 0
 
ADCDriver * adcp_err = NULL
 
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]
 
static ADCConversionGroup adcgrpcfg
 Configuration structure must be global. More...
 

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 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 144 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 subsystems 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 224 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, channel, 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 289 of file adc_arch.c.

Referenced by adc_generic_init(), airspeed_adc_init(), aoa_adc_init(), baro_init(), electrical_init(), glide_wing_lock_init(), humid_hih_init(), imu_analog_init(), infrared_adc_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_init()

void adc_init ( void  )

Adc init.

Starts conversions.

Initialize ADC drivers, buffers and start conversion in the background

Definition at line 312 of file adc_arch.c.

Referenced by mcu_init().

+ Here is the caller graph for this function:

◆ adc_regular_sequence()

static void adc_regular_sequence ( uint32_t sqr1,
uint32_t sqr2,
uint32_t sqr3,
uint8_t  length,
const uint8_t  channel[] 
)
static

Definition at line 171 of file adc_arch.c.

References channel.

Referenced by adc_init().

+ Here is the caller graph for this function:

◆ adc_sample_time_on_all_channels()

static void adc_sample_time_on_all_channels ( uint32_t smpr1,
uint32_t smpr2,
uint8_t  time 
)
static

Definition at line 195 of file adc_arch.c.

Referenced by adc_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 278 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 *ADC_BUF_DEPTH])
static

Variable Documentation

◆ adc1_buffers

struct adc_buf* adc1_buffers[ADC_NUM_CHANNELS]
static

Definition at line 149 of file adc_arch.c.

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

◆ adc1_samples_tmp

uint8_t adc1_samples_tmp[ADC_NUM_CHANNELS]
static

Definition at line 151 of file adc_arch.c.

Referenced by adc1callback().

◆ adc1_sum_tmp

uint32_t adc1_sum_tmp[ADC_NUM_CHANNELS]
static

Definition at line 150 of file adc_arch.c.

Referenced by adc1callback().

◆ adc_channel_map

const uint8_t adc_channel_map[ADC_NUM_CHANNELS]
static

#endif

Definition at line 87 of file adc_arch.c.

Referenced by adc_init().

◆ adc_error_flag

uint8_t adc_error_flag = 0

Definition at line 138 of file adc_arch.c.

Referenced by adcerrorcallback().

◆ adcgrpcfg

ADCConversionGroup adcgrpcfg
static

Configuration structure must be global.

Definition at line 305 of file adc_arch.c.

Referenced by adc_init().

◆ adcp_err

ADCDriver* adcp_err = NULL

Definition at line 139 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:289
adc_buf
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53