Go Down

Topic: Extremely inconsistent analogRead() on Nano 33 IoT (Read 869 times) previous topic - next topic

Antyos

One of my Nano 33 IoT projects incorporates reading the position of a potentiometer--pretty standard stuff. I noticed that the analogRead() values seemed a bit more jumpy than other Arduino boards I'm familiar with. I uploaded a simple program to print out the analogRead() value and removed all the components except a wire connecting the analog pin to ground. I found the value couldn't even stay at 0 for more than a few lines at a time and would frequently jump as high as 25.

I did some research and came across similar issues with these boards, such as the voltage issues described here: https://forum.arduino.cc/index.php?topic=650488.0 From this, and similar posts, I would expect the Arduino to at least give somewhat consistent readings when plugged into USB, but I can't even get that. I must say that I'm disappointed in the quality of the boards. I expected more from a first party Arduino board.

The one thing I have yet to find a solid answer to, which is why I'm posting this -- what can I do about it? I know I have seen people mention adding filtering code to some degrees of success. Is that the best option? Should I add a capacitor somewhere? Is there an alternate board that doesn't have these issues?

Thanks,
Andrew

ballscrewbob

Some things will depend in the exact parts used and the wiring.
Most Arduinos can be prone to external noise so good cable practices should be employed such as screened cable and as with guitar pots a ground to the pot case if it is metal.
Always use shortest cable runs where possible or add small ferrites on longer runs.

A stable and consistent voltage and current is a must and should also take into account the requirements of any other attached devices that may pull or cause a small voltage spike.
If you have anything like that connected then a capacitor on the supply line to that device may help smooth out the spikes.

Could you also take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.

Posting tips.
  • Your OS and version can be valuable information, please include it along with extra security you are using.
  • Always list the version of the IDE you are using and the board version if applicable.
  • How to insert an image into your post. ( Thanks Robin2 )
  • Add your sketch where applicable but please use CODE TAGS ( </> )
  • Add a SCHEMATIC were needed even if it is hand drawn
  • Add working links to any specific hardware as needed (NOT links to similar items)
  • Remember that the people trying to help cannot see your problem so give as much information as you can


Bob.

It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

Klaus_K

The ADC of the SAMD21 microcontroller on the Nano 33 IoT has a differential input. Theoretically you should be able to measure your signal against the boards voltage and therefore remove the ripple.

If you like to try that I would be happy to help test some code, if you can get started.

Antyos

The ADC of the SAMD21 microcontroller on the Nano 33 IoT has a differential input. Theoretically you should be able to measure your signal against the boards voltage and therefore remove the ripple.
Thanks! I was hoping you'd reply since you seem knowledgeable of the board (I just wish I had remembered to look back at this thread sooner).

That actually makes a lot of sense why I was getting those strange readings; I assumed the ADC worked like the Uno's. How do I set the other pole of the differential input? I'm using two pots, so do I need to have two additional lines to ground/vcc? Which pin(s) do I need to connect?

Thanks,
Andrew

Klaus_K

I did a few experiments and even though I managed to get some differential readings there is still a lot of noise in the result. The ADC has a lot of settings and features I did not try and I do not feel like spending a lot of time on that issue.

If you like to try. You will need to have a look into the following file

C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.4\cores\arduino\wiring_analog.c

I created a copy of the analogRead function and modified that.

There are some disadvantages in using the differential input. One is that the voltage range is smaller. So there is some additional complications for something that should be a lot simpler.

Antyos

I did a few experiments and even though I managed to get some differential readings there is still a lot of noise in the result. The ADC has a lot of settings and features I did not try and I do not feel like spending a lot of time on that issue.

If you like to try. You will need to have a look into the following file

C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.4\cores\arduino\wiring_analog.c

I created a copy of the analogRead function and modified that.

There are some disadvantages in using the differential input. One is that the voltage range is smaller. So there is some additional complications for something that should be a lot simpler.
Thanks! This seems a bit more complicated than I assumed. It's not outside my capabilities, but definitely seems like it's more trouble than it's worth. I think I'm going to find an ADS1115 external ADC to use, as it seems simpler to use and hopefully won't have the same noise issues. I can't believe there isn't an easier way to get native analog input on the Nano 33 IoT.


Thanks,
Andrew

KaiMatzen

