
Purple
USA
Asked
— Edited

I have about 5 adc units of noise on my 256 adc analog inputs. Also the battery voltage and cpu temperature are noisy. I have checked my incoming battery voltage and it is steady. I tried to filter the analog inputs but no luck there. Thanks
oops I guess I can not go back and fix my typo in the title.
A slight voltage drop is normal and will look like fluctuation. When the battery is under load the voltage will drop, this can sometimes be by quite a lot. 0.3v is very slight.
As for the CPU temperature, how much does it fluctuate and how often? Again, is this while the EZ-B is carrying out tasks or while sitting idle?
If you see the values of the ADC moving, that is because the input is moving.
For example, the battery supplies a specific voltage at varying consumptions. So if your robot is consuming power, the voltage will vary. Additionally, the temperature of the chip with vary with usage.
Any adc input you provide to the ezb may have some fluctuation (which is not noise). The adc ports of any chip are not able to internally generate a fluctuation because they are floating. That means they are internally separated from a digital source and connected to the adc buffer during power on configuration. The dma and peripheral settings configure the ports on power on.
Please examine your input for voltage fluctuation. You can either use our adc on the ezb, or an external device such as an oscilloscope.
Additional information on adc and voltage fluctuation caused by consumption demand can be found on google.
Digital Multimeters are likely not to update as fast as an analog pin will, so the noise you are describing is likely correct. The adc values do not show you an average like a Mulitmeter will but instead they will give you an instantaneous snap shot.
Even though you are trying simulate without a load inherently the EZ-B itself draws a load since we have an audio amplifier, camera and WiFi module that all need to be powered up from 3.3V, so unfortunately you can't really simulate a no load situation with the EZ-Bv4. Particularity with the WiFi module, the transmission power (aka current consumption from the battery) will change with signal strength as it tries to boost power to get a better signal.
Grounding out an adc line does not guarantee that you will have a value of 0 as there are always variations on the ground line as well (albeit usually small) but they are there. DJ proved this to me a couple years back by simply doing stall current sensing by attaching an adc line directly to ground and was able to get readings.
My suggestion is that if you aren't comfortable seeing these instantaneous readout fluctuations is to then do some averaging on the code side. For example take 10 samples of an adc port add them together divide the sum by 10 and then input that value into your conditional statements to get a stable value.
I have used this method in the past with other microcontrollers, like Arduinos, when I wanted a stable adc value.
One other thing to keep in mind is that adc lines have a lot less fluctuations when fed a constant voltage source, so try placing a sensor on an adc line and see what values it gives you, they should be pretty stable as long as the sensor is in a steady state.
Keep in mind that the temperature voltage which you are witnessing is actually built into the STM32 ARM Microcontroller and not an external sensor - if you feel STM has issues with their chips that are being used in nearly every smart device around the world, they have a very active forum with a great community who will be able to explain in greater detail how a raw unaltered ADC reading is more accurate than your multimeter.
I would recommend learning another microcontroller and writing a small program to display ADC voltages from varying sources to witness the fluctuating values. However, you would get the same results as if using the EZ-B
As jeremie recommended, using multiple samples and averaging the values is one way to smooth a fluctuating input. However, another way that uses less processing (and how multimeters work) is to use a small capacitor to filter voltage fluctuations.
Also, I should add that many digital devices which have a DAC or PWM to simulate an adjustable voltage range will be funny with a raw ADC input. You would very much need a small capacitor on any PWM or DAC generated voltages. I imagine you can suspect why
I also noticed that the farther the switch or pot is from the EZB's ADC port the higher the ADC reading be (or was it lower? Cant remember now). I think it was about two to three feet of wire. Then when the switch was thrown the reading wouldn't hardly move. I figured this was due to the resistance of the wire. I solved this by bringing the switch closer the ADC port but it was a pain and a disappointment as I had to redesign. This is probably a totally different cause then what Purple is seeing but I thought is was interesting to mention in this context.
@DJ, your suggestion of a small cap is interesting and sounds like a simple solution. How would you wire this cap into the ADC circuit? Signal pin to Ground pin? Would you need to do this to each port being used where you need a steady signal?
As for analog sensors (i.e. accelerometers, sharp IR distance sensor, etc..) do _not_ use a capacitor.
My old battery monitor wouldn't have much fluctuation either but the script for this used ranges rather than specific values (i.e. battery percentage 100%, 80%, 60% etc.) so I guess I wouldn't have even noticed the fluctuation in the voltage.
The question should not be "EZ-B has noisy ADC"... The question should be "EZ-B v4 has very accurate ADC"
Now on my V4 there is no way to filter this noise. I have tried.
Any suggestions on how to get my analog inputs on my V4 to perform as well as they do on my 2 V3s ?
Thanks for the help.
Code:
This is a more economical method.
Code:
You could, if you wanted to, increase the number of readings easily by changing the 10 in the repeatuntil and the 10 in the $ADCValue = Round($ADCValue/10,2)
You could also go for more or less decimal places by changing the 2 in the Round($ADCValue/10,2)
You may even be able to remove or reduce the sleep(10) or increase it if you aren't checking every 100ms.