MCP4xxx Digipot control with Analogwrite (to PWM)

Hey everyone!

I'm new to the forums here and the exciting world of Arduino :slight_smile: While I'm not a total n00b (10 years of soldering experience and hacking) I am a super n00b with code. I mean I know zilch.
Been reading up a little but I could use some guidance for sure.

My project:
I'm hoping to use an Arduino to control a MCP4661 digipot: mcp4661
However, I would like it to do 2 very specific things:

  1. move the wiper setting faster based on an analog input voltage (0-5VDC. A proximity sensor like IR or hall effect). I'm assuming this would work with a PWM from AnalogWrite function to control the number of "taps" on the wiper
  2. when zero or low voltage is present, reduce the wiper at set rate down to mid-scale

The concept is to have a digital pot mimic a real-world pot that you can turn by moving your hand side to side (e.g. without any knobs or sliders). but this pot would automatically return to mid-scale when not being triggered with a hand wave or whatever.

Any help greatly appreciated!! I just need some pointers on how to start writing this kind of code.

The data sheet indicates that chip uses an I2C interface, so PWM wont do what you're thinking.
You need to calculate and send the appropriate register values to the chip using the I2C interface from you software.

lastchancename:
The data sheet indicates that chip uses an I2C interface, so PWM wont do what you're thinking.
You need to calculate and send the appropriate register values to the chip using the I2C interface from you software.

http://www.microchip.com/wwwproducts/en/MCP4661

That makes sense. not sure how to go about that though.
What about a different "tap" digipot, like this one:

that should work with PWM, yeah?

Sure - both chips will do what you want, but first decide what sort/value pot you need.
No - neither chip uses PWM in the control interface.

Don't define the pot by the interface unless you really have to.
The Up/Down interface is easy to implement - but you have to keep track of the value, whereas the I2C interface is a register with in the pot-chip, and you simply 'set' the value. (or read back if/when ever needed).

Note - if you are going to use the Up/Down chip - this is in the notes
Endurance, 100,000 Data Changes per Bit
May cause some issues a couple of years down the line if it's a simple volume control application.
These chips are probably designed for calibration applications - not user-interfaces.

Buy whichever chip you like that suits your analog needs for 'R', then play with the control methods - there are plenty of I2C examples on the forum, and the up/down is very easy to implement.

Thanks for the reply.

That endurance note is scary, so I will be staying away from the X9C. The MCP4xxx line is very popular with lots of info around so it seems like the better choice anyway. Also, I need a 5k pot, so going with that one I won't need to gang anything.

I've watched a few videos and read some code and even programmed a basic example to the X9C103. I'm not so great at this programming thing though! heh. Excited to learn more.

After some more searching I found this very useful post:
https://forum.arduino.cc/index.php?topic=337113.0

This is exactly what I am trying to do (and I really like that sensor choice !) but with the added feature of auto-mid scale. It looks like this sensor would make life much easier than using an analog or simple state logic device (since it outputs I2C already).

Looks like they got stuck on the code though...

That would be my choice too.
If you application is audio - keep in mind two other parameters...
The 75-ohm residual (minimum resistance), and the fact (I expect that) it's a linear taper resistance profile.
If you application requires log taper - then you have to manage that in software to create the profile you want in your app. (This will provide different resolution at each end of your wiper range)

The downside to that sensor is that it is pretty expensive, $4.77 for the bare part (http://www2.mouser.com/ProductDetail/STMicroelectronics/VL6180XV0NR-1/?qs=bOHV6dImh3MAxp12geXi0Q==) and reflow-only for pcb mount = nofun :confused:

This isn't for audio, it is to control a scooter (that's why it needs to auto mid-scale). So I want it to be linear for sure. and the min resistance is tolerable.

any idea how I could arrange the code to have it auto mid-scale?

Mid-scale - It seems that both chips have last-value memory, so you could always set that before power-down, or at startup - always send the mid-range value before anything else. Always stay aware of any life cycle limitations.
Of course mid-range may no be exactly mid-value - so you need to find that value.

Why are you using a pot in a scooter control application? (It could be appropriate - just asking)
If you are keen on PWM as you started out (which is typically used more often) - you need a power amplifier/driver to drive the motor(s) - then everything else makes sense.

I should explain more:

My scooter is controlled with a regular analog pot. What I want to do is place this in between that pot and the CPU to trick it into a reading a digipot which I can then control with a proximity sensor

The reason for this is I have some disabilities with my hands and have trouble turning the pot. See here:

This version is only Stop or Go, I want to use an MCU and digipot to control the slope up/down so its not so jerky.