reading a potentiometer ?

Go To Last Post
23 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have paddle device coupled to a potentiometer, so as to generate an output voltage level varying with the wheel's angle relative to a fixed reference position. I should be able to read in the result and get the position of the paddle knob. But I dont have a clue what I could use so that the avr chip can read this data. Can I do this with the chip(atmega168) alone?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just connect the middle pin of the potentiometer to an ADC input and read the voltage. Connect the two outer pins to GND and the reference volatage of the ADC respectively.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm guessing that pin needs to be in high impedimenta mode. Is there away to set this once the port has been set to high or low?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The pin is an ADC input, this has nothing to do with "high impedimenta mode" or whether it has been set high or low.

Leon

Leon Heller G1HSM

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
The pin is an ADC input, this has nothing to do with "high impedimenta mode" or whether it has been set high or low. 

Thx, understood.

Just connect the middle pin of the potentiometer to an ADC input and read the voltage. Connect the two outer pins to GND and the reference volatage of the ADC respectively.

Perhaps I have a strange pot here? I only have two leads. More like an variable resistor of sorts.

I think I have this correct but I'm not seeing a value that I need. If I monitor the "out" lead of this variable / potentiometer I get 5 volts, I'm guessing its do to my pullup on port C ( as to why I asked earlier ). With out the pin connected to my ACD0 input I can see my resistance about 4.0 to 5.08 volts.

With the ACD pin connected and a 1k resistor from that pin to ground I'm finally able to see some input. but its in the 100's of mv's. I think I may not have set up my ADMUX type right.. That or the pullup resistance is to high. here is what I have.

in my init

	ADMUX=0x40;
	ADCSRA=0x83;

the read function

 unsigned int read_adc()
{
	ADMUX= 0 /*ch*/ | (0x40 & 0xff);
    _delay_us(10);
    ADCSRA|=0x40; // Start the AD conversion
    while ((ADCSRA & 0x10)==0);// Wait for complete
    ADCSRA|=0x10;
    return ADCW;
} 

and I just get my data from the return.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Some joysticks use a pot (3 wire), some use a variable resistor (2 wire). Can you draw a schematic of what you have?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh there is no question about it, its not a 3 wire pot. but here is a pic. Blurry but should be able to see whats needed.


click here for a bigger pic
http://spawnlinux.dyndns.org/DoC...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A pc joystick uses a variable resistor and a fixed cap in a one shot. The oneshot gets fired by a read (or write?) to the joystick port, then the pc spins in a loop checking the oneshot output and counting till the oneshot times out. Pulse width is proportional to resistance. You could do the same thing with a cap on an avr io pin. Set the pin to output, turn it on, output goes low, discharges cap. Set the pin to input, start counting in a loop and polling input. Cap starts charging to 5V thru variable R. At 2V, input goes high. Count is proportional to resistance.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thx bobgardner, I do see what you mean however adding a cap would compromise my compatibility with other devices. The avr will monitor the potential of this pin with other non pot devices.

Is the fact I have this line pulled high my issue here? Is there a way to not pull high or low when setting the other pins on this port?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I cant tell how its wired from that picture. Can you draw an ascii sketch?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My ascii sucks...

http://spawnlinux.dyndns.org/DoC...

using an 8k gives me better results. I think what is going on here is that I'm compensating for the pull up.

The strange thing is I only can use 1/8th of the knob. 8 o'clock(.8 vc ) to 11 o'clock(1.5 vc)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How much of the rotation range do you want to use?

I'm no analog wizard but I don't think you can get a linear voltage out of a variable resistor (as opposed to a potentiometer). That is to say, not without some kind of active device. If you drove a constant current through the variable resistor then you would get linear voltage vs. resistance.

If you don't want to go to those lengths, you will get a non-linear position vs. voltage output just using a fixed resistor as you are doing. You can then apply a correction in software to get position from the input voltage.

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
How much of the rotation range do you want to use?
at least 75% of it.

Quote:
If you drove a constant current through the variable resistor then you would get linear voltage vs. resistance.
I believe this is what its doing, and with the ACD port disconnected I get just that. The problem I'm having is when the ADC port is connected the it is comprised, and IMO ( could be very poor BTW ) I think its the fact I'm pulling high. This is done for other reason not related to this device. I was thinking if I could change the state back to the hi-v it may work, but I dont know how to do that. I also tried reversing the DDR but that didnt help.

but maybe this resistance I'm seeing with my volt meter can not be sampled with my avr?

Quote:
If you don't want to go to those lengths, you will get a non-linear position vs. voltage output just using a fixed resistor as you are doing. You can then apply a correction in software to get position from the input voltage.
I would hope I dont have to go this rout as I'm not having much luck with it so far. If I could use more the an 8th of my dial I'd be happy. The target being 75% of it.

-----

I guess something else that to me is a bit strange is the fact this VR has no ground source. One lead for the input voltage and one for the monitoring voltage, does that sound right?

