An advantage of bit-banging is that you have tight control of when the samples are taken, in the case given every 40 μs, not as and when the SPI driver gets around to it.
To bit-bang a chain of DMA blocks is used to switch the CLK, MOSI, and SS lines on/off according to the SPI requirements. The DMA blocks also contain gpio reads to capture the data transmitted by the ADC MISO lines. All gpios are read simultaneously (that's the way the Broadcom SOC works) so as many ADCs can be read as can be connected. In my experiment I used 2 ADCs as that is all I have.
The waveforms are constructed by a modified version of the pigpio library. Each waveform is made up of a series of pulses which define its characteristics. Multiple waveforms are generated so that samples can be held in a cyclic buffer in memory (giving enough time to extract the readings). The waveform to capture one sample is given below.
Code: Select all
micro - microseconds from waveform start
On - gpios to switch on
Off - gpios to switch off
G - 1 if time to sample MISO lines
delay - until next pulse
micro On Off G delay
0 00000000 00044000 0 1
1 00008000 00000000 0 1
2 00000000 00008000 0 1
3 00008000 00000000 1 1
4 00040000 00008000 0 1
5 00008000 00000000 1 1
6 00000000 00008000 0 1
7 00008000 00000000 1 1
8 00000000 00048000 0 1
9 00008000 00000000 1 1
10 00000000 00008000 0 1
11 00008000 00000000 1 1
12 00000000 00008000 0 1
13 00008000 00000000 1 1
14 00000000 00008000 0 1
15 00008000 00000000 1 1
16 00000000 00008000 0 1
17 00008000 00000000 1 1
18 00000000 00008000 0 1
19 00008000 00000000 1 1
20 00000000 00008000 0 1
21 00008000 00000000 1 1
22 00000000 00008000 0 1
23 00008000 00000000 1 1
24 00000000 00008000 0 1
25 00008000 00000000 1 1
26 00000000 00008000 0 1
27 00008000 00000000 1 1
28 00000000 00008000 0 1
29 00008000 00000000 1 1
30 00000000 00008000 0 1
31 00008000 00000000 1 1
32 00000000 00008000 0 1
33 00008000 00000000 1 1
34 00000000 00008000 0 1
35 00008000 00000000 1 1
36 00000000 00008000 0 1
37 00004000 00000000 0 3
Photo of setup.
Zip of captured data.
Miscelleneous plots.
Samples for ADC 1 were generated by a PCF8591. It incorporates a 256 level D/A converter which was used to supply a repeating ramp. Samples for ADC 2 were generated by twiddling a POT. One seconds worth of samples Edited to remove broken code link.