HARMcksL: ARM HAL toolbox (yet STM32 oriented) 1.6
SMFSW collection of HAL hacks for STM32
Loading...
Searching...
No Matches
ADC_ex.c File Reference

Simple extension for ADCs. More...

#include "sarmfsw.h"
#include "ADC_ex.h"
Include dependency graph for ADC_ex.c:

Data Structures

struct  AnalogTab
 

Macros

#define Def_VBatFactor   (2.0f)
 2x factor
 
#define STM32_VREF_CAL   (VAL_AT(VREF_CAL_ADDR, uint16_t))
 VRef (ADC) calibration address content.
 
#define STM32_TS_CAL1   (VAL_AT(TS_CAL1_ADDR, uint16_t))
 Temp sensor ADC raw data acquired at Lower temperature address content.
 
#define STM32_TS_CAL2   (VAL_AT(TS_CAL2_ADDR, uint16_t))
 Temp sensor ADC raw data acquired at Higher temperature address content.
 
#define ADC_NB   1
 Number of ADC peripherals used.
 
#define ADC_NB_CHAN   2
 Number of ADC channels used (per peripheral)
 
#define TOTAL_ADC_CHANS   (ADC_NB * ADC_NB_CHAN)
 Total number of ADC channels.
 
#define ADC_SAMP_BUF_SIZE   4
 

Typedefs

typedef struct AnalogTab AnalogTab
 
typedef uint32_t DMA_sz_t
 Size of DMA buffer cells (1 cell per ADC value)
 

Functions

uint16_t ADC_GetRawVal (const eAnalogInput input)
 Get ADC channel raw value.
 
float ADC_GetConvertedVal (const eAnalogInput input)
 Get ADC channel converted value.
 
FctERR ADC_Start (void)
 Start ADC conversions.
 
FctERR ADC_Stop (void)
 Stop ADC conversions.
 
void HAL_ADC_ConvCpltCallback (ADC_HandleTypeDef *hadc)
 Conversion complete callback in non blocking mode.
 

Variables

const ADC_Cfg ADCConfig [Adc_MAX]
 

Detailed Description

Simple extension for ADCs.

Author
SMFSW

ADC_ex is meant to automate ADC conversions using DMA.

  • DMA must be configured for ADC peripherals:
    • Peripheral to Memory
    • Circular Mode
    • Increment Memory
    • Data width Word for both peripheral and memory
  • ADC configuration (no need to active ADC global interrupt, DMA will handle conversion complete callback):
    • Scan conversion mode across channels enabled
    • Continuous conversion is optional (as DMA continuous request handles the behavior)
    • DMA continuous request when available (if disabled, user has to start conversions manually when needed)
    • Interrupt generated at end of single conversion (to catch every sampled values)
      Note
      Define USE_ADC_EX symbol at project level to use ADC_ex functionalities
      Configuration done calling ADC_cfg.h file

Macro Definition Documentation

◆ ADC_NB

#define ADC_NB   1

Number of ADC peripherals used.

◆ ADC_NB_CHAN

#define ADC_NB_CHAN   2

Number of ADC channels used (per peripheral)

◆ ADC_SAMP_BUF_SIZE

#define ADC_SAMP_BUF_SIZE   4

Size of the input buffer per analog input

◆ Def_VBatFactor

#define Def_VBatFactor   (2.0f)

2x factor

◆ STM32_TS_CAL1

#define STM32_TS_CAL1   (VAL_AT(TS_CAL1_ADDR, uint16_t))

Temp sensor ADC raw data acquired at Lower temperature address content.

◆ STM32_TS_CAL2

#define STM32_TS_CAL2   (VAL_AT(TS_CAL2_ADDR, uint16_t))

Temp sensor ADC raw data acquired at Higher temperature address content.

◆ STM32_VREF_CAL

#define STM32_VREF_CAL   (VAL_AT(VREF_CAL_ADDR, uint16_t))

VRef (ADC) calibration address content.

◆ TOTAL_ADC_CHANS

#define TOTAL_ADC_CHANS   (ADC_NB * ADC_NB_CHAN)

Total number of ADC channels.

Typedef Documentation

◆ AnalogTab

typedef struct AnalogTab AnalogTab
Note
ADC_SAMP_BUFF_SIZE can be defined in adc_cfg.h, globals.h or at project level if higher amount of samples required

◆ DMA_sz_t

typedef uint32_t DMA_sz_t

Size of DMA buffer cells (1 cell per ADC value)

Function Documentation

◆ ADC_GetConvertedVal()

float ADC_GetConvertedVal ( const eAnalogInput input)

Get ADC channel converted value.

Parameters
[in]input- Input index
Returns
Channel converted value
Here is the call graph for this function:

◆ ADC_GetRawVal()

uint16_t ADC_GetRawVal ( const eAnalogInput input)

Get ADC channel raw value.

Parameters
[in]input- Input index
Returns
Channel raw value
Here is the caller graph for this function:

◆ ADC_Start()

FctERR ADC_Start ( void )

Start ADC conversions.

Returns
FctERR - Error code

◆ ADC_Stop()

FctERR ADC_Stop ( void )

Stop ADC conversions.

Returns
FctERR - Error code

◆ HAL_ADC_ConvCpltCallback()

void HAL_ADC_ConvCpltCallback ( ADC_HandleTypeDef * hadc)

Conversion complete callback in non blocking mode.

!

Strong Functions
Strong implementation of HAL_ADC_ConvCpltCallback in the library (will get precedence over HAL function)
Warning
If DMA used, same number of channels to convert have to be declared between ADCs for proper handling
Parameters
[in]hadc- ADC handle

Variable Documentation

◆ ADCConfig

const ADC_Cfg ADCConfig[Adc_MAX]
extern