Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] measuring 2 different source of voltages using 1 ADC.. how?

Status
Not open for further replies.

romel_emperado

Advanced Member level 2
Joined
Jul 23, 2009
Messages
606
Helped
45
Reputation
132
Reaction score
65
Trophy points
1,318
Location
philippines
Activity points
6,061
problem with ADC0808 protues simulation

hi guys, i have question about ADC Im planning to use the ADC0808 because as i read the datasheet it is 8 channel ADC. but my question is can i read 2 different voltages at the same time??

for example i will read 9v battery then the other input is 12c battery? is that possible?
 
Last edited:

As the different channels are multiplexed, you can only measure one channel at a time.

As a solution, you could measure the different voltages immediately after one conversion has finished, reducing delay between successive measurements.
 
Each ADC has multiple channels.. so you can connect different voltage sources to different channels and read them using a controller.

---------- Post added at 22:07 ---------- Previous post was at 22:06 ----------

same time reading is not possible as you need to set the mux to required channel, issue SOC signal wait for EOC signal then read it. so simultaneous reading is not possible......
 
You can take thousands of samples per second (100us conversion time for your ADC) but not simultaneously,
it doesn't matter in your case anyway and you don't need a fast conversion speed either.
You can use one channel after the other.
Also note that you will need voltage dividers, you can't connect 9v or 12v to the ADC input.

Alex
 
thanks for your response guys.. after reading some article I understand a little then now i am starting to write the code for this project.. hope i would not having a hard time to finish this.. :) :)
 

guys. I cant get the aDC functioning with my At89S51

pls check my code if there's something wrong :(

hex file and proteus file also attached :sad:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <REG51.H>
#define adc_port P3
#define adc_out P2
 
sbit ale=P1^0;  //address latch enable
sbit oe=P1^3;  //output enable
sbit sc=P1^1;  //start conversion
sbit eoc=P1^2;  //end of conversion
sbit clk=P1^7;  // clock
 
sbit ADD_A=P1^4;  // Address pins for selecting input channels.
sbit ADD_B=P1^5;
sbit ADD_C=P1^6;
 
 
 
void timer0() interrupt 1  // Function to generate clock of frequency 500KHZ using Timer 0 interrupt.
{
clk=~clk;
}
 
void delay(unsigned int count)  // Function to provide time delay in msec.
{
int i,j;
for(i=0;i<count;i++)
  for(j=0;j<1275;j++);
}
 
 
void select_channel(char c,char b,char a)
{
  ADD_A = a;
  ADD_B = b;
  ADD_C = c;
}
 
 
 
void convert()
{
  delay(1);
  ale=0;      //activate the ale PIN
  delay(1);
  ale=1;
  sc=1;      //initaite convertion
  delay(1);
  sc=0;
  delay(1);
 
 
 
 
}
void read_adc()
{
   while(eoc == 0);  //end of convertion
   oe = 1;           //enable adc output
   delay(2);
   oe = 0;
 
}
 
 
void main()
{
 
  P2 = 0x00;
  
  TMOD =  0x22;  //timer0 setting for generating clock of 500KHz using interrupt enable mode.
  TH0  =  0xFD;
  IE   =  0x82;
  TR0  =  1;
 
 while(1)
 {
   select_channel(0,0,1);
   convert();
   read_adc();
 
}
}

 

Attachments

  • 8051_ADC.rar
    12.6 KB · Views: 86
Last edited:

    V

    Points: 2
    Helpful Answer Positive Rating
i dont know what is wrong with that code. the aDC output is blinking ang cannot get input from the channel..
 

haha i solved the problem!! haha i got it working... lol my mistake is i left vref hanging.. haha

i spent almost 24 hours with this one... lol what a carelessness..
 

#include<reg51.h>
#include<intrins.h>
#include<stdio.h>

sbit rs=P3^6;
sbit en=P3^7;

sbit eoc=P2^1;
sbit soc=P2^0;

sbit cha=P2^2;
sbit chb=P2^3;
sbit chc=P2^4;

void cmdwrt();
void delay();
void datawrt();
void asc();
void valconv();

unsigned char dis[6]={0x30,0x38,0x08,0x0c,0x06,0x80};
unsigned char a,b,c,d;

main()
{
int i;
for( i=0;i<6;i++)
{
a=dis;
cmdwrt();
delay();
}
//select channel
cha=0;
chb=0;
chc=0;
while(1)
{
a=0x80;
cmdwrt();
delay();

eoc=0x01;
soc=0x00;
delay();

soc=0x01;
delay();
soc=0x00;

while(eoc); //wait for conversion
delay();
a=P1;
asc(); //display
delay();
}
}

void asc()
{
d=a;
a=a>>4;
a=a & (0x0f);
valconv(); //conv to ascii
datawrt(); //disp on LCD

a=d;
a=a & (0x0f);
valconv();
datawrt();
}


void valconv()
{
if(a <= (0x09))
{
a=a+ (0x30);
}
else
{
a=a+ (0x37);
}
}


void cmdwrt()
{
rs=0;
P0=a;
en=1;
delay();
en=0;
}

void datawrt()
{
rs=1;
P0=a;
en=1;
delay();
en=0;
}

