AnalogRead(0) With 50K Potentiometer

Status
Not open for further replies.

Dan

Active member
Hi,

I am using Teensyduino 2.0 and have to use a 50k potentiometer (logarithm) from a pedal.

I can't get a decent and smooth reading byt the Teensy.

How can I improve this? (I am a begginer)

Regards,

Dan
 
I assume you wired the pot properly so that one pin is supply (which is the reference for the ADC), the wiper is to the ADC channel and one is to GND ?

If you have long wire (more than a couple of inches) from the Teensy to the pot, then you are probably picking up interference and also 60 Hz noise. You can filter physically by adding a capacitor at the Teensy pins - 1 uF (from the ADC pin to GND) would work. You might also add a similar capacitor across the two outside pins of the pot.

If the wires are very long, then you will need shielded wire -- stereo audio cable might be good.

If that doesn't work, then do averaging in software -- read the ADC multiple times and then average the results. in particularly noisy situations where 60 Hz is very troublesome, taking those readings over an interval that is precisely a multiple of 1/60 (i.e. a multiple of 16.667 ms) will give even more rejection.

Also -- why use a log pot ? they are harder to find than linear ones, and if you get the outside terminals swapped, the 'log' is backwards. Use a linear pot, convert with the ADC, average and then do log() {remember log() on Arduino is ln()}. Instead of using 3 wires, you can use a (say) 10k R from supply to the ADC pin, and wire pins 1&2 together on the pot to that pin, and pin 3 of the pot to GND -- uses 2 wires instead of 3. The equation to convert pot position to log(x) needs a little manipulation.
 
Since you mention 'from a pedal' I'm going to assume that you are trying to connect a guitar or keyboard expression pedal to your Teensy. Also, as you mentioned being a beginner, it may be useful to read up on pots from that perspective:

Resistors and Potentiometers used in Expression Pedals
All About Expression Pedals

So, you probably have the wiper from the pot (the centre terminal) connected to your Teensy. The first thing to check is that you also connected the ground from the pot (the end not connected to positive voltage) to ground on Teensy. Otherwise, you will just get random readings. Voltage is a difference in electical potential, and it is measured relative to a fixed point, usually ground. Also, check you are reading from the analog pin you are actually connected to :) (this sounds silly, but I have done it myself and again you just get random readings).

If that is all good then your readings should at least be changing as you move the pot.

Next thing to check is your power and how clean it is. 5V from USB connected to a computer has a lot of digital noise on it. Capacitors can help with that, as mentioned earlier in the thread. Using battery power, which is common in pedals, can also help. 3 AA batteries will give you a clean +4.5V. Or a PP3, which is often found in guitar pedals, will give you +9V which is too much for Teensy. But you can still use it - take the wiper output via two resistors (say, 10k - the value is not critical as long as they are both the same) to ground, then connect the point where the two resistors join to your Teensy. This is a voltage divider, the maximum +9V is now halved to a maximum of +4.5V.

Using a screened cable will, as mentioned earlier, help avoid hum pickup. If you are using battery power then a simple tip-screen (two-pole, 'mono') guitar jack cable will be fine as a connection. If you are using +5V from Teensy then a tip-ring-screen (three-pole, 'stereo') jack cable with two core sheilded wire will be better.
 
Also -- why use a log pot ? they are harder to find than linear ones, and if you get the outside terminals swapped, the 'log' is backwards.

I suspect that 'from a pedal' is the key here; the log pot is already in a foot pedal. Changing it would require some soldering and mechanical skills to re-connect the shaft gear to the gear on the pedal.
 
Yes, it is an expression pedal for music.
It is 50k logarithm. I have to deal with that.

Is there any function in arduino to invert the LOG?

What kind and value of condenser do you advice

Do you have an example of code to retain the average of the adc pin evry 10 or 15 milliseconds?

We want the pedal to stay reactive with a low latency who seems imediate to the user.

Thank you for your help, and long live to this wonderful community.

Tennsy is AMAZING !
 
Yes, it is an expression pedal for music.
It is 50k logarithm. I have to deal with that.

Is there any function in arduino to invert the LOG?

What kind and value of condenser do you advice

Do you have an example of code to retain the average of the adc pin evry 10 or 15 milliseconds?

We want the pedal to stay reactive with a low latency who seems imediate to the user.

Thank you for your help, and long live to this wonderful community.

Tennsy is AMAZING !

OK, a 'log' pot actually is exponential -- the pot divider ratio is exponentially dependent on the angle -- something like:

VOUT = VREF * k * exp(angle/j); k & j are scaling factors

where angle is in degrees and an angle may vary from (say) 0 to about 270 on a real pot. In your case, unless there is a lever, I suspect the pot's angle doesn't change that much. k is likely between 0.1 and 1, and j might be 360 or 270 (for angle in degrees)

So, if you want to get the angle, you have to invert this equation.

Also, VOUT/VREF is just the ADC reading divided by the ADC max (65536 ?)

angle = log(VOUT/VREF/k) * j
so you need:

angle = logADC/65536./k);

so your code could be something like this (note, I haven't checked it !, also I'm using a Teensy 3.0, so the ADC stuff might be different -- you need to check)


#define LEDpin 13
#define NLOOPS 16 // number of ADC conversions
#define measurementChannel 123456 // Need to do this for your system
#define k 0.5 // Set this yourself

// SETUP
void setup(){
int i=0;
Serial.begin(9600);
pinMode(LEDpin, OUTPUT); digitalWrite(LEDpin, HIGH);
pinMode(0, OUTPUT); digitalWrite(0, 0); // for scope
pinMode(measurementChannel, INPUT);
analogReference(DEFAULT); analogReadRes(16);
while (!Serial && (i++ < 10*6)) { // wait for serial to open or ~ 6 seconds
digitalWrite(LEDpin, HIGH); delay(50); digitalWrite(LEDpin, LOW); delay(50); }
}

// Main Loop
void loop(){
float fAngleDegrees;
static int iRollingCounter = 0;
digitalWriteFast(0, HIGH); // Trigger scope
digitalWrite(0, LOW);
long ADC=0L;
for (int i=0; i < NLOOPS; i++) ADC += analogRead(measurementChannel);
ADC /= NLOOPS; //This is the average ADC reading
ADC += 1.; // avoid log(0) issues
fAngleDegrees = log(((float) ADC)/(2^16)/k);
Serial.print("Measurement number "); Serial.print(iRollingCounter++); Serial.print(" is "); Serial.println(fAngleDegrees);
}
 
Last edited:
Than you for all that

I tried all your things and other stuffs.

Finnaly, Inverting the 3 pins was the right solution ! Added the average + some delays between reads and i have now a very stable and smooth change

Also had to change from INT to LONG...

Thank you for your help, and long life to Teensy !!!
 
Status
Not open for further replies.
Back
Top