ADC MCP3204 measuring completely off?! - Page 1
Forum section: electronics / projects

author: Unknown
author_rank: Unknown
timestamp: October 30, 2018, 10:37:08 pm
content: HiI'm still working on my self made Lab PSU which was inspired by Daves µSupply.Most things work quite nice and I'm making good progress, however the ADC MCP3204 was giving me quite a hard time recently.I had this issue before but thought i fried something by back-EMF (is it called so?) by a high rpm DC motor when I didn't have a protection diode yet in my circuit.But now I got a new revision PCB from JLCPCB with a protection diode and some other improvements, soldered everything together and tested it and everything was good until suddenly the ADC was off again (don't know what i could possibly have done to trigger that).Ok, now some hard facts.- Schematic and board layout are attached- Oscilloscope shows some SPI noise from the display and the ADC on the ADC VREF and VCC but only a couple of mV peak to peak.- Oscilloscope and multimeter measure e.g. 5.7V on the output (bang on like set via the DAC/opamp control loop) and the ADC measures 8.295V through the opamp and voltage divider.- this seems to disappear when the circuit wasn't used for a couple of hours. after like 5 minutes the voltage which the ADC reads rises again.- it does not matter what voltage I set, the ADC is almost always way off. 3.3V show 4.955V on the ADC, 10.2V show 10.215V(! this works?!) but 12.285V show 17.7V on the ADC (wtf). 300 mV measure 700mV on the ADC. I always looked at the output voltage with the multimeter and the scope, it was always bang on and clean as a whistle so definitely the ADC is measuring garbage- i already tried to slow down the measurement to 1 measurement per second because I read that polling the ADC too often makes the readings go bonkers.Does anyone got an idea what's going on here? I have another version of this board on the way to me where I got rid of the external DAC and ADC and where I'm using the Teensy integrated ones, just for kicks to look what performance I'll get out of that. naturally this design got much cleaner and more slick so maybe I got rid of some noise problems there as well but nonetheless I'd love to find out whats going on here.If I missed something, if you need any more details, let me know. Kind of tired and it is likely that I missed something to point out.Thanks!EDIT!!!LOL I definitely forgot to mention where the signal the ADC measures comes from. It is the signals coming from IC11A and IC11B. Basically ALL ADC channels are off, they all measure wrong values so there seems to be some issue with the ADC itself. I didn't socket it and I don't think I have a spare (new) one here but I bet if I'd swap it out, the issue would be gone for some time.

author: MasterT
author_rank: Frequent Contributor
timestamp: October 31, 2018, 12:14:03 am
content: I wouldn't drive adc inputs directly from +15V powered OPA, capable to supply +-65 mA.

author: nemail2
author_rank: Regular Contributor
timestamp: October 31, 2018, 12:23:34 am
content: sorry, goofed up my other account (mail verification not coming).not even with the voltage dividers? any suggestions how to solve this?thanks!

author: MasterT
author_rank: Frequent Contributor
timestamp: October 31, 2018, 12:37:44 am
content: Resistive voltage divider is o'k, below 10k and you are safe and have accurate results with low sampling rate like 100ksps. If error still concern, keep sampling rate constant, though voltage drop caused by internal S/H of the adc 'd be constant and easily calibrated out.For perfectionists, than resistive dividers you simply buffer with OPA powered by same PS line as adc.

author: Dave
author_rank: Super Contributor
timestamp: October 31, 2018, 01:22:14 am
content: This may be a really dumb suggestion, but you might as well check it just in case:Check if the IC is properly soldered to the board.I once spent a day and a half dicking around an ADC that would spew erratic measurements, only to find that the QFN chip wasn't sitting quite as flat as it should have been. There was the slightest gap between that particular input's pad and its respective land on the PCB, just enough to let the surface contamination let *something* through and give me seemingly random results.Learn from my mistakes!

author: hli
author_rank: Frequent Contributor
timestamp: October 31, 2018, 02:39:49 am
content: Assuming that you actually measured that the value at the ADC input is what it should be: when the wrong values are all over the place, I would guess at a software problem. The readings seem to be more or less stable (apart from that 'when its not used' part), but the error is not linear or something like that. Are you sure that the code converting the ADC output to a voltage is actually correct? Can you debug the raw and the calculated values to see whether they are what they should be?

author: nemail2
author_rank: Regular Contributor
timestamp: October 31, 2018, 09:25:54 am
content: Quote from: MasterT on October 31, 2018, 12:37:44 amCurrently I have 100k/25k divider, maybe that's the problem? You say I should lower the values to like 10k/2,5k? Could try that...Quote from: Dave on October 31, 2018, 01:22:14 amDefinitely a good advice, I'll check that. However I'm not very confident that that's the issue. Two PSUs, same issue, quite experienced in soldering, huge DIP packages - don't think I messed those up. But as I said, I'll definitely check that.Quote from: hli on October 31, 2018, 02:39:49 amYes, I measured at the ADC input pin, voltage was bang on correct. For 3.3V out it was 660 mV (100k/25k divider). ADC however measured (RAW data) about 991 mV. Software takes the raw value and multiplies it with 5 (100k/25k divider) which exactly gives me the errorneous 4.955V which I see on the display.Don't know what could be wrong in software as this works for the first 5 minutes if the PSU was turned off for a few hours. Also I have the 12 Bit ADC (4096 steps) and the 4.096V voltage reference so there is basically no math happening which could go wrong. Only thing I do is multiply the raw ADC value with 5 because of the voltage divider...

