Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Al Williams

Dr. Dobb's Bloggers

Flip Floppy

December 03, 2011

The last few weeks I've been musing about digital logic, FPGAs, and Verilog — all things that are appearing more and more regularly in the embedded systems space. So far, you've seen some simple logic gates and how to simulate Verilog using Icarus.

The problem is, simple logic gates are only interesting to a point. Combinatorial logic can transform an input to an output. But there are several limitations. First, it isn't practical to create circuits with memory using purely combinatorial methods. The obvious place you need memory is the registers of a CPU. However, you also use circuits with memory when building state machines and other kinds of circuits you might not immediately associate with memory. For example, if you were building a traffic light, you need a way to keep track of the light's current state, and that isn't easy to do with combinatorial logic. You somehow have to feed the output of the circuit back to the input, but there are a few potential problems with doing that.

One of those problems is that real logic circuits don't react instantly. There is a small but finite delay between when an input changes state and the output (or outputs) change to reflect the new input. What's worse is that a complex circuit may have several paths between inputs and outputs that don't take the same amount of time. This can lead to all sorts of problems.

The solution — and the real action — comes when you start playing with sequential logic. I'll spare you all the hairy theory and the drawings of cross-connected inverting gates. What you really need to know is that there is a special class of logic element called a "flip flop". This funny name refers to how the element takes one state, or the other state. You can think of a flip flop as a one-bit memory cell that operates with a clock and special rules (depending on the flip flop type).

Verilog has the reg data type, which is sort of a one-bit memory, but don't get confused. While a reg is a key part of a flip flop realization, it isn't one all by itself. You'll see what I mean after you examine a few examples.

For our purposes, all flip flops will have a clock input and — this is key — the outputs only change on the rising (or falling) edge of the clock (depending on how you design the flip flop). If the clock is stable (no edge) or presents the wrong edge, then the inputs don't matter.

This is why the flip flop is like a memory. It is also how you solve the variable delay issue. Suppose you have an AND gate with two inputs. The delay between your inputs and the first AND gate input is 100nS. The delay between your inputs and the second AND gate input is 80nS. That means that if your inputs change, in 80nS the output could be "wrong" because the first input hasn't "caught up" yet. If I remember the output of the AND gate with a flip flop, and synchronize my inputs to a clock that doesn't change more often than, say, 110nS, then the output will always be correct.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.