Custom Arduino Zero board ADC Problems - Page 1
Forum section: electronics / general

author: HappyBanana
author_rank: Newbie
timestamp: March 18, 2017, 07:19:59 pm
content: Hello,I created a custom arduino zero pcb that uses a few analog pins.The micro controller functions perfectly, but the ADC pins are never able to read a 0. When an analog pin is pulled low, the ADC always reads a value of 3 or 4 and sometimes 5. Does anyone have any guesses on why this would happen? The pins are definitely not floating, when pulled high I get 1023 and when pulled low I get 3 or 4. Attached is a image of the board, probably useless but worth a shot.Thanks,Tyler

author: Nusa
author_rank: Super Contributor
timestamp: March 18, 2017, 07:40:05 pm
content: Pulled low or actually connected directly to ground? What do you get if you connect the input to a ground pin?

author: HappyBanana
author_rank: Newbie
timestamp: March 18, 2017, 07:42:11 pm
content: No matter how I get it to 0V it always reads 3,4, or 5. Directly to gnd, through a 10K resistor, or connected to a digital pin pulled low all achieve the same result.

author: Lovely_Santa
author_rank: Contributor
timestamp: March 18, 2017, 09:19:36 pm
content: Quote from: HappyBanana on March 18, 2017, 07:19:59 pmI'm not familiar with arduino zero... but does it use an internal ADC or an do you use a seperate chip? It would help if I had a datasheet at hand...Quote from: HappyBanana on March 18, 2017, 07:42:11 pmWithout the datasheet I came up with some things:Some (read as: most of the affortable ADC's) have an offset on the lower line, so it won't show an absolute 0 read, or at the upper line, so not showing the max value (on your case 1023, it depends on number of bits, 10 in your case)Wat is your voltage reference versus the max voltage reference that you may apply? If you aren't using the full reference, or a prefered reference, you can't just apply the datasheet, but you will have to interpolate the values (mostly just linear between your and the datasheet value's)Did you short the pin directly near the ICs package to ground? Sometimes the noise in the air and nearby pads on a PCB, and the natural capasity of your PCB is enough to have a small static voltage on your input of your ADCI know you said you shorted the pin directly, but just keep in mind, when you connect an IC (directly or indirectly by a wire), this value will even rise more, becose ICs are noisy on there own.I always calculate this effect by measuring different analoge voltages on my final design, so I convert the readed input voltage to a digital number, and then I apply a correction factor... Just in software, easy fix, and when your designs get bigger, it's easy to correct by just recallibrating your correction factorHope this helps a bit,Lovely Santa

author: HappyBanana
author_rank: Newbie
timestamp: March 18, 2017, 10:10:47 pm
content: The chip is the ATSAMD21 (http://ww1.microchip.com/downloads/en/DeviceDoc/40001882A.pdf)It uses an internal ADC. I am using the logic voltage as my reference so AREF is not set, making that 3.3v, or more precisely, 3.27v. The pins directly next to the analog pins I am using are also used for other purposes, so they are not always connected to ground. Hopefully the values are consistent and I can compensate in software.Thanks,Tyler

author: senso
author_rank: Frequent Contributor
timestamp: March 19, 2017, 01:36:20 am
content: Make sure the inputs are turned into well, inputs, and that pull-up resistors are off.And if they share ISP/JTAG functionality, and IF you are using a bootloader, try disabling those features.

author: obiwanjacobi
author_rank: Super Contributor
timestamp: March 19, 2017, 06:27:16 am
content: Quote from: HappyBanana on March 18, 2017, 10:10:47 pmIs AREF connected to anything? I seem to remember that is always a good idea...What is the voltage you measure on the chip leads itself? If that is 0V then its an internal problem. If not, you're picking something up along the way...

author: ajb
author_rank: Super Contributor
timestamp: March 20, 2017, 01:21:20 pm
content: It may be helpful to show your schematic.The SAM D series ADCs have a calibration register that should be loaded with values from production testing which are stored in the NVM--I would hope that the arduino libs do this for you when initializing the ADC, but worth checking.They also have gain and offset correction registers which can be used to further improve ADC accuracy. It's up to the user to provide the correct values for these registers, which may be used to a certain extent to calibrate for external hardware as well as variation between different MCUs.The SAM D ADC is inherently differential, and when used with single-ended signals you must still select the appropriate negative input mux connection via the MUXNEG field in the INPUTCTRL register. Selecting internal gnd or IO gnd might give different results. (The DIFFMODE bit in CTRLB actually only controls whether the result is singed or unsigned; the datasheet does not make this clear.)

author: danadak
author_rank: Super Contributor
timestamp: March 20, 2017, 02:22:52 pm
content: Actually the results you are getting seem quite good, based on specs.The 15 LSB error shown in table.Right click, open image in new tab, to see image.Regards, Dana.

author: Lovely_Santa
author_rank: Contributor
timestamp: March 21, 2017, 09:56:30 pm
content: Quote from: HappyBanana on March 18, 2017, 10:10:47 pmHow do you connect your logic voltage (3.3V nominal) to your Vref? I would recommend to use a zener diode or linear voltage regulator. Those are stable, meaning low noise on the reference voltage. When you don't have a higher voltage (to use a zener or regulator), connect it directly to the VCC pin of your controller, and put a 100nF decoupling capacitor withing a close range of the Vref pin.Quote from: ajb on March 20, 2017, 01:21:20 pmIf you are a beginner or don't like to program, I would recommend to use the libraries for that, but I find that these libraries have a decent amount of overhead. Not that the library isn't good, it is very efficient, but it will never be as good as writing your own code, specific for your uses. So when you have big programs, running almost to the maximum space inside your microcontroller, I would recommend to write it yourself.Quote from: ajb on March 20, 2017, 01:21:20 pmIf you have specific questions on how to implement it, a schematic would be helpfull... I can only provide as much info as you are telling meOr your code can help too... But I think you can do it, (I believe that)Greets,Lovely Santa

author: Seekonk
author_rank: Super Contributor
timestamp: March 29, 2017, 09:35:59 pm
content: "How do you connect your logic voltage (3.3V nominal) to your Vref?"Just for reference for others, that can be very dangerous to program as it may directly connect to 5V if that is used for the micro power.

author: HappyBanana
author_rank: Newbie
timestamp: April 20, 2017, 11:41:19 pm
content: Hello,After quite a bit of testing I am still unable to get the proper ADC readings. The code works perfectly on a Arduino UNO, it is literally just reading the ADC so I doubt that is the problem. I am fairly new to pcb design so its probably something I did. I published a schematic, gerber files and kicad files on github if anyone wants to take a look.https://github.com/spadgenske/rbt-boardThank you!

author: Buriedcode
author_rank: Super Contributor
timestamp: April 21, 2017, 12:27:16 am
content: Well the UNO uses a different device - namely an atmega328. You're using the SAMD21, so apples.. oranges.. If you're getting different readings on an Arduino Zero (which uses the same device) then I would say it is indeed layout or power-supply filtering.Look at the variables:Device - including revision.PCB layout.External parts.Power supply.Any/all of those can cause an ADC reading to jump about, or have a large offset. The most obvious being the first - ADC's in microcontrollers can have a fixed offset which is usually calibrated out (that is why manufacturers can include a calibration word on NVM).ADC's in micros do not always read 0 when the input pin is tied directly to ground, for several reasons, most of which have already been covered in the thread. There is also internal interference - which is why to reduce 'noise' in readings app notes sometimes recommend disabling other peripherals or slowing down the clock during ADC reading.