# “Clocking” and “Latching” with Arduino

I've just started using IC's, and am am trying to understand exactly how they work.

I know that you must first clock in data to the shift register using Arduino's shiftOut() function, then latch the data by setting the OUTPUT pin to HIGH, but was wondering what this nomenclature actually means.

Can somebody describe for me and any other beginners having the same question what exactly does it mean to clock and latch

• This question has no meaning without a context. – Eugene Sh. Nov 21 '14 at 20:50
• Ideasmith, integrated circuits (ICs) cover an incredibly wide range of applications. From context clues in your question, it sounds like you might be using a shift register IC. If that's true, then you need to specify that in your question. And we also have no idea what the "shiftOut()" function is without more context. – Dan Laks Nov 21 '14 at 21:06
• Yeah, tell us the IC part number and show us a diagram perhaps, instead of telling us an Arduino reference function why not just describe what the function does in terms of outputting the data on the GPIO pin. It seems that you need to feed in some data to the register, then enable it's outputs which will "latch" (stay) on until changed again (by clocking in different data). Is that sort of what you are trying to do/say?? – KyranF Nov 21 '14 at 21:11

Note: When this answer was written, there was no mention of Arduino in the question.

Where memory elements such as latches and flip-flops are involved, the terms clocking and latching describe what is the sensitivity of the memory element to the control signal, which is often labeled "Clock". In this context, "Clocking" means an edge-sensitive operation and "Latching" means a level-sensitive operation.

The most basic memory element is a form of positive feedback loop called a "Latch". One such element can be formed for example by cross-wiring two NAND gates so that the output of one holds the state of the other, and vice versa. It can be extended to become something called "D-Latch", which has a Data input and a Latch Enable input. Sometimes it's called a "D-follower", because for as long as the Latch Enable input is high, the output of the circuit "follows" the input of the circuit. But when the Latch Enable drops low, the output remains fixed - whatever was in the inputs when the Latch Enable drops from high to low, is "latched" into the element.

Now, consider that you would make another latch and invert its Latch Enable signal. You'd then have another latch which scans its inputs when the Latch Enable is low and holds its output when the Latch Enable is high. Understandable enough, right?

Finally, see what happens if you place this second latch "in front" of the first latch, so that he the output of the "active low" latch goes to the input of the "active high" latch. Connect the Latch Enable signals together. What you have formed is something that was originally called a "Master-Slave Latch" and quickly renamed to master-slave "Flip-Flop". (Nowadays the "master-slave" is omitted and we just call them "D flip-flops"). Combined, the operation is such that as the first latch reads its input when the Latch Enable is low and the second latch follows the first latch when the Latch Enable is high, together they form an edge-sensitive memory element. To underline this edge sensitivity and to avoid any confusion, the "Latch Enable" signal was renamed to "Clock".

This edge-sensitive flip-flop is the basic founding memory element of all digital logic, and it's immensely useful. It's state is just about instantaneously set when there is a low-to-high transition in the Clock signal. And at all other times, it does not care what happens in its input. Now consider that you have a lot of flip-flops in a circuit, and a lot of control signals that "calculate" the input values to these groups of flip-flops which we can call "Registers".

It turns out that if there's just one signal named "Clock" which goes to all the Clock inputs of all the flip-flops in the system, the system, however large and complex may it be, is completely stable. Because the states of the registers can change only following the edge of the clock, there's "calculations", toggling, of the control signals only after the edge, and if sufficient time is allowed to pass between the edges, the signals settle to a fixed state before the next clock edge comes. With this system, you can design arbitrarily complex systems, limited only by the propagation delays and clock frequency. This style of one-clock design is called "synchronous design" and I would say it's the most important digital design methodology in use today.

• Ummm... when I answered the question, it didn't say anything about Arduino, just that he wanted to know the difference between "Clocking" and "Latching". – PkP Nov 21 '14 at 21:15
• Someone downvoted your answer when it was just the first paragraph, which indeed it was a bit strange and out of place so I can see why they did it. Don't worry, your much larger edited answer is better. – KyranF Nov 21 '14 at 21:27
• I didn't downvote, but I think this answer is way over the head of the OP. He/she is clearly struggling to understand what an IC is, let alone the intricacies of combining logic gates to form flip-flips. I appreciate the level of detail and thought that went into this answer, I just don't think it'll be useful for the OP. – Dan Laks Nov 21 '14 at 21:42
• KyranF thanks, and Dan Laks, yeah I think I agree. For my defense, the question at the time was that he wanted to know what is clocking and what is latching and how integrated circuits work and I, having designed some ICs, did my best to answer that, rather complex, question. Having taken the time to write the answer, I think I'll let my answer stand, it might be useful to someone else. Thank you to you all. – PkP Nov 21 '14 at 21:49

As was mentioned in the comments, it's hard to answer this question without context (which ICs are you talking about?), but here is some general direction:

1) Those terms do not apply to all ICs, only ICs that actually use a clock signal. For example, there are simple AND and OR logic gates that have no concept of clocks or latching. Changes on the input pins are immediately propagated to the output.

2) "Latching" a signal specifically means that you are storing a value from an IC's input pins, and retaining that value even if the logic level on the input pins changes or the clock signal changes. There is usually some other pin on the IC that will go logic high or logic low to indicate when the IC should latch a new value.

3) "Clocking" data in means to repeatedly latch data in sequence and synchronized to a clock signal.

In your shift register example, assume you have a one-byte shift register attached to your Arduino. The register has one data input pin, one clock pin, and 8 output pins. Only the input pin and clock pin are attached to your Arduino. When you call the shiftOut() function, it will put one bit of your data on the registers input pin at a time, and pulse the clock signal to tell the register to "latch" the single bit (store it). This is done repeatedly ("clocking" it in to the register) until the whole byte is transferred, then the register can present the whole 8-bit pattern on its output pins simultaneously for the rest of your circuit to use.

Clocking and latching in this manner allows data to be transferred one bit at a time (serially) in a synchronized fashion.