MCP42100 Potmeter with SPI
The MCP42100 controls the resistance for the XR2206 function generator. Together with the MCP4921 the MCP42100 determines the output frequency. In such a configuration, it should be possible the generate exact musical frequencies. Testing will begin soon!
Pin 8 and 9 are connected to enable rheostat mode, the outputs function as a resistor. The output resistance of the MCP42100 can vary between 0 and 100 Kohms.
The MCP42100 connects to Arduino pins 10,11 and 13.
MCP pin 1 > Arduino 10
MCP pin 2 > Arduino 13
MCP pin 3 > Arduino 11
Inspired by Totus Terra’s work on the SX-150.
//--- SPI code #define DATAOUT 11 #define DATAIN 12 //not used #define SPICLOCK 13 #define SLAVESELECT 10 #define NOTEON 9 void SPIInitialize() { byte clr; pinMode(DATAOUT, OUTPUT); pinMode(DATAIN, INPUT); pinMode(SPICLOCK,OUTPUT); pinMode(SLAVESELECT,OUTPUT); digitalWrite(SLAVESELECT,HIGH); //disable device SPCR = (1<<SPE)|(1<<MSTR); clr=SPSR; clr=SPDR; delay(10); } char SPITransfer(volatile char data) { SPDR = data; // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }; return SPDR; // return the received byte } //--- MCP42100 code byte SetPot(int address, int value) { // Slave Select set low to allow commands digitalWrite(SLAVESELECT, LOW); // 2 byte command SPITransfer(0x10 + address); // 0x10 = 'set pot' command SPITransfer(value); // Value to set pot // Release chip, signal end transfer digitalWrite(SLAVESELECT, HIGH); } //--- Application code void setup() { SPIInitialize(); // Initialize the SPI interface SetPot(1,10); } void loop() { // nothing }