PDA

View Full Version : Controlling a MCP4162 Digital Pot



SOTASOTA
- 17th February 2009, 23:08
Help!
I would like to control Microchip's MCP4162 Digital Pot with a PIC16F84a using PIC Basic Pro.
I have this code so far. The Digital Pot is a 256 tap pot. I want to set it to any tap position. Blow I am trying to set it to tap 128 just to get it working. But, nothing happens.

'Set these B ports O/P and LOW
Input PORTB.0 'Pushbutton
High PORTB.1 'ChipSelect
Low PORTB.2 'SCK
Low PORTB.3 'SDI

PORTB.1=0 'ChipSelect
ShiftOut PORTB.3, PORTB.2, 1, [128]
PORTB.1=1 'ChipSelect

lllfsss2
- 23rd March 2009, 03:05
'Set these B ports O/P and LOW
Input PORTB.0 'Pushbutton
High PORTB.1 'ChipSelect
Low PORTB.2 'SCK
Low PORTB.3 'SDI

PORTB.1=0 'ChipSelect
ShiftOut PORTB.3, PORTB.2, 1, [$00,$128]
PORTB.1=1 'ChipSelect

eso porque primero tienes que mandarle el codigo del wiper que vas a usar
y luego le mandas el valor variable que usaras! :)

jmgelba
- 4th February 2011, 01:07
So did you ever get this to work?

jmgelba
- 4th February 2011, 16:33
A little confusion.

Looking at the shiftout section of the pbp manual, mode is selectable with a simple 0 to 3 depending an your needs.

Past code examples include this line:


WriteOnPot0

Does the newer version of pbp take care of this now with the mode setting or is this still required at the start of the program?

jmgelba
- 4th February 2011, 18:02
More confusion. If you set the commandbyte to a constant, you wont be able to increment or decrement because the control byte is always set for one or the other. Therefore, shouldnt the commandbyte be sent at the same time the data is sent?

Example if the pot is currently sitting at position 200 and the commandbyte is %00000101 and you send:

PORTB.1=0 'ChipSelect
ShiftOut PORTB.3, PORTB.2, 1, [$00,$128]
PORTB.1=1 'ChipSelect


Nothing will happen because the pot is set to only increment.


OR am I getting this completely wrong and the $00 is the commandbyte? This would put 00 at the increment/decrement bits which is a READ condition, therefore any value sent after the $00 would be placed on the pot.
If that is the case, there is no need for the commandbyte constant.

jmgelba
- 6th February 2011, 18:51
Any help with this?