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-increment
@/digipot-increment
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
INCpulse
Increment Step
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_INC
#pragma XOD error_raise enable
node {
void evaluate(Context ctx) {
if (!isInputDirty<input_INC>(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);
uint8_t address = (uint8_t) getValue<input_Pot2>(ctx) ? _BV(4) : 0x00 ;
uint8_t command = (uint8_t) 0b0100 ; // Increment
::digitalWrite(constant_input_CS, false); // chip select active
digipot->transfer( address | command ); // value
::digitalWrite(constant_input_CS, true); // chip select unactive
emitValue<output_DONE>(ctx, 1);
}
}