PDA

View Full Version : Serial control of a digital pot?



TonyA
- 1st June 2006, 15:19
Hi,

I am searching for info and examples for controlling a digital pot serially using shiftout. I am using the pic18f452, and I'm not sure which digital pot to use. Any suggestions/info would be greatly appreciated.

Thank you,
TonyA

mister_e
- 1st June 2006, 15:37
those i already used in the past from Microchip
MCP42010, MCP42050,MCP42100, MCP41010,MCP41050,MCP4110.

TonyA
- 1st June 2006, 15:45
Hi,

Are there any examples of code around?

Thanks,
Tony

mister_e
- 1st June 2006, 15:48
Not where i am, but i could download the datasheet and try something somewhere today.

As i remind it wasn't too complicated. Maybe there's some example here already done. Do a search with the model i suggest, you may find something ;)

TonyA
- 1st June 2006, 15:50
I appreciate that very much. I will try a search here.

Thanks again,
Tony

mister_e
- 2nd June 2006, 14:50
O.K it's untested but it should work for any MCP4XXXX digital pot. Try it and post your results


'
' Hardware configuration
' ======================
TRISC=0

'
' Hardware connection
' ===================
CS VAR PORTC.0
CLK VAR PORTC.1
SI VAR PORTC.2

'
' Variables definition
' ===================
Wiper var byte

'
' Constants definition
' ====================
MSBFIRST CON 1
WriteOnPot0 con %00010001

'
' Software/Hardware initialisation
' ================================
cs = 1 ' disable MCP
PAUSE 100 ' safe settle time

Start:
for wiper = 0 to 255
cs=0 ' enable
shiftout si,clk, MSBFIRST,[WriteOnPot0, WIPER] ' Write to MCP
cs = 1 ' Disable
pause 10
next
goto start


Now connect PA0 too vcc, PB0 to GND and read the voltage on PW0 pin... is this working?

TonyA
- 2nd June 2006, 15:42
Hi,

I appreciate that very much.

What is this constant doing : WriteOnPot0 con %00010001 ?

(I aplogize in advance if this is obvious, my brain is a little jumbled today).

I will be getting the digital chip in a few days and I will try this out and post results.

I'll be using an analog sensor read by the pic 18f452 using adcin. Then interpreting that analog reading for use in the "Wiper" variable. So as the analog sensor changes so will the digital pot.

Thank again,
TonyA

mister_e
- 2nd June 2006, 23:49
This constant is the CommandByte needed by the chip. Read datasheet section 5, and look the figure 5-2.