should it have been like this
http://spawnlinux.dyndns.org/DoC... Because doing this allows me to read from 2 o'clock to 4 o'clock with out adding the resister and my voltage makes more sense. 3.8 to 6 but my software cant see above 4.5 must be something wrong in my code. I think I can handle that.

I see provision for a lead that could have been added but the land pattern is not equipped for it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you have your set up connected poorly for this purpose.

Try this configuration:

+5V----
     |
     R  (say 10K)
     |
     +-----> To ADC Input
     |
     Your 2-Wire Device
     |
Gnd----

With your configuration, you are connecting your ADC input to either the V+ or the Gnd side of the 2-Wire variable resistor. You will be reading either V+ or Gnd. You will also be drawing a LOT of current when you have a very low resistance setting.

With the above circuit you have set up a voltage divider.

If the resistance of the 2-Wire device is, for example, 10K, then when the wiper is at the "top", (full resistance), you have two 10K resistors in series and the output voltage will be V+/2, (5/2 = 2.5V).

As you move the wiper to a lower resistance, the divider changes, and you will get a bigger voltage drop across the fixed 10K resistor, and a smaller voltage drop across the 2 wire device, all the way down to 0 V.

This setup will only give you 0-2.5 V output, if the 2 wire device is 10K, not 0-5V, but it should not matter. You will still get a variable output based upon the full scale rotation.

The selection of the fixed resistor, and the ADC reference, will determine ust how much of the ADC's range you actually use. i.e. your output might go from 0 - 512 instead of from 0 - 1024.

This changes how fine your output is per degree rotation, but you will still get a variable output for the full scale.

Give this a try and report back.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, you may wish to put a 0.1 uF cap from the junction of the fixed resistor and your 2 wire device to ground.

Some pots are scratchy, with intermittant ro noisy contact, and this will help smooth out the signal.

You may wish to average several readings for your real application, once you have it working.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lastly, it probably goes without say, but just to be sure:

Be sure you have the ground, above, tied to the ground of you micro's circuit/board.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
Lastly, it probably goes without say, but just to be sure:

Be sure you have the ground, above, tied to the ground of you micro's circuit/board.

JC

- right ;)

Quote:
Some pots are scratchy, with intermittant ro noisy contact, and this will help smooth out the signal.
- I do have this problem.. THX!

I will try this setup soon thx..

I still dont understand why the OEM left the bottom end of the resistor open?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

S_K_U_N_X wrote:

I still dont understand why the OEM left the bottom end of the resistor open?

If the device was designed to be used in a timing circuit there would be no need for the 3rd connection.

Again, your choices with this device are either to use a resistor and get a non-linear voltage vs. position output, which you will need to correct for in software, or to use a current source which will give you a linear voltage vs. position output.

BTW, I'm not sure if you've mentioned this before, but what is the total resistance of the device? And what kind of position resolution do you need in your software?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Of course another solution would be to mount your own connection to the other end of the resistor, either by quickly soldering on a wire, mounting a small screw through the end of the arc, or by using some kind of springy metal (paper clip?). That might be the best way to go if you're just experimenting.

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I forget but its was 50 some k, to 7 some meg ohms I could double check.

My ideal option would be using the circuit un-touched. As I want to support this device. but the thing that gets me is it works on an atari.. The atari uses a Pot, and this has only the two leads, top of resister and wiper. So I'm not sure how it worked with the atari to begin with thus the mystery.

I have added to the circuit to make it work, but dont want to do this if at all possible.

I have tried the choices you mention but I cant see the entire resistor. its like an 8th of it.. Still looking in to this.

thx for the reply's.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
7 some meg ohms
:shock:

From the Mega168, as an example, (23.6.1):

Quote:
The ADC is optimized for analog signals with an output impedance of approximately 10 kΩ or
less.

Several more comments:

Get a 10K pot and a 10 K fixed resistor and wire it up as shown above. Read and display your values on an LCD or upload them to a PC for display on Hyperterminal. This will verify that your software is functional.

Next, as noted above, the AVR's ADC input is not designed to be driven by a multi-meg ohm source. If you have to do this you may wish to buffer the signal with a voltage follower op-amp.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I bet if you put a scope on it when its working in the atari, you will see the cap charging and discharging in the familiar exponential waveform that looks like a shark fin. Freq will get faster and slower with resistance.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
I bet if you put a scope on it when its working in the atari, you will see the cap charging and discharging in the familiar exponential waveform that looks like a shark fin. Freq will get faster and slower with resistance.
_ was wondering about that my self, but I dont have the console. I'm working blind here. Fist I'm going to do a few tests to make sure I know the resistance I'm dealing with. If 10k I my limit as DocJC sain I'm going to have 0 luck without modifications. By the way I mean .7 meg ohms but yes still way out side the limit.

incidentally the atari paddles are 1 MegaOhm, and this controller is designed to work with it, so my guess its the .7 meg oms I'm seeing could just be off by a bit.

also found this.

Quote:
Voltage divider requires 3 wires connected to the pot, but the 2600 just has two wires to use the pot as a variable resistor which controls the rate of charge of a capacitor which indirectly indicates the wiper position.

So I'm going to try using the cap method.