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] random ADC0808 output values.

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
guys I followed the project posted in this site about interfacing adc + 8051 but i got unexpected result

here's the link : **broken link removed**



my vref is 5v ..


i know that the adc output is in the range of 0 - 255 in binary..


when i input

1v the output of ADC is 51 (correct output)

2v the output of ADC is 102 (correct output)

3v the output of ADC is 153 (correct output)


but when i input 4v it will go back to 51 which is for 2v..


that is my problem... what should be the problem in this case?
 

Hi :), it sounds like you're using a state machine to change the address for in0 in1 in2 in3.. 00 01 10 11.. and so on. my guess is: when your state machine gets to state "11" to check - there's no delay / or there's a bug that advances to state 00, long story short, check your code or post it :) hope it helps have a nice day.
 
Hi :), it sounds like you're using a state machine to change the address for in0 in1 in2 in3.. 00 01 10 11.. and so on. my guess is: when your state machine gets to state "11" to check - there's no delay / or there's a bug that advances to state 00, long story short, check your code or post it :) hope it helps have a nice day.

hi sam, I am only using 1 channel and the rest of the pins are in ground..

anyway here's my code


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
// Lcd module connections
sbit LCD_RS at P3_5_bit;
sbit LCD_RW at P3_6_bit;
sbit LCD_EN at P3_7_bit;
 
sbit LCD_D4 at P3_0_bit;
sbit LCD_D5 at P3_1_bit;
sbit LCD_D6 at P3_2_bit;
sbit LCD_D7 at P3_3_bit;
 
//----------------------------//
 
// Address pins for selecting input channels.
sbit ADD_A  at P2_1_bit;
sbit ADD_B  at P2_2_bit;
sbit ADD_C  at P2_3_bit;
 
//------------adc config---------------///
sbit ale at P2_4_bit;  //address latch enable
sbit sc at P2_5_bit;
sbit oe  at P2_0_bit;  //output enable
sbit eoc at P2_6_bit;  //end of conversion
 
//----------------------------------------//
 
sbit charging at P0_5_bit;
sbit full at P0_6_bit;
sbit control at P0_7_bit;
 
//------------------------------------//
 
float inputa, inputb;
void select_channel(char c,char b,char a);
void convert();
void read_adc();
void get_adc(char x);
void display_reset(char count);
void checkbat_status();
//---------------------------------------//
 
void main()
{
  char bat[15];
  char wind[15];
 
  LCD_RW = 0;
  Lcd_Init();                        // Initialize Lcd
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
 
  charging = 0;
  full = 0;
  control = 0;
 
 
  while(1)
  {
     Lcd_Out(1,1,"BattV:");
     Lcd_Out(2,1,"WindV:");
 
     get_adc(0);
     ByteToStr(inputa, bat);
     Lcd_Out(1,8,bat);
 
  }
 
}
 
 
 
 
void select_channel(char c,char b,char a)
{
  ADD_A = a;
  ADD_B = b;
  ADD_C = c;
}
 
void convert()
{
  ale = 0;
  Delay_ms(1);
  sc  = 0;
  Delay_ms(50);
  ale = 1;
  Delay_ms(2);
  sc  = 1;
 
 }
 
 
 void read_adc()
{
  while(eoc);
  oe = 1;
}
 
 
 
void get_adc(char x)
{
 
  select_channel(0,0,x);
  convert();
  read_adc();
 
  if(x==0)
  inputa = P1;
  else if(x==1)
  inputb = P1;
  Delay_ms(1);
 
 
}
 
void checkbat_status()
{
  if(inputa > 164) //165 = 12.8v which is battery full
     {
        full =1;
        control = 1;
        charging = 0;
     }
     else if(inputa < 152)  //152 = 11.92v which is battery is discharge
     {
        charging = 1;
        full = 0;
        control = 0;
     }
}

 

**broken link removed**
please check page 9 and also your Vref(-) ..

And what did you mean by "it will go back to 51 which is for 2v.."
my confusion occurs cause of 1v -> 51 , 2v -> 102.

