Discussion in "Project Help" started by    Pater    Apr 24, 2018.
Tue Apr 24 2018, 04:51 PM
#1
Basically, I am trying to interface ADC0808 with 89C51 microcontroller, but the digital output (8 -bits) from ADC is not coming in the desired way, it is showing the random values for a given input.
I am trying to take digital data of a single input (analog) channel and the clock is generated using programming of 89C51.

Here is the code I have used,

#include<reg51.h>

void delay_sec(unsigned int);
void delay_us(unsigned int);
void InitADC(void);
unsigned char ReadADC(unsigned char);

#define AN0 0
#define AN1 1
#define AN2 2
#define AN3 3

sbit Add_A = P2^0;
sbit Add_B = P2^1;
sbit Add_C = P2^2;
sbit ALE = P2^3;
sbit EOC = P2^4;
sbit OE = P2^5;
sbit START = P2^6;
sbit CLK = P2^7;


#define Data_Bus P0
#define HalfCycleDelay 10 // usecs


void main()
{

unsigned char I;
InitADC();


while(1)
{

I= ReadADC(AN0);

}

}

void InitADC(void)
{
Add_A = 0;
Add_B = 0;
Add_C = 0;
ALE = 0;
EOC = 1;
OE = 0;
START = 0;
CLK = 0;
Data_Bus = 0xFF;
}

unsigned char ReadADC(unsigned char Channel)
{
unsigned int i = 0;
unsigned int ADC_value = 0;

/*Selecting analog Channel by providing respective
bits to A,B,C addresses*/
switch(Channel)
{
case AN0: Add_C = 0; Add_B = 0; Add_A = 0; break;

}

delay_us(HalfCycleDelay); // 250kHz Frequency
ALE = 1; // Enable Address Latch
CLK = 1; // Make CLK High
delay_us(HalfCycleDelay); // 250kHz Frequency
CLK = 0; // Make CLK Low
START = 1; // Start ADC Conversion
delay_us(HalfCycleDelay); // 250kHz Frequency
CLK = 1; // Make CLK High
ALE = 0; // Disable Address Latch
delay_us(HalfCycleDelay); // 250kHz Frequency
CLK = 0; // Make CLK Low
START = 0; // Complete the start pulse

for(i=0;i<2000;i++)
{
CLK = !CLK; // Toggle Clock
delay_us(HalfCycleDelay); // 250kHz Frequency
if(!EOC) // Wait for EOC to be low
break;
}

for(i=0;i<2000;i++)
{
CLK = !CLK; // Toggle Clock
delay_us(HalfCycleDelay); // 250kHz Frequency
if(EOC) // Wait for EOC to be High
break;
}

CLK = 0; // Make CLK Low
OE = 1; // Enable Output
delay_us(HalfCycleDelay); // 250kHz Frequency
CLK = 1; // Make CLK High
delay_us(HalfCycleDelay); // 250kHz Frequency
CLK = 0; // Make CLK Low
delay_us(HalfCycleDelay); // 250kHz Frequency
CLK = 1; // Make CLK High

ADC_value = Data_Bus; // Read value

delay_sec(1);

delay_us(HalfCycleDelay); // 250kHz Frequency
OE = 0; // Disable Output
CLK = 0; // Make CLK Low
delay_us(HalfCycleDelay); // 250kHz Frequency
return ADC_value; // Return ADC value
}


// Function for approximate delay in Secs.
void delay_sec(unsigned int d)
{
unsigned int i;
for(i=0;i<(d*20);i++)
delay_us(50000);
}

// Function for approximate delay in given uSecs.
void delay_us(unsigned int d)
{
unsigned int i, limit;
limit = d/15;
for(i=0;i<limit;i++);
}

So basically I wanted to know where I am wrong and if I give the clock from an external source then How can I give it ??
Wed Apr 25 2018, 05:23 PM
#2
I have run your code in a Proteus simulation
and it seems okay.
Do you have Proteus ?

