Latching 4 bits twice to create 8 bit output - Page 1
Forum section: electronics / projects

author: ChristofferB
author_rank: Frequent Contributor
timestamp: August 03, 2015, 10:14:04 pm
content: Okay, a little explanation: i'm making a HEX keypad for a microcomputer i'm building, and I found this really cool chip at a flea market: Harris HD-0165.It's a 16 switch decoder, providing 16 switch inputs, 4 binary outputs, along with a /strobe.Now, I'd like to be able to press two HEX switches, and having it latch an 8 bit value to be read by the processor, so my design includes two 4-bit latches after one another, and a D flipflop wired as %2 to make first the first latch clock, and then the second, but I'm a little unsure as of how the actual strobe clocking will affect the latches. Here's a schematic, I'm hoping someone will be able to tell if it looks reasonably sound.And I know "verify my design" threads are the absolute least interesting, since they don't really give opportunity for debate, and I try to avoid making them,but I'm at a bit of a loss here.Thanks in advance,--Christoffer

author: T3sl4co1l
author_rank: Super Contributor
timestamp: August 03, 2015, 11:02:54 pm
content: Nice drafting, Mims would be proud I think.Linky:http://www.decodesystems.com/HD-0165.pdfhttp://people.na.infn.it/~aloisio/sn7475.pdf7475 looks to be a transparent latch, so you can't make a chain of registers. You need D-type flip-flops for that (7474, but more of them; or whatever quad or octal equivalent). What will happen (maybe) is, when the 7474 is low and /STR is low, both latches are transparent, and D[0..3] = D[4..7] = O[1..4]. When /STR rises, O[1..4] go high, the 7474 flips, and both latches turn off, holding their data (which is equal). But what was that data? Depends on the setup and hold requirements. Which are 20ns and 5ns respectively. But the HD-0165 claims 200ns max skew, so you have no idea if STR is going to rise first, or any of O[1..4], and the data in both latches may be corrupt (missing bits that changed sooner, or that changed while one gate was cutting off before the other, or fully flipped bits due to the race condition!).What's worse, you don't have any debouncing, so you'll get probably an average of three digits (give or take sigma = undefined?) from each button press!Same goes for the NMI/INT, though that also depends on whether it's a level-triggered or edge-triggered type. Either way, you'll end up with a lot of excess interrupts, and stalled CPU time, though.So as you can see, running sequential (clocked) logic from naked switches is a very unwise idea!You can use the debounce circuit in the datasheet, though since a 9602 is awfully old, you might be better off with a 74LS123 or something like that.Once you have a debounced strobe, you can use that very easily with a pair of quad registers, e.g. 74LS175, chained as shown but with the clocks all tied to the debounced strobe. Assuming you don't mind the entry order (one press causes the present "first" digit to shift over to the "second", replacing the "first" with the just-entered number).To do an in-place entry, you need all the register D's tied to the encoder O's, and some way to alternate the CLKs. You would use a 7474 as shown, but use a one-of-two selector/mux (e.g., 74LS157, but you might just as well build it from a single quad NAND) to pulse just one register at a time.You'll probably also want an LED to indicate which digit is being entered (or a pair, one for each Q, /Q output from the flip-flop). That's another advantage of the shifting method, it's fast, simple, and general for entering any number of digits.If this is just for historical interest, then this is all fine and dandy.If not... If you really have an honest-to-goodness CPU there... why not use it? Just polling the switches directly, with an IO input port (e.g., a 74LS273 and address decoder, or 8255 or similar PIO), or even polling the HD guy, in this way, is probably a better idea. Or throwing all this mess of logic into an FPGA, or using an MCU (which already has the CPU and peripherals integrated).HTH,Tim

author: MagicSmoker
author_rank: Super Contributor
timestamp: August 03, 2015, 11:05:03 pm
content: My eyes glaze over whenever I see logic circuits (I'm a power/analog guy) but you might find the site logic.ly useful.

author: ElectroIrradiator
author_rank: Frequent Contributor
timestamp: August 03, 2015, 11:50:42 pm
content: I would do all the decoding in software on the MCU, possibly combined with some debouncing of the #STR signal done in hardware.

author: ChristofferB
author_rank: Frequent Contributor
timestamp: August 04, 2015, 12:01:11 am
content: Quote from: T3sl4co1l on August 03, 2015, 11:02:54 pmThanks for the suggestion! I think i'll use the chained 175 way, because the way I see it, having something to switch between the two 175's will make it difficult to predict which will be strobed first. Maybe use a JK flipflop with J tied HIGH, the CLK to the /STR, and the K to processor /RST, but that seems unnecessarily complex.The reason I don't use a microcontroller or FPGA is because I'm trying to keep the computer I'm building as retro as possible, using only what was available in the 70's and early 80's.And yes, I could of course poll it, but I'd rather tie it to the /INT (Z80), thus having a routine there for just jumping to the lower byte address.And I sure need debouncing on the /STR and any /INT line! going with the LS123, I think, or maybe just some buffers and caps/resistors.In case my own design doesn't pan out, it seems Jameco once sold a HEX encoder keypad kit, using the HD0165, and two 74175's ! maybe that's just the way to do it:http://www.decodesystems.com/je600.htmlAgain, thanks!--Christoffer

author: T3sl4co1l
author_rank: Super Contributor
timestamp: August 04, 2015, 12:04:39 am
content: Ahah, if I'm not mistaken, that's exactly the kind of circuit I was thinking of, and precisely what you need!Tim

author: ElectroIrradiator
author_rank: Frequent Contributor
timestamp: August 04, 2015, 12:18:43 am
content: If this is a retro computer, then I'd do as the ancient ones did and try to minimizing complexity and cost, doing most of the work in software on the CPU. Remember hardware used to be expensive.A single 74LS132 plus a few discrete components can debounce #STR and also provide an ENABLE/#LOCK flag for the keypad if needed.

author: ChristofferB
author_rank: Frequent Contributor
timestamp: August 04, 2015, 12:52:02 am
content: I think the Je600 is so close to what I was shooting for, it'd be a waste not to borrow the design- I've removed some unneeded functions and redrawn the circuit.Quote from: ElectroIrradiator on August 04, 2015, 12:18:43 amthat's very true. Really, you could probably do without the flipflops, even, just pump the 4 bits into the processor directly, and then make it take the lower 4 bits, and use them as low nibble, and then again as high, but at the moment, my assembly-fu is on the "hello world" stage, so I think I'll do this in hardware-I sure hope my HD-0165 works now! If it's busted, I'll wack an Arduino in the box, doing the same job, and then I'll spot-weld the enclosure so no one may knowmy secret.Thanks again for the advice!