PDA

View Full Version : Digital Pot



TONIGALEA
- 27th July 2004, 20:18
Hello Everyone
Could someone be kind enough to point me to and easy to ust Digital Pot of any example of using a digital pot with picbasic
This would be very much appreciated

Toni

Bruce
- 28th July 2004, 01:41
Sorry I can't give you "all" the code, but I can give you enough to show how easy it is.

This was done for a customer. It's for a hand-held RF wireless control terminal. This small section shows how to control the DS1804 digital pot. The digital pot controls the hand-held terminals LCD contrast.

The DS1804 POT wiper position is stored in internal EEPROM. Storing the wiper position allows the terminals LCD contrast to be the same after power off and on conditions. I.E. the terminal always remembers the LCD contrast settings.

CS VAR PortC.2 ' Pot chip select/control
INC VAR PortC.0 ' Pot wiper increment, 0=INC, 1=Disable INC.
UD VAR PortC.1 ' Pot Up/Down select 0=Down, 1=Up

This prints a menu on the LCD waiting for user input to adjust contrast, turn on or off the LCD backlight, etc,,. and adjusts the contrast of the LCD connected to the digital pot.

AdjCont:
lcdout CMD,CLR
LCDOUT CMD,L1," ** LCD Adjust ** "
LCDOUT CMD,L2," 1=Darken 2=Lighten" ' 1=Key #11, 2=Key #6
lcdout CMD,L3," 3=LED ON 4=LED OFF" ' 3=Key #1, 4-Key #12
LCDOUT CMD,L4," ESC=Back Ent=Save " ' ESC=Key #15, Ent=Ket #10

Adj:
gosub GetKey
if KeyIn = 15 then Mode1
if KeyIn = 11 then
CS = 0 : UD = 0 ' 0=Dark contrast
LOW INC : HIGH INC
pause 250
endif
if KeyIn = 6 then
CS = 0 : UD = 1 ' 1=Light contrast
LOW INC : HIGH INC
pause 250
endif
if (Mode=1) and (KeyIn=1) then BKLITE=TRUE
if (Mode=1) and (KeyIn=12) then BKLITE=FALSE
if KeyIn = 10 then Save
Goto Adj

Save: ' Store wiper settings in DS1804 internal EEPROM
Mode=1
HIGH INC : CS=0 : CS=1 : CS=0
lcdout CMD,CLR
lcdout CMD,L2," * Saving Settings *"
PAUSE 1000
GOTO OtherStuff

If you download & review the DS1804 datasheet, you'll understand how all this neat stuff's working. It's really very simple.

TONIGALEA
- 28th July 2004, 21:56
Thanks Bruce
For your time and explanations i have ordered the ds1804 and should get it in the morning and i have also looked at the datasheet .
The only thing thats still worrying me is i can't seem to find on the data sheet how to preset a specific value without saving the wiper position.
for my application, i want to be able to set the pot to 2k ohm
then 4k , 6k , 8k then 10k
so that when i run my program i would have 5 different subs for 2k, 4k etc
would this be posisble

Toni

Bruce
- 29th July 2004, 07:33
Hi Toni,

It's a lot easier than it might look. You can zero the wiper on start up. Then keep track of the high-to-low transitions on the INC pin to know the wiper position.

The wiper has a typical resistance of 400 and MAX of 1K when it's at the low-end.

I.E. even at the lowest pot setting you can still have from 400-1K ohms resistance.

If you start at ZERO and use this as a reference point (zero the wiper on power-up), then you can keep track of the pot resistance by keeping track of your transitions on the INC pin.

Example;

Zero: ' This sets the wiper to ~500 ohms (on mine)
LOW CS ' Enable wiper movement
LOW UD ' Move wiper to L position
FOR X = 0 TO 99 ' Move 100 positions
HIGH INC
LOW INC
NEXT X
HIGH CS ' Disable DS1804
RETURN

Now you know where you're starting at. Each high-to-low transition on INC will move the wiper "1" position. Assuming you had the DS1804-010 which can go to around 10K MAX, you can move the wiper from the low-end to high-end (or vice-versa) in increments of 100 ohms per transition from high-to-low on INC.

With 0 to 99 (100 total tap points) you can figure around 100 ohms per transition on INC with the 10K pot.

Increase:
LOW CS ' Enable wiper movement
HIGH UD ' Move wiper towards H terminal
FOR X = 1 TO 50 ' Move wiper to ~5.5K position
HIGH INC
LOW INC
NEXT X
HIGH CS ' Disable wiper movement
RETURN

Place your ohm-meter on the L & W pins and play with this. You'll see what I mean.

The Increase routine moved the wiper from the zero position to roughly 5.5K.

50 x 100 ohms per transition = 5K. Now I add the 500 ohms mine has when the wiper is in the zero position, and I end up with roughly 5.5K.

Now decrease it from 5.5K to 4.5K by moving it the other way 10 x 100 or 1K.

Decrease:
LOW CS ' Enable wiper movement
LOW UD ' Move wiper toward L terminal
FOR X = 1 to 10 ' 5.5K - 1K = 4.5K
HIGH INC
LOW INC
NEXT X
HIGH CS ' Disable wiper movement
RETURN

I don't use them like this, but it's definitely do-able. I only use them for digitally controlling LCD contrast. Don't much care what the actual resistance is.

TONIGALEA
- 30th July 2004, 23:02
Thank you very much BRUCE
i received my DS1804 today and tried it out it worked perfectly
i am going to use it to vary the frequency on a 555 oscillator
Excellent explanation i now understand how it works

Toni

willy89
- 3rd January 2012, 07:54
how can i use this chip to control the spped of a motor? pls help i need info urgently, thanx