Go Down

Topic: SPI & ADCs: bit-banging vs SPI.h (Read 3 times) previous topic - next topic

sdh314

Hi all,

I've noticed that there is very little code out there for SPI controlled ADCs using the SPI library SPI.h.  Most implementations are just bit-banged in.  One user from a previous post of mine (http://arduino.cc/forum/index.php/topic,65059.0.html) one user mentioned that the bit-banging was a much slower way to run the ADC.  Does anyone know how much faster using SPI.h would be?  I'm still having dramas getting the ADC (ADS8341), RTC (DS3234) and uSD card all working together, so looking at trying to run all SPI devices with the SPI library incase the ADC bit-banging code is causing the other devices grief.  Any suggestions welcome!

Thanks in advance!

CrossRoads

Take a look at the ADC code I put together here

http://arduino.cc/forum/index.php/topic,50125.msg484633.html#msg484633

You may need to tweak a little for the AD8341, like if it needs an address as part of the command byte or something.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

fat16lib

I just did a bit-bang library for a number of Microchip SAR ADCs.  For the MCP3201 I can get a reading in 9 microseconds.   This requires two bytes and is the maximum spec speed for this ADC.  I use a few nops to get a nice clock.

I did bit-bang SPI for SD cards as an option in the SdFat library, the base for Arduino SD.h.  I get about the equivalent of 2.5 MHz SPI clock.

My estimate is bit-bang SPI is about 1/3 as fast as full speed hardware SPI.

I like bit-bang for ADCs in ISRs.  That leaves hardware SPI free for non-interrupt use.

CrossRoads

@fat16lib,
How do you think this would be as stereo sound capture/playback system?
Fast ADCs capture sound at 40 KHz, store to serial SRAM, or direct to SD if fast enough

Read back from SD to dual DACs

2 fast 16-bit ADCs for capture, need to read 3 bytes each
http://www.analog.com/static/imported-files/data_sheets/AD7683.pdf

Fast dual DAC for playback, need to write 3 bytes each channel
http://www.analog.com/static/imported-files/data_sheets/AD5663.pdf
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

fat16lib

I don't think 16-bit stereo audio at 44.1 ksps is possible.  But I have been thinking about it for a while.

I can write a 512 byte block to SD in about 900 microseconds using a special multi-block write command.  So about 1/3 of the CPU is needed for SD write at 176.4 KB/sec.

I am going to do an experiment reading out two ADC in parallel using bit-bang.  I will connect a single pin to clock on both ADCs but have separate pins for data out.  For ADCs that need input I would use a common data in pin.

My guess is that it will take too long.


Go Up