ADC - Analog data acquisition

The ADC block (or C++ routines) are used to access data from a given Analog-to-Digital Converter (ADC) channel. They also serve to configure how this data is sampled, filtered, and rescaled, prior to being used inside the application-level user code. Together, these parameters constitute the so-called software part of the ADC channel configuration, as opposed to the hardware part.

The hardware part, on the other hand, also requires some configuration, whose details depend on the controller model. The table below summarizes these differences and provides direct links to the associated user guides. Comparative information about imperix’s programmable controllers is also given in PN250.

Param.B-Box 4B-Box 3 RCPB-Box microB-Board 3 PRO
Resources– 24x 20Msps / 16bits
– ±10V ADC range
– 16x 500ksps / 16bits
– ±10V ADC range
– 8x 2Msps / 16bits
– ±5V ADC range
– 8x 2Msps / 16bits
– ±5V ADC range
HW param.– Safety limits
– Reaction speed
– Calibration [Y/N]
– Input impedance
– Safety limits
– Pre-ADC gain
– Low-pass filter
– Safety limitsN/A
SW param.– Low-pass filter
– Sampling method
– Scaling (gain+offset)
– Sampling method
– Scaling (gain+offset)
– Sampling method
– Scaling (gain+offset)
– Sampling method
– Scaling (gain+offset)
Doc. linkAI/AO config. AI config.AI config.N/A (HW-dependent)

Principles of operation

The sampling of all analog inputs is always conducted simultaneously, driven by SCLK, which is a simple derivative of CLK0, only differing by the SAMPLING_PHASE.

Both the freqency and the phase of the ADC sampling are defined from the CONFIG block. They set part of the overall timing configuration, which must be properly coordinated with modulation-related actions to guarantee the desired execution of the control algorithms. Notably, the two following options are possible:

  • Single-rate sampling, in which case the control task is executed once per PWM period. This is the default configuration used in most examples. 
  • Double-rate sampling, in which case the control task is executed twice per PWM period, requiring ADC sampling to be executed twice faster than the modulation. This case gives best performance, provided that sufficient CPU time is available. 
  • Advanced sampling configurations are also possible, typically authorizing to retrieve multiple samples at once (data history), variable-frequency switching, or running FPGA-based control tasks at a higher rate than the CPU. 

Frequency and phase aside, all other ADC parameters are individual, channel-specific settings that can be configured independently within each ADC block.

Block parameters

Addressing

  • Device ID selects which device to address when used in a multi-device configuration.
  • Input channel(s) (vectorizable) selects which physical input channel to read from.

Sensor specifications

  • The Sensor provides a list of imperix sensors. Selecting a sensor automatically populate the sensitivity parameter. When None is selected, the user must manually enter the sensitivity.
  • 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).
  • Output offset(s) (vectorizable) compensates for the sensor offset. It is expressed in Volts at the output of the sensor.

Input full scale

  • The Input full scale parameter can be set to
    • Maximum (device dependant)
    • Programmable (B-Box RCP 3.0 only)
  • The Programmable gain value can be set to 1x, 2x, 4x or 8x and must match the B-Box RCP 3.0 front panel setting.

Sampling

  • Synchronous averaging computes the average of multiple samples over a specific and synchronous time interval. The interval can be configured to 1 period of CLK0 or 2 periods of CLK0. This technique very effectively rejects high-frequency artifacts and is therefore enabled by default.
  • A Low-pass filter is available in B-Box 3 and 4, providing a more aggressive attenuation in the high-frequency range. The chosen filter cut-off frequency may however introduce a non-negligible group delay, which should be accounted for in the control algorithm (and, ideally, the selection of the sampling phase).
    For the B-Box RCP 3.0, the low-pass filter must be configured via the front panel, as explained in PN105.
  • Data history configures the block to output a vector of the N most recent ADC samples, which can be useful when the sampling frequency  FSCLK is larger than the CPU task frequency FCPU. The maximum history depth is 64 samples.
  • Simulate synchronous averaging / low-pass filter allows for a more accurate simulation, but it increases the simulation time.

Signal specification

  • The output signal returns a single-precision floating-point value representing the measured quantity in its physical unit (e.g. Volts, Amperes).
  • The sim input signal is used in simulation and documented in Simulation essentials with Simulink (PN135).
  • The > input signal needs to be connected to the CONFIG block in order to account for the exact sampling instant in simulation.

Mask

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).
  • The target inport (only visible at the atomic subsystem level) is used in simulation and documented in Simulation essentials with PLECS (PN137).
  • The > input signal needs to be connected to the CONFIG block to account for the exact sampling instant in simulation.
Analog data acquisition block PLECS

Mask

C++ functions

Standard functions

void Adc_ConfigureSensor(unsigned int input, float sensitivity, float offset, unsigned int device=0);Code language: C++ (cpp)

Enable and configure the desired ADC channel with the desired sensor sensitivity and offset, such as:

$\mathsf{AdcGetValue()\;return\;value} = \frac{1}{\mathtt{sensitivity}} \times \mathsf{analog\;input\;value} + \mathtt{offset}$.

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 23 on B-Box 4)
  • sensitivity: the sensor sensitivity in (V/unit)
  • offset: the offset (V)
  • device: the id of the addressed device (optional, used in multi-device configuration only)
float Adc_GetValue(unsigned int input, unsigned int device=0);Code language: C++ (cpp)

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 (e.g. 0 to 23 on B-Box 4)
  • device: the id of the addressed device (optional, used in multi-device configuration only)
void Adc_EnableSynchronousAveraging(unsigned int input, unsigned int device);Code language: C++ (cpp)

When enabled, Adc_GetValue returns the average ADC value over a period of CLK0.

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)

Advanced functions

void Adc_ConfigureHistory(unsigned int input, unsigned int depth, unsigned int device=0);Code language: C++ (cpp)

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);Code language: C++ (cpp)

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)

Legacy functions

Adc_ConfigureInput(unsigned int input, float gain, float offset, unsigned int device=0);Code language: C++ (cpp)

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 \(\mathsf{value}\mathsf{float} = \mathtt{gain} \times \mathsf{value}\mathsf{16bit} + \mathtt{offset}\).

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)

Example of use

This example considers the current sensor of a PEB8024 module. Its sensitivity is \(S=50.0\,[\text{mV/A}]\). As recommended in the datasheet, the chosen front-end gain is selected as \(G= 2\). Considering that the ADC offers 16 bits over the ±10V input range, this results in a total sensitivity \(\alpha = S\cdot G\cdot 32768/10=327.68\,[\text{bit/A}]\).

In this example, gain must therefore be equal to \(\mathtt{gain}=1/\alpha=3.052\,[\text{mA/bit}]\). The offset value can be adjusted empirically to cancel the measured value when no current is flowing through the sensor (static offset).

#define ADCONV (32768.0/10.0) // +/- 10V input range, 16-bit ADC
#define SENSITIVITY (0.05*2*ADCONV) // total sensitivity
#define I_GAIN (1.0/SENSITIVITY )
 
float I_meas = 0;
 
tUserSafe UserInit(void)
{
  Adc_ConfigureInput(0, I_GAIN, 0.0);
  return SAFE;
}
 
tUserSafe UserInterrupt(void)
{
  I_meas = Adc_GetValue(0);
  return SAFE;
}Code language: C++ (cpp)