So I was looking forward to getting stuck into the switch multiplexer development that I alluded to a few posts ago. Having maxed out on software with the display project, it was good to plug the soldering iron in and wire up the multiplexer circuit to the Arduino. A very small amount of test software completed the package and it was time to test it out.
|The switch mux test set up|
Nothing! Not a sausage. This is the point at which the 'scope got wheeled out. Effectively the software counts up in binary from 0 to 15 on four data lines to select the appropriate input. So the first thing was to hang the 'scope on these lines and look for square waves. There they were, exactly as expected. Still no mux output.
After rather longer than it should have taken me to think about it I took a closer look at the CD74HC4067 data sheet. Ahha! Chip select is low to enable and I had wired it to high. A silly mistake - all chip selects are low active but I was taken off down the wrong track by the lack of a bar over the CS legend.
|Top trace is the mux selector MSB |
Lower trace is the switch 7 mux output
Fixed that and the circuit more or less burst into life. With the 'scope I could see the appropriate switch line being selected and a nice square wave pulse into the Arduino with the correct timing for its mux slot.
In the photo you can see bit 3 of the mux input selector at the top trace. This is the most significant bit, so switches 0..7 are in the low period, 8..15 in the high period. One complete cycle of the mux inputs is one cycle of the square wave. The lower trace shows switch 7 pressed and the pulse turning up at exactly the right time for its mux slot.
Gibberish from the software though. All the odd numbered switch positions worked fine but #2 gave two switch returns, #4 gave four and #8 gave eight. Now this sounds like a timing problem related to binary transitions on the selector lines.
And so it turned out to be. It takes a little while for the mux to settle down, especially after several lines switch, such as the transition from 7 (0111) to 8 (1000). This was resulting in unstable output on the mux output line. It turned out to be very simple to fix - a delay of just 5us between setting the selector lines and reading the mux output is all that was required. Software and hardware working in perfect harmony!
So I now have the switch multiplexer working and can integrate that into the controller code. A satisfactory situation that calls for a minor celebration. I'm off to the pub!