![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
BM92
Joined: 04 Oct 2013 Posts: 18
|
ADC to SPI communication |
Posted: Fri Oct 04, 2013 7:31 am |
|
|
I have recently started a project which is requiring me to use a ADS1601 and a p24FJ128GA010. I have to communicate between these two devices but am very new to programming pics and ADC's.
I understand that to initialize the ADC a pulse sync needs to be sent but cannot find any examples of this. The PIC i will be using will be a slave. WIll the following code initialize the external ADC or the internal:
Code: | void initADC( int amask)
{
AD1PCFG = amask;
AD1CON1 = 0x00E0;
AD1CSSL = 0;
AD1CON2 = 0;
AD1CON3 = 0x1F3F;
AD1CON1bits.ADON = 1;
} |
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Fri Oct 04, 2013 8:33 am |
|
|
As there are no other 'hits' for the ADS1601, I suggest you download the datasheet and grab some graph paper. Consult the datasheet and 'set' the appropriate bits in the required registers using the graphpaper.Then you can convert the binary information into hex( if you want).
It's far easier to understand 'configuration' setups in binary for me.Far easier to see if a bit has been incorrectly set/cleared.
I don't have the time to download the ADS1601 datasheet and 'play computer'. I also don't have any hardware to test the 'configuration' to verify that it is correct.
A key part of being a tech is to read,code,test and repeat as required.
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
BM92
Joined: 04 Oct 2013 Posts: 18
|
|
Posted: Fri Oct 04, 2013 8:46 am |
|
|
Thanks for the reply. I have looked at the datasheet but not much is given on the configuration as far as i can tell. Sorry if it seems like i am simply looking for an answer but this is a project which has been given to me and i have no pic or ADC knowledge so far.
I understand how to configure different control registers etc but was not sure how to initialize the ADC. Even a guide on this would be very useful as i have searched the internet for days and simply do not know where to start. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Fri Oct 04, 2013 9:16 am |
|
|
Well I'm NOT impressed with TI's datasheet either ! Not ONE sentence, let alone paragraph on HOW to configure the ADC!
Given the dismal lack of 'details', I strongly suggest you get another ADC, one with clear ,concise information on how to configure it.
Also 16bit ADCs MUST have supply well designed PCBs to be useful!! Board layout, decoupling, trace widths, etc. are CRITICAL. NOT for the beginner. even 12bit ADCs are 'fun' to get working 90%, let alone 100%.
You'll also find the '24' series of PICs don't have a lot of 'support' here. Most guys use the 16 and 18 series, so there's TONS of help for them.
Since you're new to PICs, please consider something easier, like the PIC18F46K22.Tons of goodies inside(2 UARTS,ADC,memory,etc) and well known on this forum. I consider it the 'Swiss army knife' of PICs.
However , if you're stuck using that ADC, contact TI and get some real details! 18 pages of 'analog' info doesn't help on the digital side of things !!
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
BM92
Joined: 04 Oct 2013 Posts: 18
|
|
Posted: Fri Oct 04, 2013 9:36 am |
|
|
temtronic wrote: | Well I'm NOT impressed with TI's datasheet either ! Not ONE sentence, let alone paragraph on HOW to configure the ADC!
Given the dismal lack of 'details', I strongly suggest you get another ADC, one with clear ,concise information on how to configure it.
Also 16bit ADCs MUST have supply well designed PCBs to be useful!! Board layout, decoupling, trace widths, etc. are CRITICAL. NOT for the beginner. even 12bit ADCs are 'fun' to get working 90%, let alone 100%.
You'll also find the '24' series of PICs don't have a lot of 'support' here. Most guys use the 16 and 18 series, so there's TONS of help for them.
Since you're new to PICs, please consider something easier, like the PIC18F46K22.Tons of goodies inside(2 UARTS,ADC,memory,etc) and well known on this forum. I consider it the 'Swiss army knife' of PICs.
However , if you're stuck using that ADC, contact TI and get some real details! 18 pages of 'analog' info doesn't help on the digital side of things !!
hth
jay |
At least there is a reason i seem to be struggling. These were the two devices i was specifically told to use which is very annoying as it seems to be making it very difficult for me. I completely understand the theory of how the SPI and ADC should work together but i cannot seem to get any information regarding this ADC at all
Thanks, |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 04, 2013 10:57 am |
|
|
temtronic wrote: | Well I'm NOT impressed with TI's datasheet either ! Not ONE sentence, let alone paragraph on HOW to configure the ADC!
|
http://www.ti.com/lit/ds/symlink/ads1601.pdf
The ads1601 data sheet has initialization information in these sections:
Page 8: see "Figure 1. Initialization Timing".
Page 19: Explains that you must send a SYNC pulse as shown in Figure 1.
The ads1601 is a read-only device. You can't write any configuration
bytes to it. It doesn't have a DIN pin. It only has a DOUT pin. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: ADC to SPI communication |
Posted: Fri Oct 04, 2013 11:11 am |
|
|
BM92 wrote: |
The PIC i will be using will be a slave. WIll the following code initialize the external ADC or the internal:
void initADC( int amask)
{
AD1PCFG = amask;
AD1CON1 = 0x00E0;
AD1CSSL = 0;
AD1CON2 = 0;
AD1CON3 = 0x1F3F;
AD1CON1bits.ADON = 1;
}
|
That code has absolutely nothing to do with talking to the external ads1601
chip at all. The A/D module inside the PIC is a completely separate
entity from the external ads1601 chip. The PIC must get data from the
ads1601 by using the digital interface signals of SCLK, DOUT, FSO, and SYNC.
My understanding is that you are a complete newbie. I don't know who
gave you this project, I assume maybe a teaching assistant in a lab class.
I would never give components this complex to a newbie. I would have
the newbie start with maybe a 16F887 or 18F4620, and learn how to use
the internal 10-bit A/D converter. That would make sense. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Fri Oct 04, 2013 11:25 am |
|
|
Man BIG confusion is thinking this IS an SPI device ! Well, at least a 'regular' SPI device...though TI does say '3 wire inteface', you need the 4th wire(FSO) to sync the data, so you have to treat it as NOT an SPI device. Once you get your head straight on that, a simple bitbanging driver should 'talk' to it Ok...
cheers
jay |
|
![](templates/subSilver/images/spacer.gif) |
BM92
Joined: 04 Oct 2013 Posts: 18
|
Re: ADC to SPI communication |
Posted: Fri Oct 04, 2013 1:11 pm |
|
|
PCM programmer wrote: | BM92 wrote: |
The PIC i will be using will be a slave. WIll the following code initialize the external ADC or the internal:
void initADC( int amask)
{
AD1PCFG = amask;
AD1CON1 = 0x00E0;
AD1CSSL = 0;
AD1CON2 = 0;
AD1CON3 = 0x1F3F;
AD1CON1bits.ADON = 1;
}
|
That code has absolutely nothing to do with talking to the external ads1601
chip at all. The A/D module inside the PIC is a completely separate
entity from the external ads1601 chip. The PIC must get data from the
ads1601 by using the digital interface signals of SCLK, DOUT, FSO, and SYNC.
My understanding is that you are a complete newbie. I don't know who
gave you this project, I assume maybe a teaching assistant in a lab class.
I would never give components this complex to a newbie. I would have
the newbie start with maybe a 16F887 or 18F4620, and learn how to use
the internal 10-bit A/D converter. That would make sense. |
You got that right. This is my first project i have ever done involving pic's and SPI's so i am struggling to get my head around it. All i have been told is to set up the communication between the PIC an ADC using an SPI interface and its all a little baffling to me.
Also, like i said i did have a feeling that the code i gave was for the internal ADC and not the external one. Seems i was correct
So far i know that the first thing i need to do is initialize the ADC. Finding an example or guide on how to do this is proving difficult.
Also, thanks for all the replys |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 04, 2013 3:53 pm |
|
|
I was looking at this some more, and I realized the ads1601 is the master.
It produces SCLK, DOUT, and FSO. So the 24F PIC must be the slave.
In the MSSP section of the 24FJ128GA010 data sheet, it shows a block diagram:
FIGURE 15-8: SPI SLAVE, FRAME SLAVE CONNECTION DIAGRAM
There isn't very much information on that mode in the data sheet.
They refer you to the 24F Reference Manual:
http://ww1.microchip.com/downloads/en/DeviceDoc/39699b.pdf
The timing diagrams show that it is probably possible to do this project
with the 24FJ128GA010 by putting it in "SPI slave, Frame slave" mode.
It looks like it fits the timing of the ads1601's output signals.
But I don't have the PCD compiler so I can't really help too much. |
|
![](templates/subSilver/images/spacer.gif) |
BM92
Joined: 04 Oct 2013 Posts: 18
|
|
Posted: Fri Oct 04, 2013 4:18 pm |
|
|
PCM programmer wrote: | I was looking at this some more, and I realized the ads1601 is the master.
It produces SCLK, DOUT, and FSO. So the 24F PIC must be the slave.
In the MSSP section of the 24FJ128GA010 data sheet, it shows a block diagram:
FIGURE 15-8: SPI SLAVE, FRAME SLAVE CONNECTION DIAGRAM
There isn't very much information on that mode in the data sheet.
They refer you to the 24F Reference Manual:
http://ww1.microchip.com/downloads/en/DeviceDoc/39699b.pdf
The timing diagrams show that it is probably possible to do this project
with the 24FJ128GA010 by putting it in "SPI slave, Frame slave" mode.
It looks like it fits the timing of the ads1601's output signals.
But I don't have the PCD compiler so I can't really help too much. |
Yes thats correct the PIC should be in slave mode. I understand the theory of how each step should work but as i am not entirely familiar with the coding i am struggling to produce a code which does what i want.
Is there any books, guides or websites which may help me with this project?
I appreciate all of the help and the time you spent looking at this. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Fri Oct 04, 2013 7:22 pm |
|
|
Man, it's still one ugly project !!
I tried 'googling', and there isn't a whole lot about it, sigh...
Have to ask, do you have some kind of prototyping PCB for testing?
Maybe a 'demo' kit from TI? Layout/noise will be an 'issue'.
If you can't get what PCM P was saying to work(seems sketchy.,well uncommon...) I'd run a 20MHz clock(same as PIC ?) into it and use the FSO output as an input to an interrupt to 'sync' the data.In the ISR,check 'sclk' and 'data' for hi/lo and build up the incoming data stream into 16 bits.I know 'timing' is critical and maybe the 'internal SPI peripheral' of the PIC will do the same job. sclk could be a 2nd interrupt, for proper timing ?
Kind of like making an 'old school' bit-banged UART....
just another way to look at it...
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19382
|
|
Posted: Fri Oct 04, 2013 11:57 pm |
|
|
If you look at P22 of the data sheet, Texas are careful to point out the need for really good PCB design/layout.
It is an ugly chip, and the PIC is not going to be doing much else. The lack of data, is because there is literally nothing to do. You pulse 'sync' once after power up, to start the chip, and it then just continuously sends you data, with a separate sync pulse to tell you when the readings start..
This sync, would ideally go to the slave select on the PIC,
The big question is what one hopes to 'do' with the data. It is generating MB/sec of output, and putting it somewhere fast enough, is going to be the problem, Given the small amount of RAM on the PIC, and the amounts involved, it'd be much more suited to a processor with a lot more RAM.
It is not a project to be started without at least some experience in analog design, and some understanding of both the capabilities and limitations of particular processor families....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
BM92
Joined: 04 Oct 2013 Posts: 18
|
|
Posted: Sun Oct 06, 2013 5:52 am |
|
|
Thanks for the help.
If i am using a SPI slave, framed slave setup would the synchronisation pulse be sent automatically when data is being sent or do i have to code a synchronizing pulse to happen before the data is transmitted to the SPI |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Sun Oct 06, 2013 6:38 am |
|
|
After looking at the SPI datasheet...it seems you'll have 'fun' trying to read in 16 bits of data into the 8 bit SPI peripheral.It naturally would require 2 operations and doesn't appear to be 'programmer friendly'.
I still don't see how the ADC is a real 'SPI' device,more a 3 wire device.
Honestly, if you're stuck using this ADC, consider the old school 'bit banging' approach.
Use the ADC's FSO pin to trigger an interrupt.Inside the ISR read the DOUT pin while counting SCLK transitions, building up a 16 bit variable.
This approach will work and should maybe take 2-3 hours to get it 'up and running'.Once you're OK with the data coming back, then _maybe_ see if you can get the internal SPI of the PIC to work.
It boils down to how much time you have for this 'driver' section of code or the overall project.
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|