Go Down

Topic: ADC CALIBRATION - NEED HELP PLS (Read 928 times) previous topic - next topic

Daniel Formosa

Dear all, I am designing an automated refrigirated system for car a/cs...

The user just places a gas cylinder on my load cell and then inputs the amount wanted (for example 500g using a keypad).

My problem is this:
I made an experimet, by placing the tank (empty) on the load cell, took its voltage o/p;i.e. entering ADC and succesfully monirtored the voltages by increasing 1kg, 1kg, 1kg, 1kg..to 20kgs(full cylinder)..
and monitored the ADC value (bit).  And came up with this table:

ADC10BIT   GRAMS
377   7585
400   8073
447   9073
494   10073
541   11073
587   12073
633   13073
680   14073
708   14673
727   15073
755   15673
800   16673
847   17673
893   18673
939   19673
986   20673
   
After I made a program to calibrate it accurately
Code: [Select]
#include <LiquidCrystal.h>
//#include <math.h>
#define powf

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
const int analogInPin = A0;
int count = 300;


double pow (double __x, double __y);

void setup()
{
  lcd.begin(16,2);                              //initialise LCD
  Serial.begin(9600);
  setupA();
}

void loop()
{
}


void setupA()
{
  lcd.print("TESTING");                //display on lcd
   delay(2000);
   digitalWrite(13,LOW);                  //RELAY CLOSED
   read_average_analog(250);            //NOTE ORIGNAL 250
}


/* Sample analog in pin a given number of times and
* return the floating point mean of the samples.
* The summing of samples is done using a long, which
* is subject to overflow for very large counts.
*/
double read_average_analog(int count)
{
  int i;
  long sum = 0;
  float average;
  float voltage;
  float conversiontogas;
  int gas_before;
  float calibration;


 
    sum = 0;
    for (i = 0; i < count; i++)
    {
        sum += analogRead(analogInPin);
        Serial.print(sum, 3);
        Serial.print("\n");
    }
     
   average = ((sum)/(count));
   int conv_average = average;
   //voltage = average*(0.00469592);
   Serial.print("A");
   Serial.println(average +4, 3);
   //Serial.println(voltage, 3);
   
   //calibration = ((average)*(21.8115942) - (611.1594203));
   
      if((conv_average >= 371) && (conv_average <= 400))
      {
         calibration = ((conv_average)*(21.217) - (413.96));
       
      }
       else if((conv_average > 400) && (conv_average <= 541))
      {
         calibration = ((conv_average + 4)*(21.277) - (437.64));
       
      }
      else if((conv_average > 541) && (conv_average <= 633))
      {
         calibration = ((conv_average)*(21.739) - (687.87));
       
      }
      else if((conv_average > 633) && (conv_average <= 680))
      {
         calibration = ((conv_average)*(21.277) - (395.09));
       
      }
      else if((conv_average > 680) && (conv_average <= 708))
      {
         calibration = ((conv_average)*(21.429) - (498.43));
       
      }
      else if((conv_average > 708) && (conv_average <= 727))
      {
         calibration = ((conv_average)*(21.053) - (232.26));
       
      }
       else if((conv_average > 727) && (conv_average <= 755))
      {
         calibration = ((conv_average)*(21.429) - (505.57));
       
      }
       else if((conv_average > 755) && (conv_average <= 800))
      {
         calibration = ((conv_average)*(22.222) - (1104.8));
       
      }
       else if((conv_average > 800) && (conv_average <= 847))
      {
         calibration = ((conv_average)*(21.277) - (348.28));
       
      }
       else if((conv_average > 847) && (conv_average <= 939))
      {
         calibration = ((conv_average)*(21.739) - (740.04));
       
      }
      else if((conv_average > 939) && (conv_average <= 986))
      {
         calibration = ((conv_average)*(21.277) - (305.72));
       
      }
       Serial.println(calibration);
       
       
   gas_before = calibration; 
  lcd.setCursor(0, 1);
  lcd.print(gas_before);   
   delay(100);

  Serial.println(gas_before);
 
   
   
       
 
  return gas_before;
}


Note the equations are all graphs between the values.

With this it all worked perfectly.

Now, I switch off the system, and switch it on again the next day and none of these values are the same.  They changed and not linearly.

What can I do to calibrate the system automatically.
Pls help, I ve been on the same thing for a long time now.
tnx

Daniel Formosa

Thwe graph is attached...It looks linear but I cant affort to put a linear approximation. 

An error of +/- 20grams is ok...
My cct consists of:
Power supply- PSU. (PC power supply giving a stable voltage)
Opamp cct - Using a high cost opamp so that in temp changes the offsset is low.  TCP750CPA oapmp
Load cell- Bought one about 80euros
Quote
f you simply multiply the ADC value by 20.5


Hows that?

I think its due to temp, since when putting the gas tank empty on the load cell, at exactly the same position, somethimes it gives 1.776V and somethimes 1.778 or 1.774V
I thin that is the prob...Do you know if i can cater for it in code?

tnx


Daniel Formosa

Graph sry..

Daniel Formosa

The load cell, inbuilt has a wheatstone bridge...and I used a Difrferntial Opamp amplifier so the circuitry should be fine...

Daniel Formosa

I made an experiment to compare the voltage o/p to the lioad on the load cell, an it gave a linear amplification.

How can i calibrate the system when it switches on.  I was thinking, when switching on withoud no load is on the loadcell, the adc takes an average of the voltage there at that time. 

When I took those readings, I took it and the adc displayed 27.  Therefore if i switch on the system and the no aint 27, I will increase or deacrease it until it is 27, and then put it to the equation ; polynomial where x will be increased or decreased;

e.g
y = 0.00032074x2 + 21.08194941x - 413.72455934

where x is the ADC value;

what do you thinkk?
tnx

Daniel Formosa

Yes, yes they did....ehh i really dont know what to do

Go Up