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

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
suto_2664507
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

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;                            /*  */
    ADC_DelSig_1_StartConvert();
    ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT) ;
    //       if (ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_RETURN_STATUS)) {
    // ADCから電圧を取得。単位がmVなので、Vに変換するため1000.0で割る。その結果を変数voltに代入。
    // volt = ADC_DelSig_1_CountsTo_mVolts(ADC_DelSig_1_GetResult16()) / 1000.0;
    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  Raw=%5.3f[MPa] Average=%5.3f[MPa]\r\n", volt, pascal,avg-zero_offset);
    print(buf) ;
}

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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?

   // volt = ADC_DelSig_1_CountsTo_mVolts(ADC_DelSig_1_GetResult16()) / 1000.0;

moto

View solution in original post

0 Likes
2 Replies
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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?

   // volt = ADC_DelSig_1_CountsTo_mVolts(ADC_DelSig_1_GetResult16()) / 1000.0;

moto

0 Likes

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.

0 Likes