Your code does not display a result, how to you know
your readings are wrong ?
Wed Apr 25 2018, 05:41 PM
#3
Yes, I have Proteus.
In Proteus it is running fine but I am basically getting the issues at the hardware side, when I am trying to interface the 8051 with ADC0808, the analog to digital conversion is not happening.

So basically I wanted to ask about what extra precaution we should take to get the output.

Please also give any additional suggestions if any.
Thu Apr 26 2018, 08:11 PM
#4


In Proteus it is running fine but I am basically getting the
issues at the hardware side, when I am trying to interface
the 8051 with ADC0808, the analog to digital conversion
is not happening.

Pater


It sounds like hardware / wiring problem.
You will have to post your circuit diagram.
How are you displaying your readings ?

Mon May 07 2018, 01:28 PM
#5
Sorry for late reply as exams were on,
Based on my troubleshooting I think there is problem related to the clock of ADC0808.

So can u please suggest the external clock circuit to be used with ADC0808, many of them have used 555-timer IC but I am not able to get the correct values of resistors and capacitors for generating proper clock signal.

Please suggest the solution to the problem.
Mon May 07 2018, 07:27 PM
#6
This design should be fine.
Choose a frequency between 1Khz and 100Khz to start.
http://www.ohmslawcalculator.com/555-astable-calculator

555s tend not to work well at 5 volts.
I would run it at 9-12 volts and limit the voltage applied
to the ADC0808 clock input.

Connect 555 pin3 to ADC0808 pin 10 with a 4.7K resistor.
Connect ADC0808 pin 10 to +5 volts with diode to shunt the excess voltage
on pin 10 to 5 volts.
Or
A voltage divider to drop the voltage to below 5 volts.


[ Edited Wed May 09 2018, 08:25 PM ]

Get Social

Information

Powered by e107 Forum System

Conversation

Thu Nov 21 2019, 12:30 PM
raj2555
how to interface 8051 microcontroller with NRF24L01+ module
ExperimenterUK
Sat Oct 12 2019, 10:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 10:18 AM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Thank you for your time,
ExperimenterUK
Mon Aug 05 2019, 07:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 04:33 PM
Ismail balghmi
Hello. Please I won't download
ExperimenterUK
Wed Jul 24 2019, 12:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 06:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.
ExperimenterUK
Thu Jul 11 2019, 07:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html

Downloads

Comments

ananyagupta
Tue Dec 03 2019, 07:53 AM
wells
Mon Nov 25 2019, 08:25 PM
auwal
Tue Nov 19 2019, 03:13 PM
ANKITPATEL
Mon Nov 18 2019, 11:00 AM
Casmir
Wed Nov 13 2019, 06:25 AM
DeepakBGattani
Mon Nov 11 2019, 01:31 PM
Jeanbusatta
Sun Nov 10 2019, 04:42 AM
mdayaz
Sat Nov 09 2019, 03:41 PM

Online

Guests: 34, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38107
Newest member: ananyagupta
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Nov 29 2019, 04:24 AM
" Is it possible to interface a fingerprint scanne...
ilylily07 Avatar
Posted By ilylily07
Thu Nov 28 2019, 03:50 PM
You will not find any code for an 8051 as no one w...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 26 2019, 05:44 PM
You will not find any code for an 8051 as no one w...
ilylily07 Avatar
Posted By ilylily07
Tue Nov 26 2019, 04:13 AM
I tracked down a OV7670 data sheet.The OV7670 puts...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 26 2019, 12:08 AM
I tracked down a OV7670 data sheet.The OV7670 puts...
ilylily07 Avatar
Posted By ilylily07
Mon Nov 25 2019, 04:38 PM
The 8051 has too little memory to do anything us...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 19 2019, 10:44 PM
The 8051 has too little memory to do anything us...
ilylily07 Avatar
Posted By ilylily07
Mon Nov 18 2019, 09:54 AM
0v7670 camera interfacing with stc 8051.using asse...
Jeanbusatta Avatar
Posted By Jeanbusatta
Sun Nov 10 2019, 04:43 AM
ty, really needed it
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Oct 22 2019, 05:18 AM