Programming Analog Shield (Digilent / Stanford)

Hello,

I am using Analog Shield from Digilent / Stanford on top of Arduino Uno board. I understand that Arduino Board uses 16Mhz of SPI clock (correct me if I am wrong). So, I have following questions, if someone can please explain:

  1. Analog shield has 16-bit ADC (ADS8343). Its datasheet says that it can handle maximum upto 2.4Mhz of clock and in that case it gives 100KS/S of sampling speed. Therefore, we must divide (reduce) the arduino SPI clock from 16Mhz to 2.4Mhz to meet the specs of ADS8343. Can some one please explain how and where it it performed in the code (library for analog shield is readily available in internet) ?

  2. If I want to reduce the sampling rate of ADC. Should I reduce the SPI clock frequency or use delay function between subsequent analog.read function calls ? Are there any other better alternatives ?

  3. At the same time, I also want to use DAC (DAC8564) in the analog shield. Will there be any effects in the performance of DAC if I reduce the SPI clock frequency ?

Its little urgent, I kindly request for prompt response.

Thanks

Kind regards,

In setup(),
after you call SPI.begin();
you can set the SPI clock divisor to 8 to have an SPI clock of 2 MHz. (default setting is 4 MHz).
If you look on the Reference page, I think Library at the lower right will take you to the page where you can see the SPI commands. (my internet is dog slow today for some reason).

Are you sure the two are connected? I would be really surprised to find out that the clock speed of the communication line affected the speed of the ADC. Seems like those two should be separate.

Yes, they are connected. I think SPI clock speed should effect the sampling speed of ADC.

Can you please explain as how is the SPI clock is being divided for the ADC (ADS843) in analog shield ?

I did find a code snippet in analog shield.cpp where it can be done …but not sure and neither can understand the code very well. Can you please help ?

<<
unsigned int analogShield::read(int channel, bool mode) {
// initialize SPI:
if(shieldMode != 2){
#if defined (PIC32MX)
SPI.setDataMode(SPI_MODE3);
#elif defined (SAM3X8E)
SPI.setDataMode(SPI_MODE3);
#else //(AVR)
SPCR &= ~(_BV(DORD));
SPCR = (SPCR & ~SPI_MODE_MASK) | SPI_MODE3;
SPCR = (SPCR & ~SPI_CLOCK_MASK) | (SPI_CLOCK_DIV2 & SPI_CLOCK_MASK);
SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((SPI_CLOCK_DIV2 >> 2) & SPI_2XCLOCK_MASK);
#endif
shieldMode = 2;
}

For your ready reference, I am attaching analoShield.cpp and analoShield.h

analogShield.cpp (25.1 KB)

analogShield.h (5.19 KB)

ads8343.pdf (909 KB)

I’m thinking these 2 lines have something to do with it:

SPCR = (SPCR & ~SPI_CLOCK_MASK) | (SPI_CLOCK_DIV2 & SPI_CLOCK_MASK);
SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((SPI_CLOCK_DIV2 >> 2) & SPI_2XCLOCK_MASK);

Don’t know why you need a library at all tho.
Just set the SPI Mode and Clock rate in setup, and sample away, per notes on Page 12 of the datasheet.

digitalWrite (ssPin, LOW);
SPI.transfer(commandByte); // contains channel select bits, other ADC mode bits
MSBs = SPI.transfer(0);
LSBS = SPI.transfer(0);
digitalWrite (ssPin, HIGH);
analogValue = (MSBs<<8) + LSBs; // combine into 16 bit value