help using SEROUT to control SPI digital potentiometer
byoc
Posts: 17
I have some MCP4231-104 digital pots with SPI interface that I'd like to use. I'm assuming the SEROUT command is what I want to use here. Only problem is I'm not familiar with SPI or the SEROUT command. I mean, the data sheets me how to connect it and the reference manual shows me the syntax, but I don't understand the data that I'm suppose to communicate to the digipot. Any links to practice projects that can help wrap my head around these concepts....like the classic example of making an LED get brighter or dimmer or something that I can extrapolate from to make these kinds of digipots do what I want?
Comments
LOW ChipSelectPin
SHIFTOUT SDO, SCL, MSBFIRST, [Value\7]
HIGH ChipSelectPin
Maybe value\8 if you have the 256-level version
Some of the earlier Stamp-oriented manuals will have useful information.....except, I can't find them on the Parallax or Learn sites. Anybody know where the Stamps In Class and such manuals are stashed?
MCP3208 Demo.bs2
edit: or just binary and the MODE will take care of which bit comes first I guess.
Thanks, davejames. That helps as well. I didn't realize the same command/concept could be applied to the digital pot. That is actually half of the larger ultimate project I'm working on. I'm trying to use a single "real" pot and the ADC (that part I've already got working) to control a quad gang digital potentiometer to adjust the cross over frequency of a 24dB per octave linkwitz-riley filter.
edit: I meant 8-gang pot. Yikes!
It's just that simple. Typically, you would end up putting the code in a subroutine and passing the value in a variable.
Edit: If you are planning to control multiple pots and have to control them individually (set them to different values), you will need separate chip selects (obviously). You can either spend a BS-2 pin on each or use an external decoder (74hc138 or so). In either case, you would pass the chip select pin number (or pattern) to the subroutine as well as the value (obviously).
endedit
DO
LOW ChipSelectPin
SHIFTOUT SDO, SCL, MSBFIRST, [0\7]
HIGH ChipSelectPin
PAUSE 100
LOW ChipSelectPin
SHIFTOUT SDO, SCL, MSBFIRST, [64\7]
HIGH ChipSelectPin
PAUSE 100
LOW ChipSelectPin
SHIFTOUT SDO, SCL, MSBFIRST, [128\7]
HIGH ChipSelectPin
PAUSE 100
LOW ChipSelectPin
SHIFTOUT SDO, SCL, MSBFIRST, [64\7]
HIGH ChipSelectPin
PAUSE 100
LOOP
Dave,
Such manuals are on their respective product pages on our website. For example, the What's a Microcontroller manual can be found here: https://www.parallax.com/product/28123
Always check under Downloads & Documentation. Was there something more specific?
You betcha:
- Applied Sensors manual
- Basic Analog and Digital manual
- Stamps in Class manual
- and all the N&V articles
Granted, they're old but still have great information.
It's always best to show your whole program, including pin assignments and variables.
One thing I see right away is you need to connect the SDO pin of your BS2 to SDI pin (pin 3) of the 4231. Using pin 13 makes for a bus crash.
I looked at the data sheet and it is a whole lot more complicated than just writing a wiper position. Sorry, I was making assumptions and may have led you astray.
Take a look beginning on page 33. Table 4-1 is the list of register addresses. Register %0000 is for wiper 0 and %0001 is for wiper 1. Now look on page 47. You will need to send 16 bits including a 4-bit register address, 2-bit command, and 10 bit data value.
SHIFTOUT SDO, SCL, MSBFIRST, [0\4, 0\2, 0\3, WiperValue\7] 'I think
I would be careful in driving a LED with one of these. First, the wiper resistance (that is, the minimum resistance value to either end) seems to be maybe 75 ohms which is pretty low. Second, since the resistance options are 5K minimum, the LED will get pretty dim pretty fast.
Note you can also increment or decrement either wiper with an 8-bit command.
Ah yes...some of those are discontinued and so if someone requests them we can provide them, but they're not on the current site because they were discontinued before this site went up. You can still find Applied Sensors via a Google search.
http://www.digikey.com/Web%20Export/Supplier%20Content/Parallax_149/PDF/Parallax_AppliedSensorsGuide.pdf?redirected=1
You can probably do the same for the rest, however the N&V articles are on the current website. For example, try this link: https://www.parallax.com/search?search_api_views_fulltext=Nuts+and+Volts
OH! So I can control each pot separately? That's cool. I thought they were ganged. Sending the data to SDI makes a little more sense. I'm using a transistor to actually drive the LED, so there's no worries there. I'm also using the 100k version, but I suppose that doesn't matter if I'm just using it as a voltage divide with the transistor.
I'm a little confused by the COMMAND BITS. Do you use the INCREMENT and DECREMENT commands if you only want to move the wiper 1 position.....like if you wanted to use pulses....like with the AD5220 digital pot? Do I want to READ or WRITE to move the wiper, i.e., when I'm sending data from the MCU am I writing to the digipot, or is the digipot reading from the MCU?
Once I understand that, I think I understand the memory and command bits, but what makes up the data bits? Is this the location of the wiper in READ/WRITE or how many positions the wiper moves in INCR/DECR?
You want to WRITE (command %00) to move (force) the wiper. You can read the wiper position register back if you lose track of where it is (look at Figure 6-5).
When you use Increment or Decrement command, you don't actually send a data byte, so it is just one position up or down.
DO
LOW ChipSelectPin
SHIFTOUT SDI, SCk, MSBFIRST, [%00010001, 0] 'this controls 1st pot. Wiper is full turn counter clockwise
SHIFTOUT SDI, SCk, MSBFIRST, [%00000001, 255] 'this controls 2nd pot. Wiper is full turn clockwise
HIGH ChipSelectPin
PAUSE 100
LOW ChipSelectPin
SHIFTOUT SDI, SCL, MSBFIRST, [%00010001, 63] ' 1st pot. wiper is in the middle
SHIFTOUT SDI, SCk, MSBFIRST, [%00000001, 63] 'this controls 2nd pot. Wiper is in the middle
HIGH ChipSelectPin
PAUSE 100
LOW ChipSelectPin
SHIFTOUT SDI, SCL, MSBFIRST, [%00010001, 255] ' 1st pot, wiper full turn clockwise
SHIFTOUT SDI, SCk, MSBFIRST, [%00000001, 0] 'this controls 2nd pot. Wiper is in full turn counter clockwise
HIGH ChipSelectPin
PAUSE 100
LOOP
Thank you so much, Tom.
Thanks Mr. Savage. :thumb:
@byoc - Apologies, it appeared I was hijacking your thread. My intent was to locate some of these old manuals and articles so you could glean bits of knowledge from them.
Now that we know the Nuts & Volts articles are still around, I'd recommend you peruse through the library. There is a ton 'o stuff in them, and I'm sure you'll find information pertinent to your efforts.