Oversampling configuration and utilization
Table of Contents
In a standard configuration, the control algorithm is executed just after each sampling event. The oversampling feature enables the possibility to set up multiple sampling events between each control algorithm execution.
This note explains how to configure the sampling events and how to retrieve the oversampled values.
Configuration of the sampling events
We use the term “sampling events” instead of “sampling clock” because the delays between the sampling instants are not necessarily identical.
The sampling events are defined in one period of CLOCK_0 and repeated at each period. They consist of a collection of phases (from 0.0 to 1.0). Up to 64 of those events can be configured. Then one of these sampling events must be selected as the interrupt (containing control algorithm) starting point.
As shown below, once the code is loaded on the device, the configuration analysis can be performed graphically from the BB Control utility software. This scenario is taken as an example and does not have any particular application.


Oversampling configuration with ACG SDK
In the imperix library for Simulink, the sampling events are configured from the CONFIG block by setting an oversampling ratio. This spreads equidistant sampling events among the control period (starting from the main interrupt phase):


Alternatively, arbitrary sampling phases can be defined, as below:


In the latter case, a sampling event is automatically added at the beginning of the main interrupt if the interrupt phase is not part of the sampling event phases.
Oversampling configuration with C++ SDK
When using the C++ SDK, void Adc_AddSamplingEvent(float phase);
must be used in the UserInit(void)
function.
tUserSafe UserInit(void) {
// Sets CLOCK_0 at 50 kHz
Clock_SetFrequency(CLOCK_0, 50e3);
// Adds some sampling events
Adc_AddSamplingEvent(0.1);
Adc_AddSamplingEvent(0.45);
Adc_AddSamplingEvent(0.7);
Adc_AddSamplingEvent(0.8);
// Starts the interrupt after the sampling events performed at 0.45
ConfigureMainInterrupt(UserInterrupt, CLOCK_0, 0.45);
// some other code...
return SAFE;
}
Code language: C++ (cpp)
Retrieving the oversampled analog values
In its standard configuration, the ADC block or driver will only provide the last sampled value. To retrieve older values, the ADC history feature must be used.

Using ACG SDK
From the imperix library for Simulink or PLECS, the ADC history
can be enabled and then the quantity of value to retrieve is configured using the history depth
parameter. The ADC block will return a vector containing the values as shown below.




Using C++ SDK
When using the C++ SDK, Adc_ConfigureHistory
must be used in the UserInit(void)
to enable the ADC history and configure its depth. Then the Adc_GetHistory
can be used in the interrupt to get the older ADC values.
tUserSafe UserInit(void) {
// Sets CLOCK_0 at 50 kHz
Clock_SetFrequency(CLOCK_0, 50e3);
// Adds some sampling events
Adc_AddSamplingEvent(0.1);
Adc_AddSamplingEvent(0.45);
Adc_AddSamplingEvent(0.7);
Adc_AddSamplingEvent(0.8);
// Starts the interrupt after the sampling events performed at 0.45
ConfigureMainInterrupt(UserInterrupt, CLOCK_0, 0.45);
// Setup a history of 4 samples for ADC0
Adc_ConfigureHistory(ADC0, 4);
// some other code...
return SAFE
}
tUserSafe UserInit(void) {
float s0, s1, s2, s3;
s0 = Adc_GetHistory(ADC0, 0); // sample with index 0
s1 = Adc_GetHistory(ADC0, 1); // sample with index 1
s2 = Adc_GetHistory(ADC0, 2); // sample with index 2
s3 = Adc_GetHistory(ADC0, 3); // sample with index 3
return SAFE;
}
Code language: C++ (cpp)