MP Type | ADC |
OS Type | Multi-Task AUTOSAR , etc |
Calculation accuracy | integer calculation |
Characteristic Conversion | linear conversion |
Filter | Non |
Diagnostics | SP Max/Min , CP Max/Min , MP Adc_ReadGroup fault |
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.00000053
// Interger constant
#define iInt_const 256U // Interger constant
// MPU definitions
#define iADC_bit 12U // MPU ADC bit 8/10/12
#define iADC_group 1U // ADC group
#define iADC_GrChNum 8U // Number channel in ADC group
#define iPIN_pos 7U // Sensor position in ADC group
// 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]
#define iVout_max 5000 // Vout Max [mV]
#define iVout_min 0 // Vout Min [mV]
#define iPhysical_max 100 // Physical Max [unit]
#define iPhysical_min 0 // Physical Min [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 sp2ap_t sp( cp2sp_t in )
{
sp2ap_t out = { iMP_Read , iNormal ,iNormal , iNormal , 0 };
cp2sp_t wk;
// Input buffering
wk = in;
if( ( wk.cp_stt == iMP_Read ) &&
( wk.cp_dia == iNormal ) &&
( wk.mp_dia == iNormal ) )
{
// Voltage value to Physical value conversion
out.phy = ( (sint32)wk.vi – iX_offset ) * iInt_const;
out.phy = mac_rnd( out.phy , iK_gain ) + iY_offset;
// Physical value Max or Min Diagnostics
out.sp_dia = lib_s32_MaxMin( &out.phy , iPhysical_max , iPhysical_min );
}
else
{
// Nothing to do
}
out.sp_stt = wk.cp_stt;
out.cp_dia = wk.cp_dia;
out.mp_dia = wk.mp_dia;
return( out );
}
void cpw( void )
{
VI_ECU = cp( AI );
}
static cp2sp_t cp( mp2cp_t in )
{
cp2sp_t out = { iMP_Read , iNormal , iNormal , 0U };
mp2cp_t wk;
// Input buffering
wk = in;
if( ( wk.mp_stt == iMP_Read ) &&
( wk.mp_dia == iNormal ) )
{
// A/D value to Voltage value conversion
out.vi = (uint16)mac_UpLmt( (uint32)wk.ai * iK_tc / iInt_const , iUint16_Max );
// Voltage value Max or Min Diagnostics
out.cp_dia = lib_u16_MaxMin( &out.vi , iVout_max , iVout_min );
}
else
{
// Nothing to do
}
out.cp_stt = wk.mp_stt;
out.mp_dia = wk.mp_dia;
return( out );
}
void mpw( void )
{
AI = mp();
}
static mp2cp_t mp( void )
{
mp2cp_t out = { iMP_Read , iNormal , 0U };
uint16 wk;
uint8 sts;
// Read A/D convension value
sts = adc_read_u16_wrapper( an , &wk );
// M-CAL judgment
if( sts != iNg ) // M-CAL normal
{
out.ai = wk;
out.mp_dia = iNormal;
out.mp_stt = iMP_Read;
}
else // M-CAL abnormal
{
out.mp_dia = iMPL_NG;
out.mp_stt = iError;
}
return( out );
}