MP Type | ADC |
OS Type | Multi-Task AUTOSAR , etc |
Calculation accuracy | integer calculation |
Characteristic Conversion | linear conversion |
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
main.c | application source code file |
pcmp.c | 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.00000051
// Interger constant
#define iInt_const 256U // Interger constant
// Filter definitons
#define iInt_EsfMax 65535U // Exponential Smoothing Factor in interger max value ( Corresponding to 1.0 )
#define iK_esf (uint16)( 0.75F*iInt_EsfMax ) // Exponential Smoothing Factor
// CAUTION: k is in the range of 0 to iInt_EsfMax ( Corresponding : 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 iX_offset 0 // X offset [mV]
#define iY_offset 0 // Y offset [unit]
#define iK_gain ( 1*iInt_const ) // Gain [mV/unit]
// Circuit definitions
#define iADC_vdd 5000U // MPU Vdd [mV]
#define iK_tc ( 1*iInt_const ) // Circuit Transformation ratio
void spw( void )
{
PHY = sp( VI );
}
static sint32 sp( uint16 vi )
{
sint32 wk = 0;
// Voltage value to Physical value conversion
wk = ( (sint32)vi – iX_offset ) * iInt_const;
wk = mac_rnd( wk , iK_gain ) + iY_offset;
// Physical value Exponential Moving Average calculation
wk = lib_s32_EMA( wk , &Phy_EMA );
return( wk );
}
void cpw( void )
{
VI_ECU = cp( AI );
}
static uint16 cp( uint16 ai )
{
// A/D value to Voltage value conversion
uint16 wk = (uint16)mac_UpLmt( (uint32)ai * iK_tc / iInt_const , iUint16_Max );
return( wk );
}
void mpw( void )
{
AI = mp();
}
static uint16 mp( void )
{
uint16 wk;
// Read A/D convension value
uint8 sts = adc_read_u16_wrapper( an , &wk );
return( wk );
}