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-to-class
@/digipot-write-to-class
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
POT@/digipot-class
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 spi = getValue<input_SPI>(ctx);
auto digipot = getValue<input_POT>(ctx);
uint8_t address = (uint8_t) getValue<input_Pot2>(ctx) ? 0x10 : 0x00 ;
//uint16_t command = ( (uint16_t) 0b0011 ) << 10;
::digitalWrite(digipot, false); // chip select active
spi->transfer( address ); // address
spi->transfer( (uint8_t) getValue<input_STEP>(ctx)); // value
::digitalWrite(digipot, true); // chip select unactive
emitValue<output_DONE>(ctx, 1);
}
}