Designing a 7-segment hex decoder

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so if we want to build some kind of output display for a computer we can use a register just like we've built in the past where we can push a value into that register and then have some way of displaying the contents of the register and this would be the output of the computer and so in this case you can see we have a nice binary output for for the computer but what would be much nicer is if when we put contents into that register instead of getting a binary output we get a nice decimal output like this which is much more user-friendly so let's take a look at how these display modules work so you can see there's some pins on the back and then of course our display here and here's the data sheet that comes with it or I guess just sort of the packaging and it comes in a couple different kinds the one that I have is blue and it says common anode what that means is that there's a bunch of LEDs inside this package you know one for each of these different segments and all the anodes are tied together so that's the positive side of the of each of these LEDs are tied together and on pins 3 & 8 so pins 3 Nader's the middle pins on both sides this is pin 3 and then this is pin 8 here in the middle on the other side and then the rest of the pins just control the different segments so we can hook this up on our breadboard and I'm going to connect the anode this is the the common anode which is either pin 3 or pin 8 to our 5 volt supply so this is pin 8 up here and I'm going to connect that with a 100 ohm resistor and that's because this is the blue one so it's got a 3 volt forward voltage which means that the resistor needs to drop 2 volts because 3 plus 2 is 5 and I'm guessing it doesn't actually tell me the current draw on this thing but I'm guessing 20 milliamps would be good so 100 ohm resistor should should work fine and I'll connect power this is 5 volts and then if we connect ground any of these other pins we should see stuff light up so this is that first segment second segment third segment fourth fifth sixth and this is the middle segment and then down here is also the decimal point and so you can see the inputs to this thing don't really let us input numbers per se you know we're not we're not there's not a binary input that just then displays a number we have to display numbers sort of on our own by lighting up just the right segments so if we want to light up the number one we have to connect those two segments if we want to do the number two then we have to find all the right segments for number two so it's those two and let's see it's probably this one and then this one down here and then finally this bottom one and that's how you get the number two is we have to move to manually know exactly which segments to light up to get each number but of course we have a binary number that we want to display so how do we how do we convert that so a good approach one you don't know how to solve a problem is to try to simplify the problem and try to solve that simpler problem so in this case let's let's try to solve this problem for we only have four bits so instead of thinking about eight bits and how we display that with three digits let's think about how we display four bits so these are this is essentially what we want to display for each of these bits you know zero through nine and then when we get above nine to ten instead of trying to display that as two digits we can display those as letters and this would basically just give us a hexadecimal display so instead of ten eleven twelve and so forth we have ABCDE and F and F represents 15 so this gives us a different a different display for each of the 16 values that you can have with four digits of binary so these are all the different numbers or I guess digits or things we want to display and we can create a truth table that looks at each of those cases and to simplify things even further what we can do is actually just look at a single segment in each of these and try to solve each segment by itself so instead of looking at the whole number let's just look at one segment in fact we'll start with this segment on the top here and what you'll notice is that for any of these segments we can control whether it's on or off by setting the the pin for that to either five volts which case it's off or ground in which case it's on and that and that's because these are these common anode if I had the common cathode one that it would be the other way around and you could use the same sort of logic but since these are the ones I have will do it this way and so basically if this input is is ground or a zero a logic 0 then that segment is on if that pin is a logic 1 or 5 volts then that segments off because you've got 5 volts on both sides of that LED and so there's no current flowing so with that in mind we can come up with a truth table for that segment this is the a segment each of these segments kind of by convention has a letter associated with it so a is this top one so if we look at just that segment we can see well for 0 it's on so that would be a zero right because we want that segment to be on which means we want the input for it to be at ground or zero and that turns it on for one it's off so that's a 1 for 2 it's on that's a 0 for 3 it's on so that's a 0 for 4 it's off for 5 it's on for 6 it's on for 7 it's on for 8 it's on for 9 it's on for a it's on for B it's off so it's a 1 for C it's on for D it's off and then for E and F it's on and so what we've got here is a truth table that says if you have these inputs we want that output if you have these inputs we want that output and so now the question becomes what can we build a circuit that satisfies this truth table some kind of logic circuit and if we can do that then that gives us the logic required to tell us when we should turn on that top segment and then we could do the same thing for the rest of the segments so here's the circuit that I came up with that satisfies this truth table and so what you can see is we've got the inputs d0 d1 d2 and d3 which correspond to our 4 a bit binary number that's coming in and then we have those those four inputs is d0 d1 d2 and d3 and then I've also inverted all of them so we also have the complement of d0 d1 d2 and d3 over here and then what I'm doing is using a combination of and gates and or gates to decide whether this final output should be a 1 or a 0 and the way that I did this is by looking down this column here at our outputs and looking at well when do we want our output to be 1 and it turns out there's only 4 times that we actually want our output to be 1 we want it to be 1 here here here and here and so if you look at just one of those cases when the outputs of 1 the inputs are 1 are 0 0 0 1 and so that's actually what these three and gates do here you can always think of these three and gates as a four input and gate I'm just using two input and gates for because it's what I have but what you see is I'm taking I'm an ting together D 0 so when D 0 is 1 like this when D 1 D 2 and D 3 are all zeros because if there are zeros then the complement of them will be 1 and then all 4 of these inputs will be 1 and if all 4 of those inputs are 1 then both of these outputs are 1 and this output is 1 and then that output there get soared together with the rest of this stuff and will eventually turn the final output on you know this a which of course means that that input will be a 1 and the segment will be off just like it should be for the number one the top segments not on and in number 1 same thing for 4 here this is the number 4 you can see number 4 it's also off so if number 4 d2 is high but d0 d1 and d3 are low so you can see d2 when that's a 1 but when d0 d1 and d3 when they're complements are 1 so when they're 0 then we end all that together and that also goes into this or gate and so if any of these conditions applies then we turn that on same thing down here and this is for 11 or B right because B we also don't have that top segment on and so for B D 0 D 1 and D 3 R 1 and D 2 is a zero so D 0 D 1 and D 3 when those are all 1 and when the complement of D 2 is a 1 so in other words when D 2 is 0 if all of that is true then we also turn on our output and then finally for D the letter D which is here that top segment is also not on so for D we have D 0 as a 1 D 1 is a 0 D 2 and D 3 are ones and so that's what's going on down here and actually I took a little bit of a shortcut and saved ourselves a NAND gate because for D 0 to be on and D 1 to be off we've already got that up here and so I can just pull that down and and save save and hand gate but then of course and together the case where D 2 and D 3 are both ones and so if all that's true then we also turned on so any of these four conditions where this output should be one we or those together and the output is 1 otherwise if we're in any other state this output will be 0 and so this circuit gives us everything we need in order to determine whether you know this one top segment this segment here should be on or off given a 4-bit input and so you can imagine if we do the same thing for each of these seven segments and build a similar circuit but of course come up with the truth table for for each of those different segments and build seven essentially build seven of these circuits we could we would end up with a circuit that fully fully implements this decoding and if you're thinking that sounds like an awful lot of work you're right it is an awful lot of work and I'll show you in the next video a much a much quicker way or a much easier way I guess of doing this but just to demonstrate the point I'll go ahead and fill out the rest of the truth table here you and so if I haven't made any mistakes this is the full truth table for a decoder that decodes four bits of binary to one of these hexadecimal digits and I guess I can you know just spot-checking a few things it looks like 8 so 1 0 0 0 is 8 and all of those are zeros which makes sense because 4 8 all of the all of the segments are on so at least I didn't make a mistake there but assuming I didn't make any mistakes here this is the truth table that will get us a circuit that does this and so I realize this is a little bit messy but this is the circuit that I came up with and you can see it's very similar to to the circuit that we saw before which has the d0 through de and then the inverted d0 through de and then we're looking at combinations of those so same thing and in fact this top part here is identical to what we did for segment a and then there's additional site parts for segment BC de and F and G but again I was able to save some gates because in some cases some of these things were were used previously and I could I could save some gates but even said very complex circular or at least very large circuit and in terms of number of gates and I imagine there's probably some people watching this that can look at this and find ways to you know simplify it a little bit and remove some of these gates but still it's going to be you know fairly fairly complex and so just to demonstrate that of course I built the thing and this is what it looks like and you can see it is an awful lot going on here and it's because we've got now 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 or gates and those 17 or gates are implemented on these 1 2 3 4 5 74 LS 32 s and then there's - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 and gates and those 33 and gates are on these 74 LS 0 8 so which each have four and gates there's one two three four five six seven eight nine of those and then of course we've got these four inverters which on the 74 LS 0 or and so this here should represent this circuit unless I made some mistakes somewhere but I have tested it and it works so you can see when we plug it in we get 0 because our input down here is 0 but we can cycle through and see 1 2 3 4 5 6 7 8 9 a b c d e and f and so you can see the the circuit works fine but boy it's really complicated and you can imagine that a circuit this complex just to do four bits essentially implementing this truth table you can imagine that if we had eight bits of input and instead of one digit about but we have three digits of output which is what you need in order to display the numbers you know 0 through 255 which is what you get with 8 bits of input you'd have 8 bits of input and and 21 bits of output for the 7 segments times 3 displays and the circuit would get significantly more complicated and so we don't really want to build something quite that complicated so in the next video I'm going to show you a way to use eproms to replace any combinational logic circuit and this is a combinational logic circuit because basically it has for each input there is a single output and it doesn't depend on state or anything so there's there's kind of two kinds of logic circuits there's combinational logic which is like this so for whatever input we give it we get a particular output and the output is just a function of the inputs and then there's a sequential logic which is you know things like latches and flip-flops and counters and some of some of the other things we've seen where the current state of it depends on what happened previously and there's usually a clock involved and that's sequential logic but for something like this which is purely combinational logic there's a simpler and more flexible way to build pretty much any combinational logic circuit using eproms and so we'll explore that and look at building our output stir in the next videos
Info
Channel: Ben Eater
Views: 1,438,817
Rating: 4.9264503 out of 5
Keywords:
Id: 7zffjsXqATg
Channel Id: undefined
Length: 15min 32sec (932 seconds)
Published: Sat Feb 18 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.