| View previous topic :: View next topic |
| Author |
Message |
Izzy
Joined: 27 May 2007 Posts: 106
|
|
Posted: Mon Jul 14, 2008 4:40 pm |
|
|
Hello,
I am using a 40 Mhz cystal Oscillator.I remember someone had mentioned this before about the HS fuse. But if I use H4 instead of HS fuse, it give all random characters...something that I cant read. But having or not having HS does not show any difference.
I wish I had scope to test the Oscillator. But I just did a small test and the oscillator looks fine. I removed 40Mhz oscillator from the PIC and used 4Mhz from the ADC to run the PIC and it does the same thing as it was doing before with 40Mhz.
So I am guessing that means its not the oscillator problem. |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 14, 2008 4:52 pm |
|
|
Post your compiler version. I'll look at the .LST file and see if there is
anything wrong with the SPI code. |
|
 |
Izzy
Joined: 27 May 2007 Posts: 106
|
|
Posted: Mon Jul 14, 2008 4:56 pm |
|
|
It says :
PCWH compiler
Version is 4.013 |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 14, 2008 5:18 pm |
|
|
That's an old version, but the SPI code looks OK.
The purpose of this test is to write to the control register and read from
the status register. According to the data sheet, the two address bits that
select the register to write to are in bits 15 and 14, as you said before.
But there are two other bits (bits 6 and 7) that select the register to read
from. According to Table II on page 9, both those bits should be set = 1
to read the status register. So the LSB should be set to (at least) 0xC0.
Try this code and see what you get.
| Code: | while(TRUE)
{
spi_write(0xE4);
spi_write(0xC0);
delay_us(10);
Data_msb = spi_read(0x00);
Data_lsb = spi_read(0x00);
delay_us(10);
value = make16(Data_msb,Data_lsb);
fPrintf(debug, "Reading = %lu\n", value);
delay_ms(1000);
} |
|
|
 |
Izzy
Joined: 27 May 2007 Posts: 106
|
|
Posted: Mon Jul 14, 2008 5:26 pm |
|
|
Thanks once again.
I tried the code below, same as you posted above. But Same result.
The thing you said makes sense because you have to write into the control register to read the status byte. So the first two bit of MSB should be '11'. But why in pg 12 of the data sheet, they say the following thing for the Status register.:
Bit 15 ZERO
This bit is always 0.
Bit 14 BUSY
Conversion/Calibration Busy Bit. When this bit is 1 it indicates that there is a conversion or
| Code: | #include <18F4685.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay(clock=40,000,000)
#use rs232(stream=debug, DEBUGGER)
#include <stdlib.h>
int Data_msb=0;
int Data_lsb=0;
int16 value = 0;
void main()
{
setup_spi(SPI_MASTER| SPI_H_TO_L | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16);
delay_ms(200);
while(TRUE)
{
spi_write(0xE4);
spi_write(0xC0);
delay_us(10);
Data_msb = spi_read(0x00);
Data_lsb = spi_read(0x00);
delay_us(10);
value = make16(Data_msb,Data_lsb);
fPrintf(debug, "Reading = %lu\n", value);
delay_ms(1000);
}
} |
|
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 14, 2008 5:34 pm |
|
|
The chip designers chose to return the Busy bit in bit 14. That left bit 15
free for some other information, but they didn't have anything else that
they wanted to give back as status information, so they just return it as 0.
If status cannot be read, there is some bug somewhere. Either hardware
or software. It could be in the connections. |
|
 |
Izzy
Joined: 27 May 2007 Posts: 106
|
|
 |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
| will this thread be avalaible in a printed, bound edition at |
Posted: Mon Jul 14, 2008 7:29 pm |
|
|
If so - sign me up .
I would love a copy for my coffee table.
 |
|
 |
Izzy
Joined: 27 May 2007 Posts: 106
|
|
Posted: Mon Jul 14, 2008 7:40 pm |
|
|
Why so?
Hope we didnt put you into sleep.  |
|
 |
Izzy. Guest
|
|
Posted: Tue Jul 15, 2008 8:20 am |
|
|
Any other thoughts on this?
PCM programmer or anyone? |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 15, 2008 10:55 am |
|
|
Get some other SPI chip that's known to work, and that doesn't require
an external CLKIN signal and try to make it work.
For example, get an SPI eeprom such as the 25LC640. If you can make
that work, then you know you can talk to an SPI device. You will then
have more confidence in trying to make the A/D chip work.
Here is a driver for the 25LC640 that uses hardware SPI:
http://www.ccsinfo.com/forum/viewtopic.php?t=28199&highlight=25lc640&start=1 |
|
 |
IzzY. Guest
|
|
Posted: Tue Jul 15, 2008 11:04 am |
|
|
| I think I have a 8bit- SPI interface digital potentiometer at home. I will try that this evening. |
|
 |
