Powered by Invision Power Board


Forum Rules Forum Rules (Please read before posting)
  Reply to this topicStart new topicStart Poll

> Adc0808 Channel Interfarance Problem., urgent help required
Qaisar Azeemi
  Posted: March 24, 2012 02:00 pm
Reply to this postQuote Post


Newbie
**

Group: Members+
Posts: 46
Member No.: 36,124
Joined: November 17, 2011




hi friends,

i am getting 3 analog signals at the inputs of ADC0808 and i am displaying it on LCD. they are voltage current and temperature signals. the problem is that when i vary one of the analog input it also effects the data from other inputs. that is if i vary voltage it resutls in the variation of voltage data, current data and temprature data on tha Screen of LCD. i tried my best to isolate it from each other by putting delays and clearing the arrays and data memory locations but the problem is as it is... please help me to rectify my problem...

following is my code:

CODE

#include <reg52.h>


#define select P3
#define Port P2  // control port
#define adc_input P1
#define data_port P0  // data from microcontroller to LCD
#define sec 50
#define scan 10

sbit ADC_A=Port^0; //ADC
sbit ADC_B=Port^1; //ADC
sbit RS=Port^7;    //LCD
sbit E=Port^5;     //LCD
sbit ctl=Port^6;    //LCD
sbit SC=Port^4;   //ADC
sbit CLK=Port^3;  //ADC
sbit ALE=Port^2;  //ADC

sbit v28=select^4; // carger 28v selected
sbit v14=select^5;
sbit v7=select^6;
sbit off=select^7;
sbit intr=select^2;
sbit c28=select^0;
sbit c14=select^1;
sbit c7=select^3;

unsigned int test_intermediate3=0, test_final=0, select_mem=0, x=0;
unsigned int test_intermediate1[scan], test_intermediate2[3]={0,0,0};
unsigned char temp[]={"Temp:  "}, vna[]={" Volt:    Amp:  "},  hnm[]={"  hr   min     %"}, bnc[]={"Backup:  %Charge"};


  //------------------- . --------------------------

 void delay(unsigned int msec)
 {
  int i,j;
  for(i=0; i==msec; i++)
   for(j=0; j==1275; j++);

 }

