Wednesday, April 15, 2009

4094 chips II

Following on from the previous post, here is where ill talk about what each of the 4 input pins on the 4094 chips do. These pins are Output enable(OE), strobe, clock and data.

Easiest one first: the OE pin is pretty much a global 'all outputs on/all outputs off' switch. I cheat here, because i dont really care if the lights are in a weird state before i start my program (if i cared, id keep OE low until i was ready to start doing stuff with my lights), ill just jump this pin directly to +5v. This probably isnt the best thing to do, but hey, it works and also saves me a pin. Additionally, i had trouble with this pin when supplying it from a parallel port (no such trouble using the basic stamp though). Keep this pin in mind when you are testing, as i kept forgetting about it and wondering for hours why nothing was working.

So now in order to set some states to my lights you do it in REVERSE ORDER. This is because the chip (or chain of chips) are shift registers. meaning the first bit you output gets put in slot 0. The second bit you output gets put into slot 0, and at the same time, whatever WAS in slot 0, gets shifted down the line to slot 1. So you start sending data like so: Send a state, then PULSE the clock pin. Pulsing means go 0->1->0 (or low,high,low) - this also assumes that clock is always set to low - which it should be. So repeat this process till all of your lights have been output. After the last clock pulse, all you should have to do now is pulse the strobe pin from low to high and back to low. This actually puts all the states that you just input into an 'active' mode and sets the 4094's outputs accordingly (there would have been no visible change to the output states until the strobe was completed).

4094 Serial-in-to-parallel-out chips

This is the part of the blog that gets a little programmer-ey - this post will outline how the 4094 chips work.

Firstly your basic stamp/parallel port/whatever that you are using to control the pinball machine only has a finite amount of outputs (probably 8 or 16 or something). The parallel port has 8 (more if you cheat a bit - or so im told) and my basic stamp has 16. Hobviously, this is well less than what im going to actually need if i want to control 40-odd lights and 20-odd switches. Standard pinball machines use a light/switch matrix, which from what i can guess, strobes each row of the matrix in order from top to bottom while turning on or off the required columns to light up the controlled playfield lights. I speculate that as this happens very fast and due to the fact that its using incandescent globes that take a while to turn off, it can give the illusion of always-on lighting. Anyway with the light matrix idea for up to 49 lights, i'd need a 7x7 matrix, which would still take up a good 14 pins. A good saving, but still too many.

Myself and some former workmates had once tried to make a pinmame hw board unsuccessfully, and had shelved the parts. I dutifully ninja'd these parts home and started trying to figure out how the 4094 chips worked (note that 595 chips will do pretty much the same thing, but i either couldnt find them or they were more expensive).

Off the top of my head the exact chips i had were: 74HCT4094. The other similar chip is the 74HC595 (more info and comparisons on the two from here: Also note that i learned most of what im spewing out here from that website.

Basically what the chip does is take some input from 4 (thats right, 4!) pins serially, and set a bunch of outputs (LED's) states. For example if i have 8 led's and i want every second one on, i (and this is abstracted and pseudocoded) say: "OFF,ON,OFF,ON,OFF,ON,OFF,ON". The chips goes 'ok thats the pattern, ill just set my output pins to these states - no worries'. In real life (irl) this is slightly more complicated, but thats the basic gist of it.

Ok so there are 4 input pins that we care about ont he 4094. These are data, strobe, Output enable (OE) and clock. Additionally, im powering all this from +5v DC (this includes all the led's). The chip has 8 parallel outputs, AND is so cool that you can connect multiple 4094's to each other and get n (well some large number - but the bigger it is, the slower stuff will work) led's working all from the same 4 pins!. I have 6 all lined up and working in mine thus far.

Lunch time is over! Detailed info on how to use the chips coming up later!