MP Type | ADC |
OS Type | Multi-Thread Mbed , etc |
Calculation accuracy | floating-point calculation |
Characteristic Conversion | Non-linear conversion(Two-dimensional table method) |
Filter | Exponential Moving Average ( EMA ) |
Diagnostics | Non |
Software Specifications

Caution)
Please note that the return value of the Mbed read_u16 function may be MSB-padded or LSB-packed. The adc_read_u16_wrapper function assumes LSB packing.
File ( Mbed C++)
main.cpp | application source code file |
pcmp.cpp | ADC Component source code file |
pcmp.h | ADC Component header file |
oss-ec.h | OSS-EC header file |
Source Code
- Constants for components Constants to match the component
- Constants for MPU Constants to match the microcontroller of the product
- Constants for circuits Constants to match the circuit of the product
// BCL No.00000011
// Filter definitions
#define iK_esf 0.5F // Exponential Smoothing Factor
// CAUTION : k is in the range of 0 to 1.0
// MPU definitions
#define iADC_bit 16U // MPU ADC bit
// CAUTION : When Mbed is selected, 16 bit is fixed
#define iPIN_adc A0 // MPU Port Pin (ADC)
// P-CMP ( Sysyem Parts , Circuit , IC ) definitions
// Model type System Parts definitions
#define iData_num 5U // Number of characteristic table elements
const float32 Data_x[iData_num] = // X axis for table search : Voltage [V]
{
0.0F , 0.5F , 1.0F , 1.5F , 2.0F // X data
};
const float32 Data_y[iData_num] = // Y axis for table search : Physical [unit]
{
10.0F , 15.0F , 30.0F , 50.0F , 100.0F // Y data
};
// Circuit definitions
#define iADC_vdd 3.3F // MPU Vdd [V]
#define iK_tc 1.0F // Circuit Transformation ratio
float32 Phy_Read( void )
{
return( pcmp() );
}
static float32 pcmp( void )
{
uint16 ai = mp(); // A/D value read
float32 vi = cp( ai ); // A/D value to Voltage value conversion
float32 phy = sp( vi ); // Voltage value to Physical value conversion
return( phy );
}
static float32 sp( float32 vi )
{
// Voltage value to Physical value conversion
float32 wk = lib_f32_Tbl2D( vi , &Tbl );
// Physical value Exponential Moving Averages calculation
wk = lib_f32_EMA( wk , &Phy_EMA );
return( wk );
}
static float32 cp( uint16 ai )
{
// A/D value to Voltage value conversion
float32 wk = (float32)ai * iADC_vdd / ( 1<<iADC_bit ) * iK_tc;
return( wk );
}
static uint16 mp( void )
{
uint16 wk;
// Read A/D convension value
uint8 sts = adc_read_u16_wrapper( an , &wk );
return( wk );
}