# Clock synchronization and Manchester coding | Networking tutorial (3 of 13)

So let's say we have two computers here now
We want to send some data from one computer to the other so if we've seen before
We can connect the cable between them and then maybe vary the voltage
across two of the wires within this cable like say between zero volts and 5 volts
[in] zero volts is a symbol that represents a zero and [five] volts as a symbol that represents a one and so we can send
Some binary Data this way zero one one zero one
But something interesting is happening right here. Which is we have a bunch of zeros in a [row] and
In order to know exactly how many zeros we have here?
We need we need to make sure that both of these computers have a synchronized clock and this is something that's actually very important in
Networking is is timing?
To make sure that both [sides] of these of this link agree on the clock rate
So if I add a clock rate here, this is a signal basically that just alternates between zero and one zero one zero one
And what we can do is we can look at this clock
Everywhere it transitions from Zero to one
That is a point at which. [we] should read the value of the data. So we have a data signal here
we have a clock signal here and
so for this example here
we have this whole string of zeros if
We just look at how many transitions are exactly when these transitions occur from 0 to 1 on the [clock] we can see
this transition
The Data is a 1 this transition. It's a 0 this [transitions] to another 0 this transitions another 0
another 0
Another  and then a 1 [as] long as we keep track of these transitions. We know exactly how [many]
Zeros we have no matter how long this stretch of Data is as long as we have this clock
But [the] important thing is that both sides of this link agree on the same clock so that the computer that is
Sending this data is using the same clock rate as the computer. That's receiving it
So now you might [be] [wondering] what happens if these took two computers clock signals aren't running at exactly the same speed
so like maybe maybe the receivers computer is a little bit slow so [I] can show you actually what [that] might look like if we
Take that [out] and bring this in and then actually get rid of these little
transitions, so this here is a clock that is running a little bit slower than
Then the Data was originally clocked at and so what you see [here]. Is [that] you see
Here's a transition, and we get a 0 another transition to 1 and these are these are actually lining up pretty well, so far
So this 0 kind of is lining up
but here you notice we missed a zero there should be a zero here and
Then this stuff lines up pretty well
and again we miss a zero and then
[Things] are lining up [ok]
But here in this stretch where we had 5 zeros before now with a slightly slower clock
We're only reading four zeros, and then we have this last one here
And so the places where we're missing bits because of this mismatch
[I] guess between transmit and receive clocks are called clock slips
So this is a clock slip because we're basically missing a bit of information
And then you might have the sort of opposite of this if the receiving clock were running faster
You might actually get extra bits in there
But either way, we would refer to that as a clocks flip so this here is a clock slip
and
Of course if you know if we're missing bits like this then the data that we're receiving
Isn't going to make any sense so so clearly we don't want the two computers clocks to be out of sync like this
So even if they're a little bit out [of] sync
[you] [know] of course this is kind of an extreme example here where you know we were sending 16 bits
And we only received 13 bits
but even if even if these clocks are just a little bit out of sync and
Eventually over time we will have a clocks flip and that will corrupt our message
And we would have to either we transmit our message or somehow
figure out, what happened there, so
It's important to make sure that these clocks are in sync. And there are a couple ways [that] we can do that
One way that we can make sure the clocks are in sync is actually for both of these computers [to] [to] have synchronized clocks
That are either synchronized, maybe through GPS
[Antennae]
So these computers would have little antennas that would connect or that would actually receive signals from GPS satellites which are the global positioning?
System Satellites because the GPS satellites actually have atomic clocks onboard and have very very accurate clocks
And so if these computers have those GPS receivers they can synchronize their own clocks to the GPS clocks?
And then know that that the clocks between the two computers are in sync and and use those clocks for sending and receiving data
There's obviously some disadvantages to that the GPS antenna is extra hardware, so it's a little bit a little bit expensive
[and] you also need to be [able] to mount the antenna somewhere outside or on the roof of the [building] or something like [that]
But there there's definitely some network equipment that is in use on the internet that uses GPS timing to synchronize
To synchronize its clock and data
so that is that is one solution another solution is actually to have an atomic clock in the computer itself and that's
It you know occasionally that is done. It's fairly fairly uncommon
Another approach that you could take is we get rid of our slow clock and bring back our
Normal clock here another approach that you can take is to actually send a separate signal so we have a separate
We have like another
Another link or another pair [of] wires between these computers where we send this clock signal so we're sending both the data and the clock
across two different links and so that way this computer doesn't need to use its own clock it can actually receive the clock from the
Same computer that's sending the data. So it knows that these are in sync
[and] there's actually a little bit [of] a problem with that as well or potential problem [with] that
Which is that as as you increase [the] speed that you're sending this data?
These clock pulses could could actually be as close as just a few nanoseconds apart
And so it's very important that the clock and the data line up
Because if you can imagine this shifted just a little bit to the left or to the right?
[then] these these points where the clock transitions from a 0 to a 1 might not line [up] exactly with the bits
and you could miss read a bit, so it's very important that these stay lined up correctly and
And that's called clock Phase
Phase and one of the problems with sending a clock and a data across two separate links is that it's possible that
The you know the propagation of electrons literally across one of these links might be slightly slower
Either because it takes a slightly [different] path or the conductivity is a little bit different. If this is a long path, so
You tend to not [want] to do this on very high speed links over very long distances
Or you could get into an issue where the clock gets slightly out of phase with the data and you start to miss read?
some bits
So another approach that we can take that's actually quite common is is kind of ingenious which is to combine?
the clock and the Data by using different symbols to represent ones and zeros, so
Just review what we've been doing here is
When we're transmitting our data?
We're transmitting it using two symbols
And so when we want to send we want to send a one the symbol that we're using is five volts
So you can see here every time we're sending a one our symbol is that we are
Setting the voltage to five volts when we want to send a zero the symbol we use is zero volts
So now let's see what happens when we change that so instead of making well instead
Let's try to make the the symbol for sending a 1 instead of making it 5 volts. Let's make it
Actually the symbol will be transitioning from  volts to 5 volts. This is 0 volts this is 5 volts and
the symbol for a 1 is a transition from  to 5 and
Then what we can do is the symbol for sending a 0 will be a transition from 5 volts to  volts?
So this was 5 volts and we're transitioning to 0 volts so before the symbol that we were using
was
The symbol we were using for sending a one is a just a five volt signal
Now let's try sending a transition from zero volts to five volts as the symbol
So what we can do is here. Is that same signal right here?
That we're sending up here me so we can see both of these
So this is the same the same data the zero one zero zero one zero and so on
Is now being sent?
Using this scheme so for example
Here we have a transition from five volts to zero volts, so this is five volts
oops
this is [a] transition from five volts to zero volts and
So this is a zero and here we have a transition from Zero to five so that's a one here
we have another transition from five volts to zero volts so that transition represents a zero and
This is again a transition from five volts to zero volts so that represents a zero
this represents a 1 0 a 1 a 1
0 a 1 and then here you can again see those transitions from 5 volts to 0 volts as a 0 0
0 0  so very clearly there's five of those transitions, so we know there are [five] [zeroes]
and then finally we have that transition from zero volts to 5 volts, and that's a 1
So you might be wondering?
You know what's going on like here for example
That you were transitioning from 0 volts to 5 volts, so shouldn't we should we like count this as a 1 in here
And so actually we shouldn't because there's still a clock and we still expect to see each bit at a regular time interval
[so] for example you can see there's there's still like a a regular interval here where these bits are occurring
and
And the receiver can easily tell that that this
This short interval here is is drastically different than the regular interval that we see everywhere else
And so the receiver can can just ignore this
Because it because it doesn't match the the symbol rate you know even if the receivers clock isn't completely perfect
So this method of encoding that I've described here is called Manchester
[Manchester] coding
And I believe it's named after the I think it was
s invented at the University of Manchester in
the [uk] and so Manchester coding is is just an example of one of the simpler ways of
Combining clock and data into one signal so that the transmitter and receiver don't need perfectly synchronized clocks
And so Manchester coding also happens to be the type of line coding used by lower speed Ethernet which many many
Computers use for connecting to wired networks so in the next video
We'll look at exactly how ethernet uses Manchester coding in some more detail