Bit-banging SPI from a KIM-1 clone
For M5’s ECE287 class, the final class project was to design a simple VCO using the KIM-1 clones. To do this, we used a 10k digital potentiometer to vary the resistance on a sine wave oscillator, changing the frequency in the process.
The MCP41010 E/P, found right here on the parts wall at M5, was used as the potentiometer. Looking at the datasheet, it is interfaced via a 3 wire SPI. Most of todays chips have dedicated SPI interfaces that handle timing, sampling modes, and everything else about the interface for you. The KIM-1, being about half a century old, has no such interface. So, we programmed the computer in 6502 assembly by hand to simulate the SPI interface.
Timing diagram from a logic analyzer on the KIM-1 output ports
SPI at its lowest level is a tedious list of steps that manipulate the data lines. The MCP41010 chip requires a command byte specifying write modes, and a data byte to set the value of the resistance between its output pins.
We first had to set chip select low. Then, the first two bits are don’t-care bits, followed by two bits that select the write mode, followed by two more don’t-cares, then lastly, two bits that will determine which potentiometer to write to (for the chip series that has two — we don’t use this).
Data on SI is sampled on the rising edge to SCK, so we had to program values onto PORT A and PORT B of the KIM monitor to mirror this setup.
6502 assembly code snippet
To test the device, we defined a table of data values (0x00 to 0xFF) to loop over, and send to the chip to go from a short to 10k ohms of resistance. We used bit 0 on port A for the SI line, and bits 0 and 1 on port B for the SCK and CSB lines, respectively.
Hooking it up to an LED to test it, the output looks like this:
As the resistance changes, the brightness of the LED changes — it works!
Now all thats left is to hook this up to an oscillator, and we will be all set.