void delay()
{
int i;
for(i=0;i<1000;i++);
}
 
thanks ckshivaram, but i have a hard time understanding that code.
i will read it carefully
 

i have solve my problem about conversion to string by using another compiler which is mikroC. but i have another problem

i cant create timer interrupt in mikcro like in keil.. i cant see any manual in the web or in the compiler itselt how to use the interrupts..




i have solve my problem about conversion to string by using another compiler which is mikroC. but i have another problem

i cant create timer interrupt in mikcro like in keil.. i cant see any manual in the web or in the compiler itselt how to use the interrupts..





my configuration in keil:


Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void timer0() interrupt 1  // Function to generate clock of frequency 500KHZ using Timer 0 interrupt.
{
clk=~clk; // output clock pulse to p1.7
}
 
 
void main()
{
 TMOD =  0x22;  //timer0 setting for generating clock of 500KHz using interrupt enable mode.
  TH0  =  0xFD;
  IE   =  0x82;
  TR0  =  1;
  while(1);
}

 

hello i finished this problem and this is my final code.. hehe thanks guys :-D:-D





Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Lcd module connections
sbit LCD_RS at P2_0_bit;
sbit LCD_EN at P2_1_bit;
sbit LCD_D4 at P2_2_bit;
sbit LCD_D5 at P2_3_bit;
sbit LCD_D6 at P2_4_bit;
sbit LCD_D7 at P2_5_bit;
// End Lcd module connections
 
 
sbit charging at P2_6_bit;
sbit full at P2_7_bit;
sbit control at P0_7_bit;
 
 
float inputa, inputb;
//adc config
sbit ale at P1_0_bit;  //address latch enable
sbit oe  at P1_3_bit;  //output enable
sbit sc  at P1_1_bit;  //start conversion
sbit eoc at P1_2_bit;  //end of conversion
sbit clk at P1_7_bit;  // clock
 
sbit ADD_A  at P1_4_bit;  // Address pins for selecting input channels.
sbit ADD_B  at P1_5_bit;
sbit ADD_C  at P1_6_bit;
 
 
 
void select_channel(char c,char b,char a)
{
  ADD_A = a;
  ADD_B = b;
  ADD_C = c;
}
 
void convert()
{
  ale=1;
  Delay_ms(5);
  sc=1;
  Delay_ms(10);
  sc=0;
  Delay_ms(1);
  ale=0;
}
 
 
void read_adc()
{
  while(eoc==0);
  oe=1;
  Delay_ms(1);
}
 
void get_adc(char x)
{
 
  select_channel(0,0,x);
  convert();
  read_adc();
  read_adc();
 
  if(x==0)
  inputa = P3;
  else if(x==1)
  inputb = P3;
 
}
 
 
void Timer1InterruptHandler() org IVT_ADDR_ET1
{
  clk = ~clk;
}
 
 
 
void main()
{
  float volt_a,volt_b;
  char txt[15];
  char txt2[15];
  char x;
  
  full = 0;
  charging = 0;
  control = 0;
  
  ET1_bit = 1;       // Enable Timer1 interrupt
  EA_bit  = 1;       // Set global interrupt enable
  GATE1_bit = 0;     // Clear this flag to enable Timer1 whenever TR1 bit is set.
  C_T1_bit  = 0;     // Set Timer operation: Timer1 counts the divided-down systam clock.
  
  TR1_bit = 0;       // Turn off Timer1
  TMOD = 0x22;
  TH1 = 0x00;        // Set Timer1 high byte
  TL1 = 0x00;        // Set Timer1 low byte
 
  TR1_bit = 1;       // Run Timer1
  
  
  Lcd_Init();                        // Initialize Lcd
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  while(1)
  {
 
 
      get_adc(0);
      Delay_ms(90);
      get_adc(1);
      x++;
      if(x==20)
      {
        Lcd_Cmd(_LCD_CLEAR);
        x=0;
 
      }
   //for windmill volatage display
      volt_a = (( inputa * 5) / 255)* 4;
      
      if(inputa<=10)
      volt_a = 0;
 
      FloatToStr(volt_a,txt);
      Lcd_Out(1,1,"Wind:");
      Lcd_Out(1,16,"V");
      Lcd_Out(1,7,txt);
 
     //for battery display
      //inputb=164;
      volt_b = (( inputb * 5) / 255)* 4;
      
      if(inputb<=10)
      volt_b = 0;
      else if(inputb >= 164) //165 = 12.8v which is battery full
      {
        full =1;
        control = 1;
      }
      else if(inputb >= 152)  //152 = 11.92v which is battery is discharge
      {
        charging = 1;
        full = 0;
      }
      //IntToStr(inputb,txt2);
 
      FloatToStr(volt_b,txt2);
      Lcd_Out(2,1,"Batt:");
      Lcd_Out(2,16,"V");
      Lcd_Out(2,7,txt2);
 
 
 
 
 
 
 
 
  }
}

 

guys why is that the output value of ADC during simulation is jumping? i mean if i adjust the pot from 0v to 3v then increase a little then it will detect 0v again increase a little then it will give you maximum value of 5v.. why?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top