In the last video I demonstrated a Universal Active Filter that I could adjust with a dual-gang potentiometer, here I replace the potentiometer with a processor controlled solid-state potentiometer. For those that are too young to remember, we used to say “solid-state” to differentiate between that and something that used vacuum tubes… mostly we meant you could drop it without it breakage.
The most common way to control the everyday peripheral chips available is through use of one of the common Serial Protocols such as I2C and SPI. In the before-time back when we had only 8 bits and were lucky if 7 of them worked, we used to have to memory map a peripheral or Input/Output (I/O) controller which means we had to take many control and data lines from the microprocessor such as Data, Address, Read/Write, system clocks and several other signals just to write to a couple of control registers buried in a chip.
Nowadays there is a proliferation of microcontrollers that tend to have built-in serial interface capability it is pretty straightforward to control a full range of peripheral functions; digital and analog alike. Rather than map each peripheral using said data and address lines,which is a very parallel approach, the controller communicates with peripherals serially using but a handful of signal lines such as serial data and clock. A major task of old system design, mapping of I/O and peripherals, is no longer needed.
Using Digital to Control Analog
Two serial interfaces have risen to the top of the heap as far as prevalence: I2C and SPI. I2C is a more sophisticated protocol that arbitrates who should do the talking and is basically bidirectional meaning that the data input pin can double as a data output. I2C also implies peripheral IC’s that have pre-assigned addresses and since the receivers are addressable, all can be connected together on the same I2C bus. I2C is all the better if you don’t have to debug it which I have had to do in the earlier days of the protocols existence, (but that was a while back).
I consider SPI, short for Serial Peripheral Interface, to be more of an attitude than a strict protocol as I have seen various specifications for how clocks and selects work so it is usually worth checking the details if designing for production. At the heart of SPI is a separate Chip Select for each device and a dedicated data input and output. On the plus side the data lines don’t have to worry about being bidirectional or having to deal with contention, and so they are designed as true active high and active low driven lines whereas I2C has a passive pull-up which may limit maximum speeds or loads.
In this instance I chose the digital potentiometer that I wanted and let that determine the Serial Protocol. In the video you will see the various controllers and processors that I looked at and settled on the Hackaday Pro Trinket for the simple reason it has a Hackaday skull on it.
A quick download of the IDE and I was able to speak to the module via the bootloader. Perusing the built-in examples gives us not only an SPI based project written in ”C” but also one of the two SPI examples is for a digital potentiometer. I have elected to use the MCP4161 Digital Potentiometer and even though it is a different part than the SPI example, the changes needed to the code are minor. Looking at the datasheet we find that writing a value of zero first and then a second value which indicates the resistance value of the potentiometer as a $00-$FF hexadecimal range of 256 steps. The example code sits in a loop incrementing both bytes so I changed the first byte to $00 and left the incrementing code alone as being useful for our demonstration here and recompiled.
My original plan was to demonstrate the digital pot and the filter it controlled on one PCB but ran into problems with the compatibility of too many power supplies, the grounds and even the voltage drop of the long USB cable I used to drive the demo from across the room. Using a small solderless breadboard it was straightforward to hook up the digital pots to the SPI bus and then swap them in place of the dual ganged pot.
If you didn’t see the previous video, I use a sweep frequency generator to demonstrate the effects of our adjustable filter. The function generator starts by outputting a low frequency and then quickly sweeping up to a higher frequency.
This has the effect that a properly triggered oscilloscope displays low frequencies on the left side of the display and high frequencies to the right. The frequency response of the filter as it moves between the low and high frequencies is seen as moving between the left and right sides of the display where the x direction indicates frequency.
Like our last demonstration the filters are seen moving up and down the range only now it is under the control of a simple C program and not a manual adjustment. Picture if you will, then an analog synthesizer that instead of a carefully calibrated control voltage to manage oscillators, filters and other effects, all while tracking each other closely without worrying about linearity or temperature affecting the accuracy of the control.
An Analog View
Finally, to visually demonstrate that digitally controlled potentiometer really does emulate a variable resistor I hooked up my old Simpson 260 Volt Ohm Meter (VOM) that I have had since I was 16. Let’s just say that means I have had it for almost 40 years. Setting the VOM to resistance and remembering that Zero ohms is a deflection to the right the effects of the incrementing potentiometer are readily seen.
This was just a simple example of having a processor control our analog project. These days I automatically assume that there will be a serial control bus or two in any sizable project.