iSensor-SPI-Buffer  1.15
Firmware for the iSensor-SPI-Buffer board to enable full throughput buffered data capture on Analog Devices IMUs
Functions | Variables
adc.c File Reference

Implementation file for iSensor-SPI-Buffer ADC module (for temp sensor and Vdd monitoring) More...

#include "reg.h"
#include "adc.h"
#include "main.h"
#include "stm32f3xx_hal.h"
#include "stm32f3xx_hal_conf.h"
Include dependency graph for adc.c:

Functions

static void ProcessTempReading ()
 Handle end of conversion for a temp sensor value. More...
 
static int16_t ScaleTempData (uint32_t rawTemp)
 Scale raw ADC temperature data to temp output. More...
 
static uint16_t GetVdd (uint32_t VrefMeasurement)
 Calculate Vdd from VREFINT measurement. More...
 
void ADC_Init ()
 ADC1 Initialization Function. More...
 
void ADC_Update ()
 Read and scale ADC values then load to output registers. More...
 

Variables

static ADC_HandleTypeDef hadc1
 

Detailed Description

Implementation file for iSensor-SPI-Buffer ADC module (for temp sensor and Vdd monitoring)

Copyright (c) Analog Devices Inc, 2020 All Rights Reserved.

Date
7/10/2020
Author
A. Nolan (alex..nosp@m.nola.nosp@m.n@ana.nosp@m.log..nosp@m.com)

Function Documentation

◆ ADC_Init()

void ADC_Init ( )

ADC1 Initialization Function.

Returns
None

This function should be called once as part of the firmware initialization process.

Initializes ADC1 in single sampling mode, with two input channels converted (temp sensor and VREFINT). The sample time is set to 601 ADC cycles. The ADC is clocked from 72MHz core clock divided by 8. 601 cycles / (72MHz/8) -> 66us. The Temp sensor requires a minimum 10us setting time for accurate measurements. Because these values are measured for diagnostics monitoring pursposes only, using a long sample time is not a problem.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADC_Update()

void ADC_Update ( )

Read and scale ADC values then load to output registers.

Returns
void

This function drives the ADC state machine and should be called periodically from the cyclic executive. The ADC is configured in non-continuous scanning mode, with the temp sensor and VREFINT channels enabled. For each channel, the state machine initiates an ADC sample, then goes to a wait state which does not advance until the EOC flag for that sample has been set. The VREFINT channel is sampled prior to the temp sensor channel, because the calculated Vdd value is used to compensate the temp sensor scale factor.

Here is the call graph for this function:

◆ GetVdd()

static uint16_t GetVdd ( uint32_t  VrefMeasurement)
static

Calculate Vdd from VREFINT measurement.

Returns
Vdd voltage (1V = 100LSBs)

VREFINT as a regulated ~1.23V supply generated by the STM32 processor core internally. The value of VREFINT with Vdd = 3.3V is logged by ST during production (stored in VREFINT_CAL). Theoretical value of 1501

In general, when an ADC measurement is performed, the ADC output = (2^12 - 1) * voltage / Vdd

so Vref (real voltage) = VREFINT_CAL * 3.3 / (2^12 - 1)

Therefore a measurement of the current Vref is equivalent to:

VrefMeasurement = (2^12 - 1) * (VREFINT_CAL * 3.3 / (2^12 - 1)) / Vdd VrefMeasurement = VREFINT_CAL * 3.3 / Vdd Vdd = VREFINT_CAL * 3.3 / VrefMeasurement

◆ ProcessTempReading()

static void ProcessTempReading ( )
static

Handle end of conversion for a temp sensor value.

This function reads the latest temp sensor output value and applies it to the temp sensor decimation averaging filter. If the end of a decimation period has been reached, it updates the temperature sensor output value and flags any temperature over range events in the STATUS register (outside -40C to 85C).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScaleTempData()

static int16_t ScaleTempData ( uint32_t  rawTemp)
static

Scale raw ADC temperature data to temp output.

Returns
temp value (10LSB = 1C)

Temp (in C, 10LSB per degree) = (800 / (TS_CAL2 - TS_CAL1)) * (val - TS_CAL1) + 300

The CAL values are measured with VREF = 3.3V at the factory. To make the measurement accurate, the most recent value read for VDD (using ADC VREFINT measurement) is used to normalize the raw temperature sensor measurement to a 3.3V reference voltage.

Here is the caller graph for this function:

Variable Documentation

◆ hadc1

ADC_HandleTypeDef hadc1
static

HAL ADC handle