Interfacing external ADC0808 with PIC18F4522

Status
Not open for further replies.

shaltera

Newbie level 5
Joined
Mar 26, 2014
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
52
Hi,


I'm having difficulties to integrate external ADC0808 with PIC18F45k22. ACD0808 outputs are connected to PIC18F45K22 respectively:
ADC PIC
-------------------
OUT1 RB7
OUT2 RB6
OUT3 RB5
0UT4 RB4
OUT5 RB3
OUT6 RB2
OUT7 RB1
OUT8 RB0

To IN0, LM35 is connected (VOUT)

I have tried C code below, but result is incorrect.As well temperature result on LCD does not update when voltage on LM35 is changes.

---------------------------------------------------------

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
unsigned int temp_res,cal; char last[5];
 
void main() {
TRISb = 0b11111111; // PORTB is input
lcd_init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
do { temp_res = portb; // Get 8-bit results of AD conversion
cal = (temp_res);
inttostr(cal,last);
Lcd_Out(1,1,”temp”);
Lcd_Out(1,6,last);
Lcd_Out(1,13,”C”);
Lcd_Out(1,15,” “);
} while(1);
}


---------------------------------------------------------------------------------------

 
Last edited by a moderator:

Is 'cal' an int or a char? Perhaps you have declared it as a char (technically it should be an unsigned char) but the inttostr() function expects an integer value.
Try changing "inttostr(cal,last);" to "inttostr((int)cal,last); and see if it makes a diiference.

When posting code, please wrap it in code tags, copy and paste it to the message then highlight it and click the # icon above the message window, it tells the forum to display it in it's original format instead of stripping all the leading spaces.

Brian.
 


I will try when I get home.Thanks for you reply
 

What is your LCD showing? Does the display change when you alter the voltage fed to the ADC?
Possibly you have the data bits reversed. The LSB of the ADC 0808 is pin 17 which should probably be connected to RB0.

Brian.
 

Display does not change even when I change the voltage on LM35?
 

Sounds like an electrical or interface problem then. Can you monitor the START/EOC signal and make sure it changes state. It should be a divided down speed from the clock to the ADC, one pulse per 8 clock pulses. Also check what clock frequency you are using, the ADC0808 is a very slow device, the maximum clock frequency is around 1MHz.

Brian.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…