I'm currently making Audio Spectrum Analyzer with ADC0808 trying to work with standalone mode (State machine [000 -> 111] to ABC, 555 for clock ), the point is using channel in0.. you can delete the code for channel selection and just connect A B C to Gnd,
i would also suggest using INT0 as interrupt for EOC that way you don't have to worry about checking P2.6
(p.s. correct me if im wrong but, i think you can also connect ALE and OE to Vcc, and control the ADC with START pin - as soon as it done the EOC generates micro interrupt and after specific time you can start the new conversion as you like)
 
please check page 9 and also your Vref(-) ..

yes my vref is in oV or GRND..

And what did you mean by "it will go back to 51 which is for 2v.."
my confusion occurs cause of 1v -> 51 , 2v -> 102.
i mean if we increase the input voltage form 0 to 5v meaning the binary equivalent of adc output will increase too..
but in my case if i input 4v to 5v to my adc the ouput is somethimes zero and some random values..

this time i will let you simulate the above code with proteus file and hex..
 

Attachments

  • voltmeter8051.rar
    58.8 KB · Views: 70

(p.s. correct me if im wrong but, i think you can also connect ALE and OE to Vcc, and control the ADC with START pin - as soon as it done the EOC generates micro interrupt and after specific time you can start the new conversion as you like)

yes you are right. i will try this.. thanks
 

i think its your Positive Vref, if your Vref(-) is GND and Vref(+) is Vcc (5v) that doesn't mean the Vref is truly 5V 100%, meaning you can supply by mistake or measure error 4.2v or 4.7v and the ADC should still work properly, and if you're checking a battery with 5v - by measure error it can show you at the moment 4.8v or 4.3v... and also i strongly suggest you use Wire Wrap or soldering on board, with my experience so far that test matrix board gave me nothing but trouble.. (stuff got bad connections wires were unplugged etc..)
 
i think its your Positive Vref, if your Vref(-) is GND and Vref(+) is Vcc (5v) that doesn't mean the Vref is truly 5V 100%, meaning you can supply by mistake or measure error 4.2v or 4.7v and the ADC should still work properly, and if you're checking a battery with 5v - by measure error it can show you at the moment 4.8v or 4.3v... and also i strongly suggest you use Wire Wrap or soldering on board, with my experience so far that test matrix board gave me nothing but trouble.. (stuff got bad connections wires were unplugged etc..)

hello sam. my vref is in vcc or 5v... the error I encounter in real hardware is the same error i encounter during simulation in proteus.

pretty weird... :)

I was thinking that the error will remain only during simulation and not in real hardware but it's not..
after im done testing in the real hardware I thought my code has something wrong but after I search google for many tut about adc0808 I found so many finish project about adc0808 and tested their code and its still the same..

for you to see what is the exact error is , pls take a little time to simulate the attached file above.. tnx
 

Hello romel,

Guess this is a old thread, but have you found the solution to ur problem? I am using ADC0808 & I am stuck in the same situation of ADC not outputting the correct codes for input voltages (in hardware). Even the Proteus simulation with microcontroller is in error.

I have made some test programs in Proteus to verify the correct AD conversion, but even the simplest free-running ADC0808 circuit is giving wrong output at particular values, as you had explained, and correct at some values.

Plz see the attached file. The Proteus version is 7.7 SP2.
 

Attachments

  • Desktop.rar
    49.5 KB · Views: 62

Use my code above and I think I solved the random values by averaging ( up to ten results) the final values before displaying it to the LCD.
 

Hi! Romel

I think I fixed your problem. Check the attached simulation. I think the adc outputs od ADC0808 are inverted in proteus. I think it is now giving correct values.

Did you check with real hardware?
 

Attachments

  • voltmeter8051.rar
    19.7 KB · Views: 67
Yes thanks for solving... Haven't solved this in proteus before but I did in the real hardware.. As I said I made averaging method to make the unstable output stable..
 

Hello romel
i'm new to this forum and facing the same problem of adc0808 can you mail me the code in C?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top