Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

adc0804 interface code for pic18

Status
Not open for further replies.

ulas

New Member
hi i have an adc0804 interface code for pic18.I have tried so much but ı couldt solve it.İf someone might look at my code and talk about that i would be very happy.


My algoritm is like bellow
Stage 1) To trigger a new conversion, we must make pin 3 (Write) low and then return it to the high state. The conversion process starts when Write goes high (rising edge triggered).
Stage 2) When the conversion process is complete, pin 5 (Interrupt) will go low.
Stage 3) When we see pin 5 (Interrupt) go low, we must make pin 2 (Read) low to load the new value into the outputs D0 - D7.
Stage 4) Next we read the values into the 2051 Port 1.
Stage 5) Finally, we return pin 2 (Read) to the high state. The next conversion can be started immediately.


And here is my code(written in pch picc).ıf someone can solve what is the problem i would be thankfull.

#include <18f452.h>
#fuses NOPROTECT
#use delay(clock=4000000)


#BIT rd =0xF84.1
#BIT interrupt =0xF84.0
#BIT write =0xF84.2
#define allin 0xFF
#define allout 0
#define low 0
#define high 1
#BYTE porte = 0xF84
#BYTE portd = 0xF83
#BYTE portb = 0xF81


main()
{
int i;
set_tris_e(0x06);

set_tris_b(allin);
set_tris_d(allout);

for(i=1 ; ;i++)
{
rd=high;
write=low;
delay_us(10);
write=high;


don:
delay_us(10);
if(interrupt==0)
{ rd=low;
}
else goto don;
portd=portb;

}
}
 
Hi
I am just wondaring why you are using external ADC??:confused:
you are using PIC 18 family and it contains powerful internal ADC?
I am not familier with this language but I can promise you that you can do it in 3 lines in PIC Basic.

So can I offer help???

:rolleyes:
 
Would you mind providing a few more details, like what you are observing. Testing an interrupt flag for zero looks suspuicious. Not resetting the flag after you detect it also looks suspicious. Transfering the data from one port to another looks positively silly. Why not connect the ADC directly to what is on the other side of PORTB.

It would be much easier to help you if you would use the "code" tag so that your code is indented properly, and you would describe what you observe.
 
ı will try using an inteerupt.ok
i cant use internal adc because i need to use 3 senkronized adc's and in pic there is only one adc and 8 inputs to this adc
i copy portb to portd to see ıf i an doing all right because i have leds connected to portd in my pic board so i can see if my program is working.so thats not so important.
i cant really understand why this programme is not workıng but i will try to use an interrupt.
thank you who answered please everyone write their opinion.i would be greatfull for that.bye
 
Wait!
Now that you have provided some details on what you are trying to do we are moving forward. I did not mean to tell you to "use an interrupt"; you already are using one by testing the flag. You can use an interrupt flag in a polling loop but they are usually set to 1 when there is an interrupt. Once you have detected the value of the flag equal to 1, it is customary to reset it to 0. There was no interrupt in your code; the program did not go to an interrupt location. All you did was test a flag that gets set by some hardware condition. Now ask yourself the following question. "What will happen to my program if the flag is never set" or "never cleared"?

Posting a diagram of your circuit would be helpful since we have not ruled out a hardware problem yet.
 
thank you papabravo so much
"What will happen to my program if the flag is never set" or "never cleared"?
and that is the correct part.I look at interrupt pin of adc and its never 0.so i can never go into that if clause .Thats why the program is not working.u are clever man thank u.
Do u ever used adc0804.in that device if you make write pin high to low proses begins.and when its finished it makes inteerupt pin low(else times its high).Than u can understant conversion has finished.after that u make rd pin low and take the results.after that the same process begıns agaın.u make write pin low and aftre that high aand goes on.... .so i dont really know if its really needed to make interrupt high again.
I dont thınk there ıs something wrong wıth adc because ın free runnıng mode ıts workıng clearly but ıf u want ı can send u a shematic.
thanks again.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top