Izzy
Joined: 27 May 2007 Posts: 106
|
| I am back again... :) |
Posted: Sat Dec 20, 2008 7:34 pm |
|
|
Hello respected forum member,
I am back again with this problem which I was able to solve 6-7 months ago with AD7856 Analog to digital converter. I got caught up with my school work and I didnt get time to spend on this project. But finally my finals are over, So here I go again
The problem I had before is still haunting me and I am still trying to figure out whats going on. If I had an scope, probably that would have helped me greatly, but unfortunately I dont.
I rechecked the circuit again and made sure everything is OK. Now I added 10 us delay between every SPI command and connected 4MHz clock to CLKIN as well as SCLK. And I have removed the connection between SCLK of the PIC and the AD7856.
And fortunately I am getting something, but the result does not make much sense. This is 14 bit AD. I have 2.7 V at the reference and 1.6 volts at the AD input. and I am getting this,
| Quote: | Reading = 65406
Reading = 30471
Reading = 47104
Reading = 56320
Reading = 65405
Reading = 32519
Reading = 65533
.........and so on |
| Code: |
#include <18F4685.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay(clock=40,000,000)
#use rs232(stream=debug, DEBUGGER)
#include <stdlib.h>
int Data_msb=1;
int Data_lsb=1;
int16 value = 0;
void main()
{
setup_spi(SPI_MASTER| SPI_H_TO_L | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16);
delay_ms(250);
while(TRUE)
{
spi_write(0xE1); delay_us(20);
spi_write(0x11); delay_us(20);
Data_msb = spi_read(0x00); delay_us(20);
Data_lsb = spi_read(0x00); delay_us(20);
value = make16(Data_msb,Data_lsb);
fPrintf(debug, "Reading = %lu\n", value);
delay_ms(1000);
}
} |
My Connection:
http://img175.imageshack.us/img175/5271/drawing15am3.jpg
The Control Register:
http://img371.imageshack.us/img371/5355/setbityy9.jpg
(The download link appears at the right hand side bottom corner.)
AD7856 datasheet with important points highlighted
http://www.2shared.com/file/3588490/69c2c4b2/AD7856.html
I would greatly appreciate your help! |
|
 |
Izzy
Joined: 27 May 2007 Posts: 106
|
|
Posted: Sun Dec 21, 2008 12:58 pm |
|
|
Any thought?
PCM Programmer, Ttelmah or Anyone? |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 21, 2008 2:39 pm |
|
|
| Quote: |
I have connected 4MHz clock to CLKIN as well as SCLK. And I have
removed the connection between SCLK of the PIC and the AD7856. |
1. The external 4 MHz clock oscillator signal is asynchronous to your
SDO signal. It can't work. Put the connections back the way they were.
2. The \SYNC signal is the SPI slave select signal. You're not currently
using it, and that might be part of the problem. I would connect it, and
use it. Choose an unused i/o pin on your PIC, and connect it to the
\SYNC pin on the AD7856. In the code shown below, I've picked Pin B0.
Change that pin, if required.
3. The 18F4685 data sheet says that you should use "EC" or "EC_IO"
for the oscillator mode, if your external oscillator is running at 40 MHz.
See this table in the data sheet:
| Quote: | | TABLE 27-6: EXTERNAL CLOCK TIMING REQUIREMENTS | So I've changed it from HS to EC_IO.
4. I see no reason to set the STCAL bit. I've put it back to 0.
The 2nd command byte becomes 0x10 instead of 0x11.
5. You have changed the channel select bits from your previous code.
They are now set for channel 0. That's the AIN1 input, which is on pin 9.
Verify that your input signal are connected to this pin.
The changes to your code are shown in bold.
| Quote: |
#include <18F4685.h>
#fuses EC_IO,NOLVP,NOWDT
#use delay(clock=40,000,000)
#use rs232(stream=debug, DEBUGGER)
#include <stdlib.h>
#define AD7856_SYNC PIN_B0
int Data_msb=1;
int Data_lsb=1;
int16 value = 0;
//=============================
void main()
{
setup_spi(SPI_MASTER| SPI_H_TO_L | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16);
delay_ms(250);
while(TRUE)
{
output_low(AD7856_SYNC);
spi_write(0xE1);
spi_write(0x10);
output_high(AD7856_SYNC);
delay_us(10); // Conversion time is 5.25 us max.
output_low(AD7856_SYNC);
Data_msb = spi_read(0x00);
Data_lsb = spi_read(0x00);
output_high(AD7856_SYNC);
value = make16(Data_msb,Data_lsb);
fPrintf(debug, "Reading = %lu\n", value);
delay_ms(1000);
}
} |
|
|
 |
|