I posted in Nov 19 some trouble with extrem noisy 3.3 - onboard voltage - until today an open issue ...
The onboard voltage is horrible noisy, because the pcb design rules of the MPM3610 are ignored :-((

The boards habe an heavy mistake in design of the voltage regulator, so I think you can't use these boards for analoge measurements.

Workaround for me:

1. Don't wire the Vin, let this pin float.
2. Take an 3.3V constant voltage regulator (UA78M33) and wire him at pin Vout of the board

.. so you can use the microcontroller at specs.



Luisonson

In order to get a better 3.3V line, you should desolder R9 (39K resistor from AAM pin of the mpm3610 to ground). That will make the mpm3610 works in ccm mode always, which is the low noise mode.

Luisonson

I posted in Nov 19 some trouble with extrem noisy 3.3 - onboard voltage - until today an open issue ...
The onboard voltage is horrible noisy, because the pcb design rules of the MPM3610 are ignored :-((


Which mistakes? You can desolder the R9 resistor but other than that, the rest seems ok. :?

Klaus_K

Which mistakes? You can desolder the R9 resistor but other than that, the rest seems ok. :?
Have a look at the MPM3610 datasheet. There are PCB Layout Guidelines (page 19), that the PCB does not seem to follow.

Luisonson

Have a look at the MPM3610 datasheet. There are PCB Layout Guidelines (page 19), that the PCB does not seem to follow.
Yes, is not as clean and close as the datasheet, but I don't think that is the problem. I think the mpm3610 is working in AAM mode that has a huge noise. Please, desolder R9 and check again.

floater

#11
Mar 05, 2020, 01:21 am Last Edit: Mar 05, 2020, 01:28 am by floater Reason: Embedding images in the text
I'm just starting out with this board and, like Antyos, I need to measure the voltage from a pot and am having problems with noise. Other boards that I own do not exhibit the same behaviour. I tried Luisonson's suggestion and thought I'd feedback my findings.

I created a very basic sketch that simply reads analog pin A0 and writes the value to the serial port while pin A7 is HIGH. The only additional circuitry I added was a jumper wire going from pin A0 to ground or the 3.3V output, and the jumper wire for taking A7 HIGH.

I'm using Arduino IDE 1.8.12 in Windows 10, and watching the values stream past in the serial monitor or serial plotter. The board is powered by a short micro USB cable from my PC.

Doing 10 bit ADC with pin A0 tied to ground, the values are very noisy, regularly exceeding 30 and ocassionally exceeding 45, although most are below 5. When I tie A0 to the 3.3V output, I get similar amounts of noise.

I'm not sure I have the skill to replace R9 if I had to put it back so, instead of desoldering it, I manually shorted it to ground with a breadboard jumper wire. There was no subjectively discernable difference in noise. Here is an image of where I think R9 is, in case anyone wants to correct me:



I also tried powering the board with a range of voltages between 5 and 16V to the Vin pin, instead of by USB. No difference. And I tried different USB cables.

The only improvement I have found so far, without meddling with settings in wiring_analog.c or exploring differential measurements, is by adding a 10k resistor between the voltage I want to measure and pin A0. It gives a significant reduction in noise, but not enough. The first image is with A0 tied to ground, and the second is with A0 tied to the 3.3V output:






Is it likely that the Nano 33 IoT can be made to perform as well as other arduinos, or is it junk in terms of ADC? If the latter, I need to decide pretty quickly to switch to something else.




Luisonson

I'm not sure I have the skill to replace R9 if I had to put it back so, instead of desoldering it, I manually shorted it to ground with a breadboard jumper wire. There was no subjectively discernable difference in noise. Here is an image of where I think R9 is, in case anyone wants to correct me:



Hello Floater,
The R9 is the only 39K resistor in the board, so with a multimeter should be easy to find it.

R9 resistor connect AMM pin (18), of the mpm3610, to ground. That AMM pin has to be high or floating to force the mpm3610 to work in CCM mode. Conecting that pin to ground force the oposite! Always high noise.

So... Connect a wire from vcc to the mpm side of the resistor... Or remove the resistor that is perfectly ok if you don't need super low consuption.

Thanks for testing. Waiting for your new tests ☺️

floater

#13
Mar 05, 2020, 03:17 am Last Edit: Mar 05, 2020, 03:19 am by floater Reason: Embedding images in the text
R9 resistor connect AMM pin (18), of the mpm3610, to ground. That AMM pin has to be high or floating to force the mpm3610 to work in CCM mode. Conecting that pin to ground force the oposite! Always high noise.

D'oh! Of course! Apologies. And thank you.

I just double checked the resistance of the resistor I highlighted. R38.67. Looks like not everything I've done this evening is a silly mistake :-)

I've tried taking it high now and sadly, I can't see any difference:


Luisonson

I've tried taking it high now and sadly, I can't see any difference:

Wow!, I didn't expect the same result with the MPM3610 working in AAM mode and in CCM mode... That's super wird... but the results are clear  :smiley-sad:

Thank you for testing.

Go Up