4V Potentiometer Range

Hey everyone,

So I bought a T-Bar cross fader that has a range of +2v and -2v. This means when I use the fader, I am only getting a range of 20%-80% on my program because the Potentiometer only has a 4V range and does not reach the 5V range. How can I program this to compensate for the 4v range?

Below is the chart of the range.

Use the Map function to scale it up or down

 /* Map an analog value to 8 bits (0 to 255) */
void setup() {}

void loop()
{
  int val = analogRead(0);
  val = map(val, 200, 818, 0, 1023);  // map 4 V range to 5V

}

I'm not sure if that is the range you meant. (2V dc to 4V dc)

Great thanks! Let me give that a try!

Or change the arduino analog voltage reference.

Or change the arduino analog voltage reference.

Where can he get a precision 4V reference ?

raschemmel:

Or change the arduino analog voltage reference.

Where can he get a precision 4V reference ?

He can use the internal 1.1V Reference voltage and add a divider to the potentiometer.
This also reduces any noise due to VCC fluctuation, as VREF is not tied down to VCC

I don't think that's going to work for him . He paid for +2V/-2V crossfader . I don't think he wants to limit it to 1.1 V because that will reduce the resolution. The arduino will round it up or down and he'll have 1/4th the resolution that he would have with +2/-2V,
I doubt he would want to do that. I wouldn't

raschemmel:
I don't think that's going to work for him . He paid for +2V/-2V crossfader . I don't think he wants to limit it to 1.1 V because that will reduce the resolution. The arduino will round it up or down and he'll have 1/4th the resolution that he would have with +2/-2V,
I doubt he would want to do that. I wouldn't

You're missing the point.
If I set VREF as 1.1V I have 100% resolution at 1.1V. So 1100mV = 1023!
He can add a second potentiometer, set as a voltage divider to convert the 4V signal into 1.1 - no resolution is lost!

On the other hand, if he uses the 4V, the ADC can go to (1023/5)*4 = ~ 818, resulting in only 80% resolution. He can then map 818 to 1023 using the map function as described above, but the efective resolution is not going to increase. Its still 818!

Of course this may not be an issue. 10 bit is plenty and it may well work out with only 80% resolution. I leave that as an exercise for the OP to determine.

I actually only need a resolution of 255. This is for a video switcher which has a value from 0-255.

Here is what ended up working for me for a 0-255 resolution. However I do seem to be getting a little bit of noise on one end of the fader so the value stutters between 255 and 254

  int TBarValue = analogRead(A9);
  int TBarPosition = map(TBarValue,0,1023,-30,287);

Now me second question is this. Is there any way to invert the value of the input? For instance the way the software that I am controlling is set up, once the value reaches 255, the software that I am controlling then is set back to 0. So if I move the T-Bar back down, instead of starting 255 and going back down to 0, I need it to switch to 0 and go back up to 255. So no matter if the T-Bar is traveling up wards or down wards, I need the starting value to be 0. So it would work like this.

Fader in down Position and value is 0
Fader moves upwards and reaches the top and the value is 255
Fader in up position and value now resets to 0
Fader moves downwards and reaches the bottom and the value is 255

You're missing the point.

No , I think you're missing the point. The pot is a physical device and when you use a voltage divider, the accuracy is not the same because you are compressing 4V into 1V and the only way to do that is to sacrifice sensitivity.
As far as the range, the Map function can scale it up or down as needed to whatever you want.
You have to map your pot and setup the Map function accordingly. Draw up a scale and post that with the Max at the top and Min at the bottom and the values you want to the right.

I have never seen a potentiometer that creates a specific voltage.

raschemmel:
The pot is a physical device and when you use a voltage divider, the accuracy is not the same because you are compressing 4V into 1V and the only way to do that is to sacrifice sensitivity.
[/b]

Are you saying that a 3.3V arduino nano has less sensitivity than an arduino uno at 5V?

I guess they're the same but the signa to noise rstio is not.

Is there anyway to reverse the range of the potentiometer?

For instance if the down position would normally start at 0, could you make the up position start at 0 instead?

Clearly you don't understand the function of the Map function.
Look at it again. Think of it as a circuit with two inputs and two outputs. You choose how the output relates to the input. If you want to completely reverse it, then go ahead and do it. If you want to split in half and put 0 in the middle and + an - at the two ends then do it.
If you want to put 0 at both ends and midrange in the middle then do it. (although I have never heard of that one, I don't see why it wouldn't work)
You need to stop associating values to the pot and think of it and simply a resistance instead of 255 because there is really no connection between the two other than the Map function, since the analog input range is 0 to 1023. Those are the only limits you can logically associate with the pot. Everything else is the work of the Map function, not the pot.

Is there any way to invert the value of the input?

int TBarValue = 1023 - analogRead(A9);
int TBarPosition = map(TBarValue,0,1023,-30,287);

Like I said, it's all about the Map function.

On the other hand, if he uses the 4V, the ADC can go to (1023/5)*4 = ~ 818, resulting in only 80% resolution. He can then map 818 to 1023 using the map function as described above, but the efective resolution is not going to increase. Its still 818!

This is a good point for Newbies to think about. If you stick to hardware (using only pots) there is no resolution loss. On the other hand
If you only start with 800 counts in your range, using the Map function is not going to restore it to 100%. I don't know if that is readily obvious to Newbies.

Fader in down Position and value is 0
Fader moves upwards and reaches the top and the value is 255
Fader in up position and value now resets to 0
Fader moves downwards and reaches the bottom and the value is 255

There is no limit to how many times you can use the Map function. It's just a matter of detecting the proper moment to invoke it.

raschemmel:
Clearly you don't understand the function of the Map function.
Look at it again. Think of it as a circuit with two inputs and two outputs. You choose how the output relates to the input. If you want to completely reverse it, then go ahead and do it. If you want to split in half and put 0 in the middle and + an - at the two ends then do it.
If you want to put 0 at both ends and midrange in the middle then do it. (although I have never heard of that one, I don't see why it wouldn't work)
You need to stop associating values to the pot and think of it and simply a resistance instead of 255 because there is really no connection between the two other than the Map function, since the analog input range is 0 to 1023. Those are the only limits you can logically associate with the pot. Everything else is the work of the Map function, not the pot.

Exactly, that is why I am asking the question. I need to more clearly understand that function.

From my understanding, the first number in the Map function is always the low number in the range when their is the least resistance. So if that is true, wouldn't it be impossible for the most resistance reading to be lower than the least resistance reading?

Would these two Map functions create opposite readings and ultimate the results I am looking for?

  int TBarPosition = map(TBarValue,0,1023,287,-30);
  int TBarPosition = map(TBarValue,0,1023,-30,287);

For instance, when I setup my code normally. The down position is where I get my 0 reading. If I wanted the down position to be the highest number of my set range would be, how would I achieve that?