//...........;;;;;;;;;;..........................
 
 void long_delay(unsigned int second)
 {
    int i,j;
    for (j=0; j<second; j++)
      for (i=0; i<0xffff; i++);
 }




 //---------------- timer 0 interrupt----------------

 void timer0() interrupt 1
 {
     
    CLK=~CLK;  // Toggle port bit p3.5
    TR0=0;         // stop timer
    TH0=0xff;     // 500hz clock for adc
    TL0=0xff;
    TR0=1;   // start timer
 }

    //;;;;;;;;;;;;;;;;;;;;;;;;;;;

  void switch2(void)
 {
   if (v7==1 & v14==0 & v28==0)
  {
   c7=1; c14=0; c28=0;
  }

 else
 if(v14==1 & v7==0 & v28==0)
  {
   c14=1; c7=0; c28=0;
  }
 else
 if (v28==1 & v7==0 & v14==0)
  {
   c28=1; c14=0; c7=0;
  }        



}
 
   //---------------- External 0 interrupt----------------

 void switching() interrupt 0
    {
     
        intr=1;
     delay(sec*4);
         select = select_mem;
      intr=1;
       delay(sec*4);
     
     // ...............---------........................


        if(v28==0 & v14==0 & v7==0 & off==1)
         { off=0; v7=1; v28=0; v14=0; }
   
       else
                       if(v28==0 & v14==0 & v7==1 & off==0)  //e1
                               { v7=0; v14=1; v28=0; off=0; }
   
    else
     if(v28==0 & v14==1 & v7==0 & off==0)   //e2
             { v14=0; v28=1; v7=0;  off=0; }
   
    else
     if(v28==1 & v14==0 & v7==0 & off==0)   //e3
          { v28=0; v14=0; v7=0; off=1; }
             
               
   
   delay(sec*4);        
   intr=1;
   c7=0; c14=0; c28=0;
   delay(sec*4);
      select_mem = select;
 

   long_delay(10);
    switch2();

 }




 //.................. LCD .................


 void lcd_cmd( unsigned int item )
 {
  data_port=item;  //command on data port p0 of lcd
  RS=0;            // selecting command register of lcd
 // RW=0;
  E=1;
  delay(1);
  E=0;
                       
 }




 void lcd_data( unsigned int item )
 {
  data_port=item;  //data on data port p0 of lcd
  RS=1;            // selecting data register of lcd
 // RW=0;
  E=1;
  delay(1);
  E=0;
 
 }










  //----------- custom character Generation for Degree symbol-----------

  void shape()
  {
   
  lcd_cmd(64);   // first location in CGRAM
  delay(sec);
  lcd_data(2);
  delay(sec);
  lcd_data(5);
  delay(sec);
  lcd_data(2);
  delay(sec);
  lcd_data(0);
  delay(sec);
  lcd_data(0);
  delay(sec);
  lcd_data(0);
  delay(sec);
  lcd_data(0);
  delay(sec);
  lcd_data(0);
  delay(sec);

 
  }


  //-------------------- for volt symbol-----------------

   void shape2()
  {
   
  lcd_cmd(72);   // second location in CGRAM
  delay(sec);
  lcd_data(0);
  delay(sec);
  lcd_data(0);
  delay(sec);
  lcd_data(17);
  delay(sec);
  lcd_data(17);
  delay(sec);
  lcd_data(17);
  delay(sec);
  lcd_data(10);
  delay(sec);
  lcd_data(4);
  delay(sec);
  lcd_data(0);
  delay(sec);


  }

 //---------------------- for current symbol-------------------

  void shape3()
  {
   
  lcd_cmd(80);   // Third location in CGRAM
  delay(sec);
  lcd_data(0);
  delay(sec);
  lcd_data(0);
  delay(sec);
  lcd_data(4);
  delay(sec);
  lcd_data(10);
  delay(sec);
  lcd_data(17);
  delay(sec);
  lcd_data(31);
  delay(sec);
  lcd_data(17);
  delay(sec);
  lcd_data(0);
  delay(sec);


  }
       





  //..... Converting binary value of ADC to ASCII value of LCD for Temprature........




  void convert()
  {
    int s;
     
  test_final=(((9*test_intermediate3)/5)+32);    // Farenhite conversion
 
  s=test_final/100;
  test_final=test_final%100;

  lcd_cmd(0xc5);
  delay(sec);
  if (s!=0)
   {
   lcd_data(s+48); //c5
   delay(sec);
   }
  else
   {
   lcd_cmd(0x06);
   delay(sec);
   }


   s=test_final/10;
   test_final=test_final%10;

   lcd_data(s+48);    //c6
   delay(sec);
   lcd_data(test_final+48); //c7
   delay(sec);
   lcd_data(0);     // space for degree symbol
   delay(sec);
   lcd_data('F');
   delay(sec);
   lcd_data(' ');
   delay(sec);


 //------------------- for Celcius scale----------------

   test_final=test_intermediate3;



   s=test_final/100;
  test_final=test_final%100;

  lcd_cmd(0xcB);
  delay(sec);
  if (s!=0)
   {
     lcd_data(s+48); // 1st digit MS
    delay(sec);
   }
  else
   {
     lcd_cmd(0x06);
    delay(sec);
   }



   s=test_final/10;    // 2nd digit
   test_final=test_final%10;  // 3rd digit LS

   lcd_data(s+48);  //89
   delay(sec);
   lcd_data(test_final+48);  //88
   delay(sec);
   lcd_data(0);     // space for degree symbol
   delay(sec);
   lcd_data('C');
   delay(sec);
    lcd_data(' ');
   delay(sec);

  }







  // Converting binary value of ADC to ASCII value of LCD for volts


  void  Convert2()
  {
   int s;
 //.................... Voltage conversion ............................

     
  test_final=test_intermediate3/5;
 
  s=test_final/100;
  test_final=test_final%100;

   lcd_cmd(0x85);
  delay(sec);
  if (s!=0)
   {
   lcd_data(s+48);
   delay(sec);
   }
  else
   {
   lcd_cmd(0x06);
   delay(sec);
   }


   s=test_final/10;
   test_final=test_final%10;

   lcd_data(s+48);    
   delay(sec);
   lcd_data(test_final+48);
   delay(sec);
   lcd_data(1);
   delay(sec);
    lcd_data(' ');
   delay(sec);
  }

 //-------------------..................-------------------

  void  Convert3()
  {
   int s;
//.................... current conversion ............................

     
  test_final=test_intermediate3;
 
  s=test_final/100;
  test_final=test_final%100;

    lcd_cmd(0x8D);
  delay(sec);
  if (s!=0)
   {
   lcd_data(s+48);
   delay(sec);
   }
  else
   {
   lcd_cmd(0x06);
   delay(sec);
   }


   s=test_final/10;
   test_final=test_final%10;

   lcd_data(s+48);    
   delay(sec);
   lcd_data(test_final+48);
   delay(sec);
   lcd_data(2);
   delay(sec);

  }

 
 
 
 
 
 
 
  //.........--------.......Main Program.......-------........

 

    void main()
    {

      int i,j,k,l,m,n;
   adc_input=0xff; // making p1 as input port
   TMOD=0x01;    // timer 0,  mode 1
   TH0=0xff;     // 500hz clock for adc
   TL0=0xff;
   TR0=1;         // timer start

   IE=0x83;  // interrupt enable; timer interrupt, external interrupt and globle interrupt.
   
  v28=0; v14=0; v7=0; off=1;  // intializing charger selection to 0V
  c28=0; c14=0; c7=0;
  intr=1;

    select_mem = select;
    delay(sec);
         
 
   lcd_cmd(0x38);  // initializing LCD module
   delay(sec);

   lcd_cmd(0x0c);
   delay(sec);

   lcd_cmd(0x01);
    delay(sec);

   lcd_cmd(0x06);
   delay(sec);

         
   
//;;;;;;;;;;;;;;-----------;;;;;;;;;;;;;;;
//......... volt and ampere display........

       lcd_cmd(0x80);                      
     delay(sec);
                   
  for(i=0; vna[i]!='\0'; i++)
   {
    lcd_data(vna[i]);
    delay(sec);
   }
   
//;;;;;;;;;;;;-----------------------;;;;;;;;;;;;;;;;;
//..........- Back up and %Charge display ----........

   lcd_cmd(0x90);
      delay(sec);

  for(i=0; bnc[i]!='\0'; i++)
   {
    lcd_data(bnc[i]);
    delay(sec);
   }      

       

 //;;;;;;;;;;;;;;-----------;;;;;;;;;;;;;;;
    //......... ----Temp: display-----........

  lcd_cmd(0xc0);
   delay(sec);
   
  for(i=0; temp[i]!='\0'; i++)
   {
    lcd_data(temp[i]);
    delay(sec);
   }


//;;;;;;;;;;;;;;-------------------------;;;;;;;;;;;;;;;;;
//.............- hour and minute display ------...........

     lcd_cmd(0xD0);            
     delay(sec);
   
  for(i=0; hnm[i]!='\0'; i++)
   {
    lcd_data(hnm[i]);
    delay(sec);
   }
       
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



   while(1)
   {

   //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Temprature samples;;;;;;;;;;;;;;;;;;;;;;
     
       test_intermediate3=0;
      test_final=0;
     test_intermediate2[0]=0;
     test_intermediate2[1]=0;
     test_intermediate2[2]=0;
     
   
     for(j=0;j<3;j++)
     {
      for(i=0;i<scan;i++)
      {    ctl=0;
            delay(10);
          ADC_A=0;
          ADC_B=0; // channel 0 is selected  ; pin 26 of ADC

        delay(200);
       
        ALE=0;
        SC=0;
        delay(1);

         ALE=1;
         delay(1);
         SC=1;
         delay(1);

         ALE=0;
         delay(1);
         SC=0;
       
         delay(200);
                 
         test_intermediate1[i]=adc_input/scan;
       
       
      }


      for(i=0;i<scan;i++)
      test_intermediate2[j]+=test_intermediate1[i];
     }


     test_intermediate2[0]=test_intermediate2[0]/3;
     test_intermediate2[1]=test_intermediate2[1]/3;
     test_intermediate2[2]=test_intermediate2[2]/3;

     test_intermediate3=test_intermediate2[0] + test_intermediate2[1] + test_intermediate2[2];
   
   

     convert();
     shape();

    long_delay(1);
    ctl=1;
    delay(10);
      ADC_A=1;
     ADC_B=0; // channel 1 is selected for voltage

   //;;;;;;;;;;;;;;;;;  Voltage samples;;;;;;;;;;;;;;;;;;;;;;;;;

      test_intermediate3=0;
      test_final=0;
                       test_intermediate2[0]=0;
     test_intermediate2[1]=0;
     test_intermediate2[2]=0;
   

       for( k=0;k<3;k++)
     {
      for(l=0;l<scan;l++)
      {  
        delay(10);
          ADC_A=1;
          ADC_B=0; // channel 1 is selected

        delay(200);
       

        ALE=0;
        SC=0;
        delay(1);

         ALE=1;
         delay(1);
         SC=1;
         delay(1);

         ALE=0;
         delay(1);
         SC=0;

         delay(200);
                 
         test_intermediate1[l]=adc_input/scan;
       
       
      }


      for(i=0;i<scan;i++)
      test_intermediate2[k]+=test_intermediate1[i];
     }


     test_intermediate2[0]=test_intermediate2[0]/3;
     test_intermediate2[1]=test_intermediate2[1]/3;
     test_intermediate2[2]=test_intermediate2[2]/3;

     test_intermediate3=test_intermediate2[0] + test_intermediate2[1] + test_intermediate2[2];
   
     
      Convert2();
       shape2();
 
     long_delay(1);
      ADC_A=0;
     ADC_B=1; // channel 2 is selected for current

 //;;;;;;;;;;;;;;;;;  Current samples;;;;;;;;;;;;;;;;;;;;;;;;;

         test_intermediate3=0;
      test_final=0;
     test_intermediate2[0]=0;
     test_intermediate2[1]=0;
     test_intermediate2[2]=0;
                 

       for( m=0;m<3;m++)
     {
      for( n=0;n<scan;n++)
      {    
        delay(10);
          ADC_A=0;
          ADC_B=1; // channel 2 is selected

        delay(200);
       

        ALE=0;
        SC=0;
        delay(1);

         ALE=1;
         delay(1);
         SC=1;
         delay(1);

         ALE=0;
         delay(1);
         SC=0;
       
         delay(200);
                   
         test_intermediate1[n]=adc_input/scan;

       
      }



      for(i=0;i<scan;i++)
      test_intermediate2[m]+=test_intermediate1[i];
     }


     test_intermediate2[0]=test_intermediate2[0]/3;
     test_intermediate2[1]=test_intermediate2[1]/3;
     test_intermediate2[2]=test_intermediate2[2]/3;

     test_intermediate3=test_intermediate2[0] + test_intermediate2[1] + test_intermediate2[2];
   
      Convert3();
       shape3();
     long_delay(1);
     
   }
    }


