Why disable the SPI peripheral at all? Provided there's no actual SPI communication being performed when the ADC is working, there will be no switching and therefore no noise.
Well, the theory was that since I saw all kinds of noise showing up on my oscilloscope when the SPI was sending bits to the LCD, that some of that noise would also find its way to the ADC. Here's what my scope shows when I probe one of the ADC input lines. Yuck!
![](http://turkish.smugmug.com/Electronics/Sync/i-Pn7wsxk/0/M/CA_12311208062793-M.jpg)
This project uses the STM32's DMA to feed data into SPI. Basically, you set up the DMA channel with a pointer and a byte count and then it feeds data directly to the SPI peripheral without CPU intervention. So even though the CPU is off doing something else, data is still being sent to the LCD. The ADC works the same way--via DMA transfers, so keeping these two parts of the chip from stepping on each other was a little tricky.
Here's a logic analyzer trace showing SPI activity (look at SCK) occurring at the same time as the ADC is taking samples (when the top trace is high):
![](http://turkish.smugmug.com/Electronics/Sync/i-Gvr2hf9/0/XL/Screen%20Shot%202012-12-31%20at%207.39.23%20AM-XL.png)
I tweaked the code so that just before the ADC takes a reading, the SPI peripheral is disabled. Note that the SPI won't necessarily shut down right away if it's in the middle of transmitting a byte. There's a slight overlap at the beginning of the ADC period, and the ADC collects an extra "dummy" sample at the beginning to skip over that part.
Here's a trace showing SPI being suspended before each ADC run:
![](http://turkish.smugmug.com/Electronics/Sync/i-f6ktCvf/0/XL/Screen%20Shot%202012-12-31%20at%207.40.23%20AM-XL.png)
There's a very slight overlap at the beginning while the SPI clears its transmit buffer. After that, SCK goes low and MOSI (for whatever reason) goes tri-state and/or high depending on which tool is used to measure it.
The $64K question is whether this trick improves the ADC measurements. Unfortunately, my "lab" is a little limited and the best tool I have for generating signals is a DG1022 function generator. Setting it to put out a DC voltage at about 50% of what the board's input stage can handle looks like this on the scope:
![](http://turkish.smugmug.com/Electronics/Sync/i-G6F7bRL/0/M/CA_12311207491745-M.jpg)
I put a T-connector on the output of the DG1022. One side of the T has a 50-ohm terminator and the other side is a short length of BNC that runs directly into the scope's input. The function generator's output impedance is set to 50 ohms. The result is about 8mV of high frequency noise on top of the DC signal.
The board's firmware now lets ADC and SPI overlap by default, but if you press one of the buttons, it separates them (the change only occurs between screen updates). To test the board, I leave the T and the terminator in place and use a BNC-to-alligator cable to apply the signal to one of the board's sensor inputs. Here's what that DC signals looks like with ADC overlapping SPI:
![](http://turkish.smugmug.com/Electronics/Sync/i-3xLrftv/0/M/CA_12311207432476-M.jpg)
Here's what Rigol's version of DC looks like when ADC and SPI *don't* overlap. Note the finger on button #4:
![](http://turkish.smugmug.com/Electronics/Sync/i-XMQJ2fD/0/M/CA_12311207434056-M.jpg)
They look pretty much the same to me. Here's the same experiment using a 10mV square wave as generated by the DG1022. First, how it looks to the scope:
![](http://turkish.smugmug.com/Electronics/Sync/i-Wktk5kH/0/L/CA_12311210545741-L.jpg)
How it looks to the board without SPI noise reduction:
![](http://turkish.smugmug.com/Electronics/Sync/i-ftJ49Xp/0/M/CA_12311210552003-M.jpg)
And with the noise reduction:
![](http://turkish.smugmug.com/Electronics/Sync/i-X746wJN/0/M/CA_12311210582692-M.jpg)
There might be a difference, but it's not very big. I still have
screen shots of previous experiments that showed more objectionable noise, but I can't recreate those results now, and I can't explain why they happened either (very annoying).
At any rate, I think I've been chasing my tail on this noise "problem" and will put it aside for now. Measuring single-digit millivolts (reliably) is proving to be a challenge with the equipment I have.
The next spin of this board will have the LCD connector the right way up, and won't require the LCD breakout board and the shameful bodge wires, which can't be helping the situation.