MCP413X/415X/423X/425X
Max STEPS (128 or 256) and Max Resistance (5, 10, 50, 100 kOhm) depend on model of unit.
STEP 0 = max resistance.
digipot-write-step
@/digipot-write-step
MCP413X/415X/423X/425X
Max STEPS (128 or 256) and Max Resistance (5, 10, 50, 100 kOhm) depend on model of unit.
STEP 0 = max resistance.
SPI@/spi
CSport
CS (chip select) pin, can be any digital pin, to allow multiple devices.
Pot2boolean
STEPnumber
The Step from 0 to Max Range (128 or 256)
UPDpulse
Update the Device
DONEpulse
To use the node in your project you should have the xodballxod/digipot-mcp-spi library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.
C++ implementation
// used for MicroChip Technology MCP413X/415X/423X/425X SPI controlled digitial potentiometers and rheostats
// Reference for Wiring: http://www.learningaboutelectronics.com/Articles/MCP4131-digital-potentiometer-circuit.php
#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_UPD
#pragma XOD error_raise enable
node {
void evaluate(Context ctx) {
if (!isInputDirty<input_UPD>(ctx))
return;
static_assert(isValidDigitalPort(constant_input_CS), "must be a valid digital port");
::pinMode(constant_input_CS, OUTPUT); // set pinmode output for Chip Select
auto digipot = getValue<input_SPI>(ctx);
// Breaks the 16-bit message into 2 8-bit parts
uint8_t address = (uint8_t) getValue<input_Pot2>(ctx) ? 0x10 : 0x00 ; // Choose which wiper address (8-bit format)
::digitalWrite(constant_input_CS, false); // chip select active
digipot->transfer( address ); // address
digipot->transfer( (uint8_t) getValue<input_STEP>(ctx)); // value
::digitalWrite(constant_input_CS, true); // chip select unactive
emitValue<output_DONE>(ctx, 1);
}
}