Hi,

I am trying to use a serially controlled digital pot MCP42100 with Pic 18F452.

What I'm doing is receiving an analog input (a pot) on portA and then converting its reading to operate the digital pot.

(Note this is a continuation of an old thread located here:
http://www.picbasic.co.uk/forum/show...ed=1#post21450

This code was from Mister E (thank you)

My question is should I just replace the For Next loop with my adc pot reading and replace the variable "Wiper" with the pot reading results?


' ' Hardware configuration
' ======================

'DEFINITIONS'
DEFINE OSC 20 'set for external high speed powered ocsillator
DEFINE ADC_BITS 10 'set number of bits in result
DEFINE ADC_CLOCK 3 'set internal Pic timer as RC
DEFINE ADC_SAMPLEUS 15 'Set sampling time in uS

'serial registers for midi out option'
DEFINE HSER_RCSTA 90h 'receiving definition for hardware serout (Midi)
DEFINE HSER_TXSTA 20h 'transmitting difinition for harware serout
DEFINE HSER_BAUD 31250 'Baud rate for midi

'PORT SETUP'
TRISA = %11111111 'Port A as inputs
TRISB=0 'Port B as outputs
ADCON1 = %10000010 'Set PORTA analog conversion and right justify result

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

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

' ' Constants definition
' ====================
MSBFIRST CON 1 'this is part of the shiftout function of the Pic
WriteOnPot0 con %00010001 'this is a command byte needed by the digital pot

'WriteOnPot0 = Command Bytesee fig. 5-2 of data sheet)

'EXPLAINATION OF THE COMMAND BYTE(see fig. 5-2 of data sheet);
'Pot Selection Bits: Starting from the left 01 means the command is
'executed on Pot 0
'(there are 2; pots 0 and 1)

'Command Selection Bits:
'At bit 4 and 5, the 01 means write data to the pot selected by the first 2 bits,
'which in this case is Pot 0

' ' Software/Hardware initialisation
' ================================

cs = 1 ' Make CS pin on dig pot high = disable MCP

PAUSE 100 ' safe settle time

Start:

for wiper = 0 to 255 'For demo purposes this will automatically toggle the pot
'up from 0-255 steps

cs=0 'CS pin low = Enable

shiftout si,clk, MSBFIRST,[WriteOnPot0, WIPER] ' Write to Digital Pot

cs = 1 ' CS Pin high = Disable

pause 10

next

goto start


I thought this might be good for others trying to use serial controlled digital pots, so I commented everything, which helps me too.

Thanks for any input,
Tony A