Placeholder Image

Subtitles section Play video

  • when we're sending data from one computer system to another over a serial link with a simple clock and data protocol like this have showed you in previous videos how it's pretty straightforward to build a circuit that computes the parity bit.

  • So we just have our clock and data coming in here, and we just have an ex or gate and a D flip flop.

  • And out the other side comes a parity bit that we can use to validate that our message was received correctly, or at least that certain types of errors didn't occur when we received our message.

  • But of course, the parity bit is not very robust.

  • There's all sorts of errors that might be injected into our message that apparently it won't catch.

  • And it's actually pretty pretty easy to inject an error like that.

  • And you'll see the parity bit is still matching on both sides, and so we haven't actually caught this error with parity bit.

  • So in other videos, I showed you things like check sums and see our seas that are much better at catching all sorts of different types of common errors that might occur in a communication network like this, but the downside of those is that they're much more complex.

  • So CRC, as we saw in the last video, the math behind that's fairly involved.

  • So we take our message, we converted to a polynomial.

  • We then divide that polynomial by this generator Palin UMA that we come up with and then that division, Uh, after we do all that long division that results in a remainder and then we subtract that remainder from our original message, and we get the actual polynomial the message that we're going to transmit, and then we can use the mathematical fact that that transmitted message is a multiple of our generator, and the receiver can do the math on the other side to determine if any errors occurred.

  • Now that's a lot more complex than our simple little parity bit here.

  • But what I want to do in this video is actually look at the math and a little more detail and look for some patterns that exist in this math that we're doing to calculate the CRC and show how we can use the patterns that are in here, too.

  • Actually distill this fairly intimidating looking computation into reasonably straightforward hardware.

  • Let's take a closer look at this process of computing the CRC and see what sort of patterns we confined.

  • So it all starts with the message that we want to send.

  • And so this here is the message we want to send.

  • And it's if we chuck this up in the little eight bit chunks, we've got an H there.

  • That's the ass Keefer in h.

  • R.

  • The binary representation of the asking value for an age that's an eye.

  • And then here we have an exclamation point.

  • So it's a chai.

  • A commission point high is our message, followed by 16 zeros and these 16 zeros is where we're gonna put our 16 bit CRC and that 16 that CRC comes from this Ah, Harry little division problem that we've got here and it comes from the remainder of that division problem.

  • So once we've done this whole division problem, we end up with the remainder.

  • Those 16 bits are the ones that we feel in here to complete our message, plus CRC.

  • But this whole division problem starts with the message itself, because the polynomial that we start with here that we're dividing is based on our message.

  • So each time we have a one in our message Here we have a terminar polynomial, and each time we have a zero in our message of the term is not in our polynomial.

  • And so that's what we start with.

  • And so how do we get from this polynomial we start with That represents our message down to this 16 bit value that is RC RC not as this process actually work.

  • Well, looks like we're doing a bunch of subtraction.

  • So each step along here were subtracting something.

  • So we start with this thing representing our message, and then we subtract something, and then we get something, and then we subtract something else from that and we subtract something else from that.

  • And we just keep doing the subtraction until we ultimately end up with her.

  • Searcy.

  • So what is it that we're subtracting?

  • Well, it's all multiples of the generator polynomial, right?

  • Because the way that we come up with what thing to subtract is based on the process of this long division that we're doing the first term here, we say, Well, how many times is extra?

  • 16 go into extra 38 it goes X to the 22nd times, and then we take extra the 22nd we multiply it by the generator polynomial, and that's what we subtract.

  • It's another way to think of.

  • That is, if our generator polynomial is is this Exodus 16 plus X to the 12 plus X to the fifth plus one and we can line that up with the columns here.

  • But then we multiply this generator palomino by X to the 22nd which has the effect of simply moving at 22 places over to the left like this.

  • And so what we end up subtracting is a multiple of the generator polynomial.

  • And when we subtract because we're using this finite field, the result is that essentially what happens is each of these places where I've drawn these arrows essentially each of these places that lines up with the terms in our inner general polynomial.

  • We flipped the bit value there.

  • So if we have an extra 38 here, we flipped that, and we don't have it here.

  • So here the extra 34 term is not there.

  • And now it is.

  • We flipped that your ex 27 is there, we flip it.

  • And now it's not there.

  • Next to the 22nd is not there, and we flip it.

  • And it is the rest of the terms, Uh, stay the same.

  • So here, you know, these terms aren't there, and so they're not here down here.

  • Extra 30 plus x 29 or there they remain down here.

  • So we're only flipping thes four terms.

  • Then what we do is essentially you think of this sort of mechanically.

  • What's going on is you just slide this over until this exodus 16 arrow lines up with another term in this case, extra 35.

  • And then you flip those bits and you end up with this parliament down here is we just flip those four positions from this line here.

  • So this extra 35 got flipped off this exodus 31 got flipped on, um, and so forth for each of these two and everything else just stays the same, and then we just slide over to the right.

  • Let those four bits and we end up with a new polynomial here.

  • And then we could slide over to the right.

  • Keeps sliding.

  • Until this exodus.

  • 16 lines up with a term and then flip those bits and we end up with another polynomial.

  • We just keep doing this sliding, flipping those bits, sliding, flipping those bits, sliding, flipping and we just keep sliding and flipping those bits until ultimately we eventually get to the point where we slide over.

  • And now Exodus 16 lines up with the exit 16 place we've slid essentially as far over as as we can.

  • So we kind of we've gotten all the way to the end.

  • And then we do that final flip and this polynomial.

  • Now that we end up with the bottom there, that's RC RC.

  • So is messy.

  • And as complicated as his math might seem, it's actually a fairly simple algorithm to get from our message down to RC RC of just lining this up here and then sliding over and flipping and sliding and flipping.

  • And we just keep doing that will ultimately end up with RC RC.

  • Now let me show you that same mechanics of sliding and flipping represented a little bit differently.

  • So here we have our message in binary, and then this is the generator polynomial and another way we can think of it with that same sliding and flipping sort of idea is we can slide our message along like this until the X to the 16 place lines up with a one.

  • And so we sort of keep sliding and sliding and sliding.

  • And so here we have zero, and now it lines up with one.

  • It's like, OK, now that that lines up with the one.

  • What we could do is we can flip each of those four bit positions.

  • So what I'll do is we'll use a little white out here to flip each of those.

  • So that becomes a zero.

  • This becomes a one.

  • This becomes a zero and this becomes a one.

  • And now that we do that, we can keep sliding.

  • So now we just keep sliding this until the Exodus 16 position lines up with one, and there goes it lines up with another one.

  • It's now what we'll do is we'll flip those same four bits again, and now that we flip, those four bits will slide again.

  • And now this exit 16 lines up with another one.

  • So we'll flip those four bits again, and then we keep going.

  • So slide over that's still a zero slide over and still a zero slide over.

  • And now we got a one here.

  • So we'll flip those four bits again.

  • And hopefully you see, this is a pretty straightforward pattern, so we can just continue to do this.

  • Slide over until the X to the 16 place, lines up with one and then flip those four bits and keep sliding and flipping and sliding and flipping until we finally get to the end and then we'll slide again.

  • Now this lines up, and at this point, we're now at the end, so we'll do one last flip another.

  • We're we're at the end.

  • We've done that last flip.

  • You'll notice that all of the positions from Exodus 16 to the left have all been zeroed out.

  • So that's one sort of property of this operation.

  • And then the last 16 bits should be our RC RC.

  • So let's compare that to our long division here, and hopefully if I did this right?

  • Yes, it looks like it.

  • It's looks like it's the same, doesn't it?

  • Right?

  • So that's our CRC and were able to calculate it just by this sliding and conditionally flipping these four bits.

  • And so those air fairly mechanical things that we ought to be able to do in hardware.

  • And when I think about that idea of sliding bits along, what comes to mind for me is something like a shift register.

  • And so this is a 16 bit shift registered.

  • It's just made with a bunch of D flip flops, all chained together.

  • And basically the way this would work is that we've got our data and clock over here.

  • We can imagine our data coming in like this, and if we have a date a bit, let's say we have a zero here.

  • When the clock pulses that zero will be read into that first D flip flop.

  • Then the next time the clock pulse is if we have a one here at the data input than that, one will get read into that D flip flop.

  • But also the zero that was in the first D flip flop gets read in to the next D flip flop.

  • Because all these clocks are chained together, are connected together.

  • And so if each pulse of the clock each new data bit will get read into the first D flip flop here, but then each subsequent data bit just shifts along down this shift register.

  • And so this gives us something very much like that sliding that we were seeing as part of our Searcy algorithm.

  • So it seems like this would be a good place to start us with a 16 bit shift register like this that we can read all of our data into.

  • And then once we get this working, we can start to think about Okay, how would we flip certain of these bits under certain conditions?

  • So we've got our transmitter here, and if we reset this, we can see we've already got the clock and data signals.

  • I'll set up here for transmitter.

  • And so those are those are going to the inputs to our shift registers.

  • We've already got that.

  • We've got a clock that's pulsing every time there's a bit and we've got a bit that's either on or off, indicating whether it's a zero or one.

  • So we're gonna have no problem.

  • As far as getting the inputs to our shift register.

  • We just need to build the actual shit register, and to do that, we can use the 74 HD to 73 which has eight of these D flip flops in here.

  • So we're gonna need 16 of them.

  • So we need two of these chips.

  • But but each of these little blocks in here is one of these blocks in our shift register, and we could just hook them up like I've got here.

  • And actually, I've already got one of those 74 h c 2 73 is here that we used because we did use one d flip flop for our parody circuit so we can actually re use that.

  • Let me actually get rid of some of the parts here for a parody, and we can reuse the same chip for RC RC.

  • And so the first thing I'm gonna do is actually hook up a bunch of led so we can see the contents of each of the D flip flops.

  • So basically, what I'm gonna do is I'm gonna connect the outputs of each of these d flip flops up to an led.

  • So the Q p in here just so we can see because each of these D flip flops is gonna hold A is gonna store a bit a zero or one, and so, by hooking led up to each one will be able to see whether it's storing a zero or one.

  • Then I'm gonna connect the other side of each of these ladies to ground through a current limiting resister.

  • Think this is just a 270 ohm resistors, something like that.

  • And as I'm hooking this up, it looks like some of these bits are on.

  • But I guess I would expect this sort of random data in the D flip club.

  • And so now I have connected the outputs for each of these eight D flip flops that air in this in this chip.

  • But, you know, we're doing a 16 bit CRC, so we actually want another another eight bits here.

  • So what I'm gonna do is add a 2nd 74 80 to 73 Chip, um, over here and add another eight l E D's.

  • I could use a jumper here to connect my clear pin to ground momentarily, and that clears it.

  • Okay, so we've got our 16 d flip flops here, Um, and they're hooked up to led so we can see what's in them, and we've even got our clock hooked up.

  • That's this white wire that's hooked around here.

  • And so now what we need to do is hook our data into one of them.

  • I guess we'll do the one on the right here just so everything kind of makes sense and then hook the outputs of each one into the inputs of the next one.

  • So that's what I'll do next is just hook up all those outputs and inputs.

  • Actually, before we do that, there is one thing we contest, which is, uh, just hooking the data into the first flip flop and just verifying that that works.

  • So I'll just disconnect the data signal here.

  • That was we were using for parody.

  • And then I come to connect a jumper from the data pin or the data out of the Arduino into the input for the first full plop over here.

  • That should be there.

  • If I reset this, we should see the 1st 1 Yeah, we see it kind of some random stuff coming in here because I don't have the other inputs hooked in there floating.

  • But this last led We should see pretty much following the data led down here and we see that.

  • So we ignore the other 15.

  • There's a sort of reading and random floating garbage.

  • It's coming in.

  • But this last one, yeah, should be matching the data.

  • So then what we need to do is then feed that into the one next to it.

  • And so the output of that was this one is pin 19 into the input of the one next to it, which is pinned 17.

  • So let's hook up in 19 depends 17.

  • Now, if I reset this, we should see those 1st 2 And it does look like that.

  • Yeah, whatever is, it goes into the 1st 1 which comes from our data here, then gets fed into the next one on the next clock cycle and again ignore the last 14 because right now they're just garbage.

  • It looks like that's working, which is which is wonderful.

  • We keep going on, and basically, I'm just gonna connect the output of each of flip flop into the input of the one next to it.

  • So this point I've got the 1st 4 So let's just test that.

  • And yet it looks like in those 1st 4 we see data moving from right to left.

  • So that looks good.

  • I'm gonna keep going.

  • So now the output of this guy's got to go down to the input of this.

  • You know, I think I have the 1st 8 hooked up.

  • So let's reset this and just see if those 1st 8 Yeah, it looks like we're we're shifting along those 1st 8 So now I just need to connect into the 2nd 8 over here.

  • So you take the output of this led and get it into the input for that one to the output of that one that's gonna be pin to here and then the input of the one next to it.

  • That's this Elliot comes all the way over here.

  • So that's the top left again.

  • That's gonna be pin ah, seep in 18.

  • Pit two down here goes up to pin 18.

  • And so now I'm basically gonna do the same thing on this chip that I did over here, which is just wire, all of the outputs of each flip flop to the input of the next one.

  • Okay, now I believe I've got it all hooked up.

  • So what I can do is I can reset eso We've got all zeros in there.

  • Enough.

  • I reset this.

  • We should see our our bits getting shifted in and shifted all the way across.

  • You should do that for the entire message.

  • And so if we go back to that sort of slide and flip algorithm that we talked about before, we've got the basically got the sliding figured out already.

  • Now, the one thing we do need to change in the code for the transmitter is that once we've sent the message, we need to send an additional 16 zeros is you'll remember original message.

  • We had our message over here, and then we had 16 zeros that we're then gonna be filled in with the CRC.

  • So if we go back to the code for our transmitter, this is our transmitter.

  • One thing I'm a changed man.

  • Change the message too high.

  • And then, uh, we get down to the bottom here.

  • There's this little bit of code here where we're sending the parody bits would get rid of that because we aren't gonna be sending the parity bit, actually, yeah, get rid of that.

  • And then what we want to do after we send our data.

  • So this is the loop where we send the data.

  • We want to send those 16 zeros.

  • So I just had a loop here, and basically in this loop, we just want a pulse.

  • The clock, which we actually have code for here.

  • So we use that and we want to send zeros.

  • Let's make sure we so see what we're resending DX data.

  • Make sure date is low, so center data low, and then we will send 16 clock pulses.

  • Then we don't really need that parody stuff anymore.

  • Until this should send 16 zeros is sent.

  • Hi.

  • This is our message.

  • Hi.

  • Um, and then we'll send the message down here, and then we'll set our data low, and then we'll pulse our clock from high low 16 times.

  • So that'll send 16 zeros.

  • Someone s save this.

  • Make a new folders Will be transmitter CRC transmitter, CRC.

  • It's now let's program this Look the USB up and upload.

  • All right, there goes.

  • It's sending high and not sending a bunch of zeros that looked like it worked with you.

  • We can reset it just to make sure, but there's our h.

  • There's our I.

  • There's our exclamation point going across, and then it just sends a bunch of zeros.

  • So that's what we want.

  • Remember, that was originally what we had on this piece of paper here because we had our message here, and then we had zeroes over here.

  • And then once we run it through our little algorithm, we'll get our CRC over there.

  • Okay, So with our shift register, we've pretty much taking care of the sliding part of our slide and flip mechanical CRC algorithm.

  • But we still need to worry about the flipping part.

  • So we're saying that once we start sliding this are shifting this data into our shift register here.

  • Once we get the one down here in this last place, we then want to be able to flip some of these other bits.

  • It's normally when you think about flipping bits, you might think of using an inverter, and that certainly makes some sense.

  • But we don't always want to invert the bits.

  • We want to selectively invert them, everyone to invert them conditionally.

  • And whenever you think about conditional inversion, the first thing that should come to your mind is an ex or gate.

  • If you look at the truth table for an ex or gate.

  • What you'll see is that if you have one input, say the A input here is zero.

  • Then the output of the X or gate is going to be the same as the bee input.

  • So whatever comes in to be is what the X or gate outputs.

  • But if the A input is a one, then whatever the X or outputs is gonna be the opposite of whatever the be input is, any time you think you might need a conditional inversion, X or gate is definitely the first place you should look.

  • And that's gonna be useful because what we want to say is we want to say we want to invert the bits that are in these other positions whenever there's a one in this last position.

  • Now the other thing you might have noticed is that our polynomial goes from Exodus 16 down to one, which is really X to the zero.

  • So if you go from 0 to 16 then that gives you 17 places and we've only got 16 flip flops, so this doesn't quite seem to line up, so you have to do something about that.

  • But one thing that's sort of interesting about that is that if we look at this original thing that we did here before, we started out over here and we're feeding this through.

  • And so, yeah, we were looking at the span of 17 bits, but this last bit that we were flipping the sex with 16 bit.

  • The result of flipping that each time meant that all of the bits out here to the left ended up is all zeros.

  • And then we ended up with the last 16 bits here being RC RC one a shift register.

  • If this is our shift register, it's not really that important that we flip that last bit every time because we're basically tossing it out the end of our shift register, and we're losing it anyway, So it doesn't really matter that we set it to zero.

  • So you kind of think of it as the bits we want to flip are the bits that are going into thes three places.

  • We really don't need to flip that last bit because we're discarding it anyway.

  • And then the other trick here is, rather than thinking about how we flip what's in the register.

  • What we could do is think about flipping the data as it enters the register.

  • So if we just slide this over a little bit, this maybe changes the way we can think about this.

  • We can say if what's coming out of this last register is a one, then what we want to do is when we do that shift, we wantto foot the bit as it shifts from one registered to the next one.

  • I flipped that bit as it shifts from the one register the next, or here want to flip the bit as we read it into the first register.

  • And so that way we don't need to think about how do we flip a bit in a register and we don't have to think about, Well, how do we handle this 17th place over here?

  • If we would actually try to line it up like that, lying up this way helps us out a lot and in fact, what we could D'oh is just in those spots.

  • If we insert an ex or gate, that'll let us invert that bit as it moves from one registered to the next.

  • So it's gonna come out of this register, go through that X or gate and then whether it inverts it or not as a go see that X or gate will depend on this other input.

  • And that other input comes from this last position over here.

  • So if this last position is a one, then we're gonna invert the bit as it moves from this flip flop to the next.

  • We're gonna invert this bit as it moves from this flip flop to the next, and we're gonna invert the new bit that's coming in.

  • But if we have a zero in our last register over here, then all these X or gates will just pass along whatever bits being input into them.

  • And so it'll work just like it did before.

  • Now I think this new design here will not only do the shifting like we were doing before, but it will also do the flipping when we need it to.

  • And so hopefully if we just add these three x or gates to our circuit will be able to compute a CRC.

  • So let's give it a try now, Conveniently, we've already got a 74 h c 86 over here, which is a quad X or gate s.

  • So this is what that looks like.

  • We got four X or gates in there.

  • We'll start by hooking in this first X or gate all the way on the right here.

  • So instead of our data going directly into her first D flip flop, which is this yellow wire here, we'll go through an X or gate.

  • Okay, so our data now is going into pin nine here and then coming out pin eight.

  • So we're going into one input of the text or gate coming out the output of the architect or gate and back in to our initial data input.

  • So then we'll need to connect.

  • Pin 10 which is the second input of that ex or gate will need to connect that around to our last D flip flop here.

  • And the output of that last D flip flop is pin to over here.

  • It's rather than connecting that directly up there.

  • What I'm gonna do is connect it to the other X or Gates.

  • So just sort of changing around.

  • We're gonna need that same signal to go to all three of the X or gates that we're using looking pin 2 to 1 of the inputs for first X or gate down there.

  • And then I'll continue that around to one of the inputs for another X or gate.

  • And then I could bring it around to the top two in input for that third ex or gate, which is the one of the top that were using before.

  • So now we have our data coming out is going into this X or gate at the top.

  • The second in putting that X or gate is the last flip flop here in our little string here and in the output of that ex or gators than going into the input over here.

  • So now we've got this X or gate here on the right, hooked in.

  • We've also got these two pins of these two X or gates wired up.

  • Now we just need to insert these two X or gates into the right place in our shift register.

  • And so this one here is gonna be after 1234 fives after the fifth.

  • So between the fifth and sixth, we want insert that X or gate until we look over here.

  • This is the first.

  • So 12345 So it's between this one and this one.

  • So the output of this was gonna be pin nine, and the input of the 6th 1 is gonna be pin seven.

  • So between pin nine and pin seven, we should already have a jumper.

  • And we do.

  • That's this jumper here.

  • Pull that jumper out instead of a jumper, we're gonna have to get that all the way over to one of these X or gates.

  • So the output there is going to go to input over here.

  • And so that's either pin four pin five.

  • Already using PIN force up in five will be the other input.

  • And so pin for infant fiver, the inputs the output has pinned six pin sixes, then gotta come all the way back over to the right here in six times, all the way back over here as an input to the next.

  • Okay, so that should insert that X or gate.

  • So then we now need to insert this X or gate, which probably the easiest account from this side.

  • So 1234 and five said between the fourth and fifth from from this side, which is actually just gonna be It was four on each side of this.

  • So it's gonna be this jumper that jumping from one side to the other.

  • I pull that jumper out.

  • And so now the output up here is gonna come down into one of the inputs of our ex or gates up in what I'm already using.

  • Celia's pin to is the second input for that X or gate and in the output of that ex or guilty pin three and soap in three, then comes around to the input down here.

  • It's now I've inserted that third ex or gate.

  • So at this point, we should have this entire circuit built, which means that if we send our data clock and data here, we should compute the CRC.

  • So this is the moment of truth and just remind ourselves what that c R.

  • C is.

  • Here's what we computed before, so let me reset and we should see data shifting.

  • But when this gets to the end, we should see things not quite exactly shifting.

  • And is that it?

  • Is that right?

  • That looks like it's right 001100011111101 Perfect.

  • So we've computed the CRC in completely in hardware.

  • Okay, so now that we can compute the CRC and we're doing that on the transmitter, we need to be able to compute the CRC on the receiver as well.

  • So we need another circuit identical to what we have on the transmitter over on the receivers.

  • We need to build that now, conveniently, I've already prepared one, and so this is identical to this Should be should be exactly the same.

  • And so I'll just go ahead and swap that in in here in place of the parody circuit, and then we'll hook up the clock and data, too.

  • A receiver actually just noticed one thing that I didn't D'oh, we're here is I have the unused inputs for the one X or get that.

  • I'm not using its have this tied to ground.

  • So we do that on this one here, too.

  • Okay, Now let's power up the receiver with a c.

  • R C circuit.

  • It looks like it's come up with some random stuff here, but we can reset that.

  • We've reset that and I'll reset the transmitter as well.

  • And now if I reset the transmitter, we should transmit the message.

  • No, that's not working.

  • What did I do wrong?

  • I would have my clock and data plugged in the wrong place.

  • I think I d'oh!

  • So let's see here.

  • Data clock is their date, is there?

  • I think.

  • Let's reset and try again.

  • There we go until we see the same thing on both and we should see it compute the same CRC on both.

  • So that gives us some assurance that what we received is the same as what we sent because the CRC is the same.

  • And in fact, if we wanted to test that, we can if we reset here and I'll just reset all the CR seas again Now if we retransmit this again and all injecting error this time.

  • So now we have an error here, and we should see that we get a different CRC.

  • And so no surprise our seer sees don't match.

  • But of course, in reality, that's not how a CRC check works.

  • You don't just compute the CRC on the transmitter, compute the CRC on the receiver and look at both because you know how.

  • How does the receiver look at the CRC on the transmitter?

  • The receiver is the thing that's validating the message, and all it has is the seer.

  • See that?

  • It's computed, so it has no way of knowing that is different.

  • So what we need to do is we need to transmit the CRC that's computed on the transmitter to the receiver so that the receiver can do that comparison, if you will.

  • And we actually have to make a few changes here on the transmitter in order to do that.

  • So if you look at what we've got right now, this is essentially a block diagram of our our set up here.

  • So you got the Arduino on the one side with transmit clock and data.

  • Which of these two ladies going over to the receiver and we have a receive clock and data over here, and those are connected across our transmission medium here.

  • There's also a ground wire in here that I don't show on the diagrams, So everything is a common ground reference point.

  • But then the CRC computation on both is just sort of tapped in to the clock and data on both sides.

  • And so, of course, if there's no errors, you'd expect to see the same CRC on both sides.

  • There's a couple problems with the way that this is set up right now, because when we want to use a CRC, what we're doing is we're taking our message and we're adding these 16 zeros at the end of the message, and we do that so that when we compute the CRC, we can fill in those last 16 bits with the actual CRC.

  • But in this case, what we're doing is we're sending our message, and then we're sending 16 zeros and that so we could get the 16 zeros into RC RC computation up here.

  • But we're also at the same time sending those 16 zeros to the receiver.

  • We don't actually want to send zeros to the receiver.

  • We want to send the CRC to the receiver.

  • So what we need is we need some way to get the CRC out of this computation.

  • So once we've computed it, we've got to see our sea here, and that's that's great.

  • But we need to get the CRC out of here and then transmit each of those bits across our transmission medium to the receiver somehow.

  • And so that brings up to sort of questions, right?

  • So one question is, how do we get data out of the CRC into our daily knows?

  • We need some wayto get the data from the CRC computation back into the artery, know so that we can then transmitted across.

  • And then the other question is, when we're sending those zeroes in, how can we clock those zeros into the CRC computation without also sending them across to the receiver?

  • Well, where we can do that is at a couple extra control signals.

  • So this is what I've come up with here.

  • And so what I've done is separate the clock for the CRC computation on the transmitter to a separate CRC clock signal.

  • So when we're sending our data, you know, we'll put our data out here on the TX data line and then also pulse the TX clock to actually send the data across, but at the same time will also pulse the CRC clock and so that I have the same effect has when RC RC, you know, as configured Now the clock and eight are connected directly to our transmission lines.

  • So here we just plot pulse, this t X clock and CRC clock at the same time, and then I'll have the same effect.

  • But then when we get to the end of our data and we need to push those 16 zeros into RC RC computation thing in order to actually get the CRC, then we don't pulse the transmit clock.

  • We just put a zero out on our T X data and we pulse the CRC clock 16 times and that'll push 16 zeroes in here, and then we'll actually have the CRC in our CRC competition, just like we do here.

  • But we won't have sent those 16 zeroes across to the receiver.

  • So the next thing we need to do is we need to get the 16 bit CRC out of here and actually transmit the CRC to the receiver.

  • And so for that we have an output here.

  • So what were the output?

  • Will you do?

  • We could just read each bit out of here.

  • We can just keep pushing these bits along, read each one out into the Arduino, and then the Arduino could just pass that along to the transmit data and pulse that t x clock to send the 16 bits of the CRC over to the receiver here.

  • So let's put this up.

  • So instead of our clock coming from our transmit clock here and going up to RC RC computation thing What?

  • I'm gonna d'oh remove that and hook this clock instead up to pin 13 of my art.

  • We know this is just a completely new unused pin on the Arduino that I can use for the CRC clock.

  • So now I got this separate clock line and then the other thing I want is I want to go to get the output from the CRC computation and be able to feed that back into the Arduino.

  • So I wanna be able to pull data out of this thing and get it back into the artery.

  • No, and I won't take this last bit here, and that's connected to pin, too.

  • And it's coming out of pin to I should say and feed that into my yard.

  • We know, So I'll feed that into ah oh, where we pin 10 I guess.

  • And so what that's gonna do is that's gonna take the output of this shift register and feed that back into the artery.

  • No, that's RC RC output.

  • In that way to get the CRC out, we just need to shift all of those bits out and read them back into the yard.

  • We know however, there is a little bit of a problem with this, which is that once we have a valid CRC in here, we wanna be able to shift it out without modifying it.

  • And the way this circuit is set up, we can't really do that because we've added these X or gates.

  • And so what's gonna happen is as it's shifting out, if there's ever a one here than these, X or Gates are gonna start inverting things and it's gonna mess up our CRC, and we aren't actually going to get the correct CRC out the other end.

  • So to fix that, what we need to do is we need to have some way of sort of turning off these X or gates to say that Hey, we just want to read what's in here.

  • We don't wanna we don't want we don't want to do any of this inversion, and so we need a little bit of extra logic here to be ableto inhibit these X or gates just while we're reading the CRC out.

  • And since I don't really have any more room on the bread boards for any more logic, I came up with a little ah, little hack here with some die odes to do the logic and effectively.

  • What I'm doing here is I'm just creating an and gate with to die odes and a resistor, but just a walk through what's going on here?

  • What we've got here in the normal case is if we're not just trying to do that read operation, we're just doing the normal CRC computation.

  • Then this active, low read thing will be high.

  • I won't be active, So this is high and we've got this pulled hi to five volts through 100 Kate resistor.

  • Then effectively, This will normally be high right here.

  • And because this both sides of this diet or high, there's to be no current flowing through that die owed.

  • This will just normally be high.

  • And then, if the output if the end here of our 16th flip flop is high, then you know no current flows through this diet either.

  • And this is still high.

  • So if this is hi, this is high Which is just how it worked when we had a wire.

  • Right, If this is hi, this is high.

  • But if what happens is the operative this goes low then we have current flowing from our five volts through a resistor through this die owed because current can flow that way through the dia and and being sunk by this low output here In that case, because this is high and this is low on the other side of the dye owed, the die only drops about 0.6 volts.

  • So this side here will be just 0.6 folds and that's that's low.

  • And so now this will be low.

  • So to summarize, if the output here goes low, then this side goes low as well.

  • Which again?

  • Same is if we just had the wire, right?

  • This is low and it's low.

  • So that's the normal case where this read, Linus.

  • Hi.

  • But if we bring the reed line low, then what that does is it creates a current flow this way through this diet, which means we're high.

  • Where five volts here were a desirable tear.

  • The Daio drops 50.6 volts or so.

  • So we'll have 0.6 volts here.

  • So thou this this note will be low.

  • And I will always be low even if this side goes high, because current can't flow this, you know, from high to low through a diary.

  • That way, that's that's the wrong way.

  • That's why we have a die out there.

  • And so as long as our read line is literally pull that low, then this will always be low.

  • Which means that these X or gates will always be inhibited.

  • So this just gives us a control signal that we can use to sort of turn off the inverting operation of these X or gates regardless of what's going on here.

  • But if the read lines high, then it works normally like we saw before.

  • So what that means is that we're gonna add that read line to RC RC thing and we're gonna see RC read signal on Arduino.

  • And of course, this will be connected just like that.

  • So with that out of the way, let's go ahead and build our little Daio resistor and gate thing.

  • So we're replacing this wire that goes from the output of the last flip flop around to all of these X or gates.

  • So that's this wire right here.

  • Well, kind of Pull it halfway out and I'll replace that wire.

  • Actually, with this first die out on the left.

  • So that comes out and this dial goes in, then this side of the diet, we want to pull 25 volts through 100 k resistor There's a resistor, and then we have another die.

  • Oh, that goes to the read signal, which we're gonna connect around to the Arduino somewhere.

  • So let's see.

  • I can put another die out in here.

  • I'll just jump over to an unused part and then the other side of that die.

  • Oh, it is there that I could bring that down to, my lord, we know, and that'll go to pin looks like D 11 on the Arduino.

  • There we go.

  • Okay, so now we've got all of this stuff hooked up means that we now have the ability to control the clock to the CRC independently of the clock of our transmit clock.

  • And it means that we can read the output of the C R C a cz.

  • Well, now we just need to update the code that's running on Arduino to take advantage of all this.

  • All right, So first, what I'll do is I'll go ahead and define our additional pins here so we don't have a parody pin anymore.

  • But D 10 is now the CRC output pin because rename this Searcy output and then pin 11 is going to be that CRC read that we just built.

  • And then the other pin, we've got his pin 13 here, which is that second clock for the CRC, That sea air, Sea clock.

  • It's been 13.

  • Those are new signals and say we don't have parody anymore.

  • We have Searcy output, which is confusingly going to be input because its output from the CRC computation, which will be input to the Arduino.

  • Then we've got Searcy read, which will be output.

  • That's a control signal.

  • The Arduino is gonna tell the CRC computing thing that we want to read from it and we have CRC clock, which is output, because it's a clock signal going to the CRC computer thing.

  • Okay, so we keep going here.

  • Initialize are still CD.

  • And here is where we are.

  • Just where were you?

  • This is where we're transmitting.

  • And so we'll need to make.

  • Wouldn't change here, which is when we pulse the clock.

  • Not only do we want her pulse the transmit clock, we also on impulse, the CRC clock because each date a bit that we send, we want to send to both the receiver into the C R.

  • C circuit.

  • Then here we're gonna send our 16 zeros.

  • And so when we send our 16 years, we don't want a pulse.

  • The transmit clock, we want a pulse.

  • The CRC clock.

  • This will send the 16 zeros now just to the C R.

  • C circuit.

  • At this point, let's actually give this a try and see if it's working so far.

  • So I plug in my USB and upload.

  • I didn't reset anything, but let's ah, reset our receiver here and reset her.

  • Receive CRC.

  • And now let's reset this.

  • Now we see it's sending the data to both and then at the end.

  • That's interesting.

  • So it's sort of working, says a couple things going on here.

  • So, first off, what you'll see is that when it's sending the actual data it's sending it tow boats.

  • So you're seeing it go into this c.

  • R C circuit and you're seeing it going into the serious C circuit.

  • But then, when it finishes sending the data and it sends the 16 zeros, it's only sending them into the sea Air C circuit here is not actually sending them across our transmission medium.

  • But what's interesting is that when it sends those 16 zeroes in, it's just sending them in.

  • And it's not actually computing the CRC, and it's just filling it with zeros.

  • And I believe that is probably because this read signal is probably telling it that we're in read mode because I didn't actually do anything with that.

  • And we probably did set that high since its active low.

  • It's probably defaulting toe low and so everything we send in, it's not.

  • It's not doing these X oars, and so it's just sending the data in and and shifting it across.

  • So look at the code and make sure we initialize that read signal.

  • Hi.

  • Let's just go up to the top here.

  • Um, yeah, I guess we could just do it here and make sure CRC reed is high which means that we're not reading, which means that it should computer CRC and I'll blow that.

  • Okay, right off the bat, that looks better.

  • But just to validate everything, let's reset and clear all of the things.

  • And now, if I reset this, what's gonna happen?

  • It's gonna transmit the h.

  • It's gonna transmit the eye.

  • It's gonna transmit the exclamation point.

  • It is no longer transmitting anything, but it is filling the rest of this zeros such that when it's done, we have the correct CRC, right?

  • That's we double check our math here.

  • That's the correct CRC in there.

  • So this point, we've sent the data and we've computed the CRC.

  • Now we just need to send the CRC instead to do that.

  • What we needed was toggle this into read mode and then read the output of the CRC as we pulse this clock and then take that output and send it out the data to the receiver Over here.

  • Let's go down here.

  • Here we send our 16 zeros.

  • So just to back up here a second, we're gonna send the data who transmit the data.

  • Then we fill the CRC circuit with 16 zeros and now we need to read the CRC from the C R.

  • C circuit.

  • So to read from the C R C circuit, first thing we need to do is put it in to read mode that ways we pull the data out, it's not gonna keep doing those those X whores or those inversions.

  • And I just want to go through 16 bits and who read out the data.

  • Actually, what I'll do for now is just print the CRC on the screen.

  • So I read it into the Arduino imprinted on the screen.

  • So let's, um And then what we can do is weaken d'oh LCD that print Searcy output.

  • And then if that is high, we want to print one.

  • Otherwise, we will print a zero.

  • So that'll grab the left most bit out of the C R C circuit, and then we want to do is shift everything in the C R C circuit left.

  • Once we get the next bit.

  • And to do that, we just need to pulse the CRC clock.

  • So I'm just gonna grab this code here, which does a delay, and then it pulses the Searcy clock high, and then a delay and then impulses this year see clock low.

  • So that'll pulse the Searcy clock and then I think that's all we'll d'oh!

  • And what that should do is just go through and grab 16 bits out of the CRC and print them on the screen.

  • So that should read in the CRC.

  • So let's go ahead and upload that and you can see is reading something in there.

  • But let's go ahead and reset everything and we'll run this again.

  • You know, what it's gonna do is it's gonna send the h, it's gonna send the eye.

  • It's gonna send the exclamation is gonna push 16 zeros into the CRC, and then it's gonna read the contents of the C R.

  • C out.

  • And so there we go.

  • That is our Searcy, and we can look here.

  • And in fact, that is the correct CRC.

  • It's now the only thing left to Dio is to actually just transmit the CRC over to the receiver.

  • And that should be simple enough, right?

  • Because essentially, what we just want to do is want to take whatever we're reading from the C R C circuit and send it so to send it we're gonna do a digital right for a TX data and we want to train our transmit data to basically just be that same bit from RC RC And then instead of while not instead of.

  • But in addition to Paul saying the CRC clock, we also want a pulse, the transmit clock.

  • So this is just gonna be take the transmit clock high and low.

  • I read the CRC circuit CRC from the Serie C circuit, and so let's upload that.

  • So go ahead and reset everything.

  • And at this point, now that we're actually computing and transmitting the entire message with the CRC, I want you to think about what's gonna happen on the receiver here.

  • Because at this point, what we're doing is we've got our message.

  • We've computed our Searcy and we've added the CRC to the message.

  • So what we're transmitting now is this entire polynomial and the whole purpose of what we're doing here is that this polynomial will be divisible by our generator polynomial.

  • So that means that if we compute the CRC of this transmitted polynomial and what is that sea air sea going to be?

  • In other words, this transmitted polynomial is computed to explicitly be divisible by our generator polynomial.

  • So if we then on the receiver are dividing this by our generator polynomial the remainder, that is the CRC oughta be zero.

  • So let's give it a try.

  • We're transmitting our h.

  • They're transmitting our eye.

  • We're transmitting our exclamation and we're feeding 16 zeros into the C.

  • R.

  • C circuit here and now we're reading that CRC out and transmitting it.

  • And when it's done, we've received a CRC here, and the computer computed CRC on the receiver is now zero.

  • And that's actually how we validate that.

  • The message was received correctly is because the receiver is going to receive the message plus thes two extra bites, which are the 16 bits of the CRC.

  • So this one in this division symbol that just happens to be what are CRC, you know, works out to be If we just ignore that part, we have our message.

  • And then we have this extra bit that when we compute the CRC of that whole thing, the Searcy is zero, and that zero validates that we received the message correctly.

  • And so for the reset everything and transmit and this time.

  • Inject an error.

  • Oops.

  • I forgot to reset this side.

  • We'll let it go.

  • We'll just reset that.

  • Clear This again.

  • Okay, so now I'm gonna recent returns made here.

  • The sides reset.

  • Now, if I inject an error so we get some error in here when we compute the CRC and send the CRC, we know we have an error because their final CRC on the receiver is not zero.

  • So because this is not zero, we know that that is not our message.

  • It's now this po

when we're sending data from one computer system to another over a serial link with a simple clock and data protocol like this have showed you in previous videos how it's pretty straightforward to build a circuit that computes the parity bit.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it