Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Potentiometer on a 16f628

Status
Not open for further replies.

brentonw2004

New Member
Hello all. I am new to this board so hello. Here is my problem. I am using a Pic 16f628 to build a car part. I am programming it with Pic Basic Pro. I need to get an 8-bit reading from a 100K potentiometer. I have tried to use the "POT" command, but I am having very little luck with this. I am debugging my chip with a serial cable connected to my computer. The pot seems to work, but it seems to increase the value of my variable way too fast, it stays at zero until nearly half way through the turn, then it increases very rapidly to 255 and stays there for the rest of the turn. How can I space this out to were 0 is at one end and 255 is at the other. I have a lot of these chips, so changing to a different chip with an a/d converter would be very costly, and I cannot simplify my design to not use a microchip. Also, could I use the POT command with a pressure sensor as well, it is after all just another type of variable resistor? Thanks!
 
brentonw2004 said:
Hello all. I am new to this board so hello. Here is my problem. I am using a Pic 16f628 to build a car part. I am programming it with Pic Basic Pro. I need to get an 8-bit reading from a 100K potentiometer. I have tried to use the "POT" command, but I am having very little luck with this. I am debugging my chip with a serial cable connected to my computer. The pot seems to work, but it seems to increase the value of my variable way too fast, it stays at zero until nearly half way through the turn, then it increases very rapidly to 255 and stays there for the rest of the turn. How can I space this out to were 0 is at one end and 255 is at the other. I have a lot of these chips, so changing to a different chip with an a/d converter would be very costly, and I cannot simplify my design to not use a microchip. Also, could I use the POT command with a pressure sensor as well, it is after all just another type of variable resistor? Thanks!

I don't use PIC BASIC, so I can't comment specifically on the Pot routine, but it works in a standard way - by timing the charge or discharge of a capacitor. Obviously this time depends on the resistor and capacitor values used, presumably these values are explained in the manual?.

Another point, which type of pot are you using?, linear or log, and is the pot OK - a broken track in the pot would tend to cause this effect.
 
I would test your pot by checking the resistance with a multimeter.....
What capacitance do you have?

According to the manual:
The resistance is measured by timing the discharge of a capacitor through the resistor (typically 5K to 50K). Scale is used to adjust for varying RC constants. For larger RC constants, Scale should be set low (a minimum value of one). For smaller RC constants, Scale should be set to its maximum value (255). If Scale is set correctly, Var should be zero near minimum resistance and 255 near maximum resistance.

Unfortunately, Scale must be determined experimentally. To do so, set the device under measure to maximum resistance and read it with Scale set to 127. Adjust Scale until the Pot command returns 254. If 255, decrease the scale. If 253 or lower, increase the scale. (NOTE: This is the same type of process performed by the Alt-P option of the BS1 environment).

Most of the time I use a PIC with a ADC in it so that this process is more effective and exact. The PIC16F876 or 877 will have that..... also you can use a serial ADC (8 pins) to have it more accurate than the pot. Remember that depending on the capacitor you are going to have a change of +/-20% to +/-5% of the value add that to your linear pot which might have a +/-20% to +/-10% and you are going to have a heck of a time.

Ivancho
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top