The ALM1000 has 4 general purpose digital input/output pins. What if you need more than 4 digital inputs/outputs? One solution is to use an 8-bit shift and store register like the CD4094 integrated circuit. This chip has 8 output pins that can be set to high or low depending on the value of an 8-bit number stored in the chip’s 8-bit storage register. Importantly, this 8-bit number can be sent serially to the chip in the form of a binary number via an 8-bit shift register and the chip converts this serial input to a parallel output. For example, if the number 197 is sent serially to the chip, LSB first, (binary 11000101) then output pins Q1, Q2, Q6, and Q8 will be set high while output pins Q3, Q4, Q5 and Q7 will be set low. A way of thinking about the serial to parallel process is that on every rising edge of the serial clock pin, the bits in the shift register shift one place to the right and the least significant bit drops off. The most significant bit is set to whatever the serial data input pin is set to. So if the number in the shift register is 01110001, with the serial input pin is set high (1), and the serial clock is toggled high, the number stored in the shift register becomes 10111000.
The chip includes a strobe pin. Data from each stage of the shift register is latched on a negative transition of the strobe input. The output data latch is transparent when strobe is high. By holding the strobe pin low we can change the shift register and hide the changes until we are finished, making it appear like we have individual control over all of the outputs. After new data has been shifted in we bring the strobe pin high to transfer the contents of the shift register to the eight parallel output pins.
CD4094 Pinout Diagram
Q1-Q8 – Output Pins
VDD – 5 V
VSS – 0 V
STROBE – storage register clock pin
CLOCK – shift register clock pin
OUTPUT ENABLE – enables outputs if set high (must be connected to 5 V for normal operation)
DATA – serial data input pin
QS, Q’S – allows more than one chip to be daisy-chained together by sending the least significant bit to another CD4094′s DATA pin allowing for the effective creation of 16-bit (2 chips), 24-bit (3 chips), or larger shift and store registers.
It is a fairly simple matter to connect the shift register to three of the general purpose digital I/O pins on the ALM1000. We can use PIO 0 for the CLOCK input, PIO 1 for the serial DATA input and PIO 2 for the STROBE input. Using Python we can step through the necessary sequence to serially shift an 8 bit number into the register and then set the STROBE bit high transferring the data in the register to the output pins. An example Python program for the CD4094 is attached to this blog.
Similarly, a parallel-in serial-out register such as the CD4021 could be used to serially read 8 bits of parallel data into the ALM1000.
The connections to the CD4094 chip ( or CD4021 ) are relatively easy and it can be constructed on a solder-less breadboard along with the rest of a circuit project. There are also premade break out boards available such as these two from SparkFun. They offer serial-in parallel-out and parallel-in serial-out shift register break out boards that use 74HC595 and 74HC165 shift registers:
In conclusion we can use shift registers to increase the number of digital inputs and outputs the ALM1000 can control. In future blogs we will see how to use the ALM1000 digital pins to control other devices that have serial inputs and outputs.
As always I welcome comments and suggestions from the user community out there.