View previous topic :: View next topic |
Author |
Message |
Birdasaur
Joined: 07 Oct 2003 Posts: 29
|
Having trouble using an AD7829 with a PIC 18f8620 |
Posted: Thu Jan 22, 2004 7:46 am |
|
|
Hey hey everybody!
Does anyone out there have any experience using the A/D device AD7829 with a PIC. This is my first time using an External A/D with a PIC, so go easy on me. I think I'm following the data sheet correctly but I can't seem to get any output from the A/D device.
Here's a little sample of the code I'm trying to use:
Code: |
while(TRUE)
{
//Power up the A/D
output_high(CONVST);
delay_us(1);
output_low(CONVST);
//Set the Address bits on the A/D for the ADC8 channel
output_high(ADR2);
output_high(ADR1);
output_high(ADR0);
output_low(CS); //Enable A/D Chip Select Line
output_low(RD); //Enable the A/D Read (!RD) Line
data = input_b(); //Read converted data byte
output_high(RD); //Disable A/D Read (!RD) Line
output_high(CS); //Disable A/D Chip Select Line
printf("\b\b\b%03i",data); //output value
delay_ms(250); //wait a bit
} //end of while(TRUE)
|
Is there anything GROSSLY wrong here?
Am I missing anything or are there any tips for troubleshooting?
I'm trying to use a battery based voltage on my selected channel for the analog input. If anyone has any information that could help jumpstart me I'd appreciate it. |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Thu Jan 22, 2004 8:33 am |
|
|
I'm assuming you are trying to run in "mode 1" where the CONVST- is not being used to both convert and power down.
A quick look at the data sheet tells me:
1) Select your input first.
Code: | //Set the Address bits on the A/D for the ADC8 channel
output_high(ADR2);
output_high(ADR1);
output_high(ADR0); |
Your code is selecting Vin8, by the way.
2) Pulse your CONVST- for at least t2 which is given as 20ns minimum. Depending on the clock speed you have chosen, you could probably use "delay_cycles" instead of "delay_us"
3) Watch for EOC- to go low, indicating conversion complete. This is a good use of the external interrupt pin. Or you can poll on the pin or you can delay 420ns (according to the datasheet).
4) Drop CS-
5) Drop RD-
6) Read data
7) Raise RD-
8) Raise CS-
9) Before you start another cycle, you should check that EOC- has gone high again before dropping CONVST- otherwise you will put the ADC into sleep mode. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
Birdasaur
Joined: 07 Oct 2003 Posts: 29
|
Good points that raise a few questions |
Posted: Thu Jan 22, 2004 11:26 am |
|
|
rwyoung wrote: | I'm assuming you are trying to run in "mode 1" where the CONVST- is not being used to both convert and power down. | That is correct.
rwyoung wrote: | 1) Select your input first. | I made this change.
rwyoung wrote: |
2) Pulse your CONVST- for at least t2 which is given as 20ns minimum. Depending on the clock speed you have chosen, you could probably use "delay_cycles" instead of "delay_us"
| Will leaving this delay at 1 us have a negative effect
rwyoung wrote: | ... you can delay 420ns (according to the datasheet). | Would it be possible that I delay too long and lose the data? In other words... is the data still going to be available after 1 us
rwyoung wrote: | 6) Read data | Can I just use an input_x function or do I ABSOLUTELY have to use a port in PSP mode
Thanks for you input so far! I really appreciate it! |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Thu Jan 22, 2004 11:49 am |
|
|
Conversion starts on the falling edge. Since the maximum conversion time is suppoed to be 420ns and the AD7829 has an automatic power downmode you are probably powering down the ADC with your long 1us delay.
The automatic powerdown occurs if CONVST- is still low after the conversion is complete (or might be 120ns after conversion is complete).
If you must have that 1us delay then you are probably going to need to bring the ADC out of power down before you can read the data. Again, I'm not exactly sure since I don't have one here to play with.
I'd suggest you get a scope hooked to your CONVST- signal and the EOC- signal and look at the timing relationship between them. [/quote] _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
|