Hi I'm doing my first C program. I do know how to program in general having used other languages just coming up to speed with C. What I'm writing is a Pong program on a 2560 using 10K pots an a SSD1306 display. Progress is being made but I'm looking at noise issues. I'm not sure if it is the poor reference I'm using, noisy pots or wiring. I expect to find out soon with some experiments. I'm using the DEFAULT reference of 3.3V. I also the 3.3V power pin for my pots. I use about 1/4 of the spans of the pots for moving paddles. Full scale is 64 so when I first noticed noise, I just divide the reading by 4 to get a less noisy signal but no other filtering. I expect to see some bouncing of the paddles if on edge but what I'm seeing is occasional bouncing in both directions. This would indicate noise spikes of at least +-5 LSBs. I'm thinking of adding a capacitor to the pots but if my problem is reference noise, it will increase the noise instead of decreasing. If just input pin noise, it should decrease. I just thought I'd note the experiments that I'm looking at. Having the graphic output of what is going on is really a great way to look at things. If I had to look as a bunch of numbers, I know it would be more frustrating. Dwight
- I didn't see, but I assume you are using the analog pins to read the center tap of the pots.
- What are the values of the pots? I would hope around 50-100k.
- It is a good idea to have a cap (about 0.1 or 0.01uf) between the analog pin and ground. A few extra caps on the 5v and 3v3 rails would not hurt either.
you can take multiple readings of the pots - e.g. 8 - and average them to reduce the noise.
robtillaart: you can take multiple readings of the pots - e.g. 8 - and average them to reduce the noise.
I agree that in most cases, averaging multiple readings is a good thing. But I am not so sure that in a gaming situation, the time to do that 8 times would be good. Maybe 2. I guess it would have to be tested for the situation. I normally use a moving average (average the current reading with the previous results).
I understand the default reference of a Mega 2560 is 5 volts. If so, connect your potentiometers across the 5 volt supply. When I do that with an Arduino Micro I get no noise issues: the analogue-to-digital reading is constant (until I rotate the potentiometer of course). From my experience there's absolutely no need for a capacitor, nor to average the readings.
I guess your 3.3V has noise on it.
Did you use analogReference() in your script?
[quote author=jack wp link=msg=2415458 date=1443467620] Did you use analogReference() in your script? [/quote]No.
BTW: my Arduino Micro was powered from USB.
"I’m using the DEFAULT reference of 3.3V. I also the 3.3V power pin
for my pots."
The default on the 2560 is 5 volt.
If you are mixing 5v and 3v3 you should expect some variation.
Decide which one you want to use, and it should work lots better.
By default they measure from ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and analogReference() function.
I was under the impression that default was 3.3V but I could have misread it ( a common problem for me ). It is a 3.3V processor, although the digital out is 5V. The part I read said that 3.3V processors use 3.3V as default. It seems that I didn't look at the page mentioned: https://www.arduino.cc/en/Main/ArduinoBoardMega2560 I can easily move the pots to the 5V line. I thought I'd mentioned that I was using 10K pots but I guess I'd lost it someplace. Yes, I used: analogReference(DEFAULT); in my init. Working with these processors is a learning process. Thanks Dwight
We are all in a learning experience, one way or another.
Give that a try and let us know if it helps.
The Mega runs on 5volt, not on 3.3volt.
If you use default 5volt Aref, and connect your pots to 5volt, A/D value is stable (the tide rises all boats). If you use default 5volt Aref, and your pots are hanging on the (cleaner) 3.3volt, you get "noise". A varying 3.3volt will change A/D readings, but so will a varying ("dirty") 5volt Aref.
No need to call analogReference(DEFAULT); Unless you have used another analogReference before. Leo..
I tried moving from the 3.3V to the pot to the 5V to the pots. Still about the same amount of noise. Before trying averaging, I'll try to use some caps on the wipers of the pots.
And yes, I knew analogReference(DEFAULT); was not necessary but it is a handy place holder if I wish to change references. Dwight
Another think you may try, since you are reading multiple analog inputs (how many anyway), is a small delay between readings, on the order of
I use about 1/4 of the spans of the pots for moving paddles.
Is that 1/4 from one side of the pot from ground.?
If it’s from the edge of the pot, you could supply the pot with the cleaner 3.3volt.
And read the pot with 1.1volt Aref enabled.
The wiper of the pot has to output <1.1volt for this ofcourse.
It is almost 1/4. There is a little offset. I've still not determined that it is reference noise or just noise from the wiring. Adding the capacitors to the wipers should increase it if it is reference noise. I can also move to the internal 1.1V as you've mentioned. All experiments that require a little time ( I also have family requirements ). Dwight
If the pot is giving e.g. 0.5volt - 1.5volt when supplied with 3.3volt, there’s another option.
Make your own Aref.
Use a resistor between 3.3volt and the Aref pin, and call analogReference(external).
With e.g. a 33k resistor, Aref will be ~1.625volt.
Read the warning about using a resistor <5K.
I've tied a 104 ceramic from the wiper to ground side on each of the pots. The adjustment is rock solid. I can't get it to jitter, even if I really try. So, it would seem that my noise was just picking up noise on the wiring and pots ( just glued to a piece of ply wood ). I don't notice any lag in the pot to paddle on the screen so no time constant issue ( only about 200us ). My pong is working well but I keep tweaking it and breaking it. Right now it uses a lot of RAM. It takes two 1K arrays for the display. I've been thinking how to cut that down. The paddles only have a limited area they can be in and the ball can only move so fast. I could keep a moving window for the ball and a tiny paddle area. I have it so that the writes to the dislay are minimum. I use the auto x step and only write the page address as needed. If there is not change in a page-col, there is no write. To do that require a history method. Dwight