i dont know how to upload immage here from my pc so plz consider all connections ok. and eoc pin of adc0808 is tied with Vcc.



thanking you in anticipation.

regards
Qaisar azeemi.
PMEmail Poster
Top
Gorgon
Posted: March 25, 2012 02:12 am
Reply to this postQuote Post


Forum Addict ++
*******

Group: Trusted Members
Posts: 3,009
Member No.: 3,861
Joined: December 18, 2005




Is the ADCs voltage references connected in any way to the voltage you measure? If your reference is variable all measurements will be variable too.

TOK wink.gif


--------------------
Light travels faster than sound. That's why some people appear bright until they speak!
PMEmail Poster
Top
Qaisar Azeemi
Posted: March 26, 2012 06:05 am
Reply to this postQuote Post


Newbie
**

Group: Members+
Posts: 46
Member No.: 36,124
Joined: November 17, 2011




yes refrance is connected. i have connected 2.56v dc to +Vref using a voltage divider network... it is fixed...
PMEmail Poster
Top
Sch3mat1c
Posted: March 26, 2012 06:13 pm
Reply to this postQuote Post


Forum Addict ++
Group Icon

Group: Moderators
Posts: 19,467
Member No.: 73
Joined: July 24, 2002




Circuit, layout?


--------------------
Answering questions is a tricky subject to practice. Not due to the difficulty of formulating or locating answers, but due to the human inability of asking the right questions; a skill that, were one to possess, would put them in the "answering" category.
PMEmail PosterUsers Website
Top
Qaisar Azeemi
  Posted: March 27, 2012 06:32 am
