Thursday, May 21, 2009

That damn flippity flop music

Otherwise known as flip-flops - these are handy structures that store 1 bit of information - a 1 or a 0. Imagine 8 of them put together and BAM - 1 byte of memory, or imagine 8589934592 and again, BAM, a gig of memory!. So I dont really need much memory for my application as it is all going to be controlled by a laptop which has its own memory anyways. What I do need, though, is a way of remembering if a button has been pressed or not in hardware. This is because (and i cant remember if i talked about this earlier) i cant guarantee that ill be checking the state of a switch while it is actually pressed, so the next best thing is to work out if it was pressed.

Now theres a heap of different flip flops that one can use: SR (set-reset), JK (not sure what that stands for) and more. I have elected to go with an SR type flip flop, which I made myself out of a couple of NAND gates. I reccomend spending some time on this site: http://www.falstad.com/circuit/e-index.html learning how stuff works. If you check out the SR flipflop (unclocked) on that site, youll see a part of the circuit im creating.

So i couldnt find any SR flipflops in a handy dandy IC package so i decided to make my own out of the heap of nand gates i had lying around. I got a little lazy and decided to do it all on a breadboard.Breadboarded NANDS to make flip-flops

Those wires hanging off are going to be terminated with a standard 40 pin IDE cable, and connected on to the actual input board (more about which later).

Thursday, May 14, 2009

Inputs

Been a bit lazy lately, been trying to buy our first house, and it is consuming a lot of my time, and is exceedingly frustrating. Aaaanyway here is a post about inputs!

So we've more or less got lights working, but now we're going to need a way to detect what buttons have been pressed and when. Remember how the 4094 chips were serial in, parallel out?? Well we're going to use a slightly different chip called the 74HC165 (which will be affectionately known as a 165 chip from now on). It takes parallel inputs, and converts them all into a handy dandy serial output for you. They work in much the same way as the 4094 chips do, but instead of setting a bit to 1 or 0, we will be reading a 1 or 0 bit to determine the current state of a switch.

Initially i had breadboarded this and it worked out fine, however when i started wiring this up to actual switches on the pinball machine, i ran into one major problem - which was almost a show-stopper. See when a pinball runs over a switch embedded in the playfield, the switch is only pressed momentarily. Now unless im checking the state of the switch at that exact time, the switch is going to read 0. Since I cant guarantee that the state will be read when its pressed down, this means i would miss out on some switch presses, which is a bad thing (tm).

Back in the day when i was writing video games for a living, we had something called a was-pressed state as well as an is-pressed state for each button. So at any stage we can know if the button is currently pressed or had been pressed in the past. I wanted to implement something similar for the pinball (maybe without the is-pressed as all switches will be momentary). I realised that i needed to do this with hardware, so i'd need a flip-flop. A flip flop can store exactly 1 bit of data, and in this case will be storing a switches state. There are various different kinds of flip-flops which work slightly differently, however i decided to go with a simple S-R (set-reset) model, which i made myself.

Next post will be alllll about flip flops for your reading pleasure.