2 Replies Latest reply on Jun 16, 2019 8:57 PM by suto_2664507

# PSoC5LP:How to match the analog input value to the ADC value?

At the analog input, when vin_A = 0.80 V, when the value of ADC is 0.90 V and Vin = 1.00 V, the value of ADC is output as 1.121 V.
Although the output voltage of the ADC is converted to a pressure display, naturally, a shift occurs.
I used Cypress's sample code, but I would like to point out and give advice on where the problem lies.

void measure_pressure(void)
{
static uint8_t initialFlag = 1;                            /*  */
volt = (ADC_DelSig_1_CountsTo_mVolts(ADC_DelSig_1_GetResult16()) + 100.0) / 1000.0 ;

// 0.8～4.0の値を、0.0～5.0の範囲に線形変換する。その結果を変数pascalに代入。
pascal = lerp(0.8, 4.0, 0.0, 5.0, volt);

if (initialFlag) {
// 初回のみ、平均値（移動平均）を直接セットする。そうしないと、起動直後に0.0からゆっくり変化してしまってよくない。
setAvg(pascal);
initialFlag = 0;
}

// 平均値（移動平均）を更新。平均値は、上のほうで定義している変数avgとに代入される。
updateAvg(pascal);

pressure = pres_ramp * avg + pres_bias ;
}

void report_pressure(void)
{
// UARTへデバッグ出力
sprintf(buf, "ADC=%5.3f[V]  Raw=%5.3f[MPa] Average=%5.3f[MPa]\r\n", volt, pascal,avg-zero_offset);
print(buf) ;
}

• ###### 1. Re: PSoC5LP:How to match the analog input value to the ADC value?

Hi,

Assuming ADC_DelSig_1_GetResult16() is returning a right value, adding 100.0 make 0.80V to 0.90V.

> volt = (ADC_DelSig_1_CountsTo_mVolts(ADC_DelSig_1_GetResult16()) + 100.0) / 1000.0 ;

How about use the commented line?

moto

• ###### 2. Re: PSoC5LP:How to match the analog input value to the ADC value?

Originally,
volt = ADC_DelSig_1_CountsTo_mVolts (ADC_DelSig_1_GetResult16 ()) / 1000.0;
However, +100 was being added in the meantime.

After removing +100 and building again, the analog input value and the ADC value are equal.

This part was solved.
Thank you.
There are still three other places to rework.