author: mk_
author_rank: Regular Contributor
timestamp: October 31, 2018, 10:16:04 am
content: I would say: GND should beone- and olnyone- plane.And - connect those GNDs at the ADC as short as possible.There are some powersupply-pins not connected at the MCU-schematic....Powerup-Sequenze is within specs?SPI-Timing is correct? No glitches on any signal? I would expect a lot of nasty noise because of your large GND-loop from levelshifter to ADC...good luck - btw - send me an PM if some further help required, I`m located in AT-49xx area

author: nemail2
author_rank: Regular Contributor
timestamp: October 31, 2018, 11:27:13 am
content: Quote from: mk_ on October 31, 2018, 10:16:04 amHi,thanks for the offer, I might come back to this soon :-)@Ground: I tried to make digital ground and analog ground and connect them at a star point. That's why it is like it is. I wanted to avoid digital noise in the analog output as much as possible (but my knowledge is very limited, to be honest). The ADC has a direct connection to digital ground (that's where the MCU board sits), you can see that direct connection on the board layout PDF.@MCU ground/powersupply pins: The MCU has internally connected all ground pins, I did not want to create loops through my PCB by connecting all grounds together which are already connected on the teensy board. also I don't use the 3.3V rail of the teensy integrated voltage regulator, i have a dedicated TO-220 one for the display and the W5500 ethernet module.Regarding powerup sequence and spi timing I have to admit that I neither know (yet) how to measure that nor how to check if the values are good or not.I'm not sure what could go wrong here, besides something like noise as you said. however the values are static, I don't have something like "flickering" in the measurements so for me that kind of means it can not be a noise problem on the SPI between the level shifters and the ADC, otherwise there would be just random complete crap readings or am I mislead here? The read value for set 3.3V is always quite exactly 4.955V, that would be some kind of very strange (consistent, periodically always the same) noise I think.I'm from AT-2xxx area, so quite far away from you unfortunately

author: mk_
author_rank: Regular Contributor
timestamp: October 31, 2018, 11:44:36 am
content: Quote from: nemail2 on October 31, 2018, 11:27:13 amSW is ok? No summingerrors after some minutes because of some kind of overrange inside some register?Can you decode the SPI-stuff with a logicanalyser so that you can locate the problem if it is on the ADCs or at the uc - side?

author: nemail2
author_rank: Regular Contributor
timestamp: October 31, 2018, 11:58:04 am
content: Quote from: mk_ on October 31, 2018, 11:44:36 amThat's a good idea, I'll do that. Thanks! I have a chinese ripoff salae logic analyzer and an SDS1104X-E scope, one of them will manage to capture the SPI data and decode it.strange thing is, though: NOW the issue starts after a few minutes. right after I finished soldering everything together, everything worked for days(!). So it seems to me like something got damaged. Literally nothing changed, suddenly errorneous readings after a few minutes where there were no wrong readings for hours earlier. Very strange and I'm very excited to find out what's wrong here :-)

author: mk_
author_rank: Regular Contributor
timestamp: October 31, 2018, 12:47:15 pm
content: Quote from: nemail2 on October 31, 2018, 11:58:04 amESD

author: nemail2
author_rank: Regular Contributor
timestamp: October 31, 2018, 01:28:35 pm
content: yeah might be.. although i'm quite cautious and i've never lost a device to ESD, until now... but there's always a first time.the whole case is printed of PET-G, maybe the case got charged up. I'll try to put ESD bags everywhere beneath the mainboard so it won't be exposed to the case anymore and see if that helps.didn't think of that yet..thanks again!

author: nemail2
author_rank: Regular Contributor
timestamp: November 05, 2018, 04:47:16 pm
content: success :-)after hooking up my scope, i noticed that SPI to the ADC was at 10 MHz, regardless of what clock divider was set in the code. So I changed the ADC library to use SPITransactions (https://www.arduino.cc/en/Tutorial/SPITransaction), set the frequency to 1 MHz and that solved my issue. Readings are bang on again.Thanks for the hint to try to decode the SPI data :-)What I'm still curious about: Using the scope and decoding the SPI, I was reading the correct values using the scope but the software did have the wrong values. Not exactly sure how this is possible, assuming the Teensy 3.5 + the library didn't have any issues with 10 MHz. Clearly the correct values were visible on the SPI bus.Only thing I could imagine, is that the TXB0104 level shifters flipped some bits at that frequency. However they're rated for 100Mbps data rate at 3.3V on the lower voltage side so I'm not really sure here either.Anyway, glad it works now and thanks again for your suggesstions!

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 05, 2018, 05:51:33 pm
content: Quote from: nemail2 on November 05, 2018, 04:47:16 pmIt's possible that you're using the wrong SPI mode (there are 4). A very common issue with SPI devices which all seem to be implementing a different modeThe timings (setup/hold time) could still be within specs with the wrong mode at 1 MHz but not at 10 MHz. Just a thought.

author: nemail2
author_rank: Regular Contributor
timestamp: November 05, 2018, 06:57:18 pm
content: Good point, I am now using mode 0,0 which is supported by the MCP3204. However I have no idea what mode was used before I made the changes.