Reply to this postQuote Post


Newbie
**

Group: Members+
Posts: 46
Member No.: 36,124
Joined: November 17, 2011




how do i post immage ...... i don't know... :-(
PMEmail Poster
Top
MacFromOK
Posted: March 27, 2012 05:10 pm
Reply to this postQuote Post


Forum Addict ++
*******

Group: Spamminator Taskforce
Posts: 14,051
Member No.: 5,314
Joined: June 04, 2006




You can't upload images directly, but you can use a free image hosting service (such as photobucket.com) and either use the IMG tags (if the pic isn't too large) or just post a link to the image.


--------------------
Mac *

"Basic research is what I'm doing when I don't know what I'm doing." [Wernher Von Braun]

* is not responsible for errors, consequential damage, or... anything.
PMEmail Poster
Top
CoulombMagician
Posted: April 01, 2012 04:13 pm
Reply to this postQuote Post


Forum Addict
******

Group: Spamminator Taskforce
Posts: 992
Member No.: 3,131
Joined: August 29, 2005




Been there, done that. Connect one input to ground and switch the mux to that input before reading any of your other inputs. This will eliminate the crosscoupling between channels in most cases. The "proper" way to do it is to drive each input with an active low impedance source which will discharge the input capacitance of the ADC, most people however just connect passive sources to ADC inputs.
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 


:: support us ::




ElectronicsSkin by DutchDork & The-Force