Go to start of banner

# General description

The ADC block is used to retrieve the measurements from an analog input of the B-Box or B-Board.

This help documentation deals with the software part of the analog data acquisition. To set-up the hardware part, please refer to the following documents:

Note on sampling: The sampling instant is the same for all the analog inputs, across all devices (when in a multi-devices configuration). The sampling is, by design, linked to the same clock generator as the interrupt and is configured using the CONFIG block. See CONFIG - Interrupt configuration to learn more.

# Signal specification

• The output signal returns a single-precision floating-point value representing the measured quantity in its physical unit (e.g. Volts, Amperes). When use ADC history is selected, it returns a vector of the N last values, as documented in PN154: Oversampling.

• The sim input signal is used in simulation and documented in PN135: Simulation essentials with Simulink.

• The > input signal needs to be connected to the CONFIG block in order to account for the exact sampling instant in simulation.

## Standard parameters

• Device ID selects which B-Box/B-Board to address when used in a multi-device configuration.

• Input channel selects which physical input channel to read from (e.g. 0 to 15 on B-Box RCP).

• Quick configuration loads the parameters of an imperix sensor.

• Sensor sensitivity is the sensor sensitivity in Volts per measured unit (e.g. V/V for a voltage sensor and V/A for a current sensor).

• Sensor output offset compensates for the sensor offset. It is expressed in Volts at the output of the sensor.

• Programmable gain value must match the configuration set on the frontpanel of the B-Box.

• Match B-Board input full-scale must be checked if the device is a B-Board PRO. It forces the programmable analog gain to x2, to account for the +/- 5V input full-scale of the B-Board PRO (as opposed to +/- 10V on the B-Box RCP).

• Use ADC history enables the possibility the retrieve the N last sampled values.

• History depth (samples) is the number N of values to retrieve.

To see how to set up an oversampling (multiple sampling instants at each interrupt) please refer to the CONFIG - interrupt configuration page.

PLECS block

# Signal specification

• The output signal returns a single-precision floating-point value representing the measured quantity in its physical unit (e.g. Volts, Amperes). When ADC history is enabled, it returns a vector of the N last values, as documented in PN154: Oversampling.

• The target inport (only visible at the atomic subsystem level) is used in simulation and documented in PN137: Simulation essentials with PLECS.

• The > input signal needs to be connected to the CONFIG block to account for the exact sampling instant in simulation.

## Standard parameters

• Device ID selects which B-Box/B-Board to address when used in a multi-device configuration.

• Input channel (vectorizable) selects which physical input channel to read from (e.g. 0 to 15 on B-Box RCP).

• Use/load sensor parameters loads the  parameters of an imperix sensor.

• Sensor sensitivity (vectorizable) is the sensor sensitivity in Volts per measured unit (e.g. V/V for a voltage sensor and V/A for a current sensor).

• Sensor output offset (vectorizable) compensates for the sensor offset. It is expressed in Volts at the output of the sensor.

• Programmable gain value must match the configuration set on the frontpanel of the B-Box RCP. If the device is a B-Board PRO, it must be set to x2, to account for the +/- 5V input full-scale of the B-Board PRO (as opposed to +/- 10V on the B-Box RCP).

• Use ADC history enables the possibility the retrieve the N last sampled values.

• History depth (samples) is the number N of values to retrieve.

To see how to set up an oversampling (multiple sampling instants at each interrupt) please refer to the CONFIG - interrupt configuration page.

# C++ functions

The sampling is by design linked to the same clock generator as the interrupt, thus the sampling frequency and phase are configured using the ConfigureMainInterrupt function as explained in the related note: Interrupt configuration.

## Standard functions

void Adc_ConfigureInput(unsigned int input, float gain, float offset,
unsigned int device=0);

Configures the desired ADC channel with the desired gain and offset that is applied on the 16-bit digitally-converted value to obtain a floating-point quantity such as: $//$

It has to be called in UserInit() for each channel that the user wants to use.

### Parameters

• input: the analog input channel number (e.g. 0 to 15 on B-Box RCP)

• gain: the gain applied on the 16-bit digitally-converted value

• offset: the offset applied to the returned value

• device: the id of the addressed device (optional, used in multi-device configuration only)

The gain is not equal to the sensor sensitivity. The example of use section below shows how to compute the gain and offset parameters.

float Adc_GetValue(unsigned int input, unsigned int device=0);

Retrieves the value of an ADC channel, with the gain and offset already applied.

It has to be called in the interrupt.

### Parameters

• input: the analog input channel number (0 to 15)

• device: the id of the addressed device (optional, used in multi-device configuration only)

void Adc_AddSamplingEvent(float phase);

It enables the possibility to set up an oversampling by selecting multiple sampling instant per interrupt.

It has to be called in UserInit().

### Parameters

• phase: sampling phase with respect to the CLOCK associated to the interrupt.

void Adc_ConfigureHistory(unsigned int input, unsigned int depth, unsigned int device=0);

Enables the possibility to have access to the N last ADC samples using Adc_GetHistory().

It has to be called in UserInit().

### Parameters

• input: the analog input channel number

• depth: the number of samples available

• device: the id of the addressed device (optional, used in multi-device configuration only)

float Adc_GetHistory(unsigned int input, unsigned int n, unsigned int device=0);

Gets the Nth historical sample of a given ADC channel.

Using Adc_GetHistory(n=0) is equivalent to using Adc_GetValue().

It has to be called during the control interrupt.

### Parameters

• input: the analog input channel number (0 to 15)

• n: the historical index of the sample to read (0 is the most recent one)

• device: the id of the addressed device (optional, used in multi-device configuration only)

Example of use

For the sake of this example, we recompute the necessary ADC gain. However, the gains for imperix standard sensors and power modules are already defined in sensors.h

This example considers the current sensor of a PEB8024 module. Its sensitivity is $//$. As recommended in the datasheet, the chosen front-end gain is selected as $//$. Considering that the ADC offers 16 bits over the ±10V input range, this results in a total sensitivity $//$.

In this example, gain must therefore be equal to $//$. The offset value can be adjusted empirically to cancel the measured value when no current is flowing through the sensor (static offset).

#define ADCONV (10.0/32768.0) // +/- 10V input range, 16-bit ADC
#define SENSITIVITY (50*2*ADCONV) // total sensitivity
#define V_GAIN (1/SENSITIVITY) //

float Vdc = 0;

tUserSafe UserInit(void)
{
}