<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>State Machines on Digital Logic Notebook</title><link>https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/</link><description>Recent content in State Machines on Digital Logic Notebook</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/index.xml" rel="self" type="application/rss+xml"/><item><title>What Is a State Machine?</title><link>https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/fsm-concepts/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/fsm-concepts/</guid><description>&lt;h1 id="what-is-a-state-machine"&gt;What Is a State Machine?&lt;a class="anchor" href="#what-is-a-state-machine"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;A finite state machine is the most general form a sequential circuit can take. It is defined by three things: a finite set of &lt;strong&gt;states&lt;/strong&gt;, a rule for choosing the &lt;strong&gt;next state&lt;/strong&gt; from the current state and the inputs, and a rule for producing &lt;strong&gt;outputs&lt;/strong&gt;. Anything that has to remember where it is and act on what happens next — a controller, a protocol handler, a vending machine — is a state machine.&lt;/p&gt;</description></item><item><title>Moore vs. Mealy</title><link>https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/moore-vs-mealy/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/moore-vs-mealy/</guid><description>&lt;h1 id="moore-vs-mealy"&gt;Moore vs. Mealy&lt;a class="anchor" href="#moore-vs-mealy"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;The two classic styles of &lt;a href="https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/fsm-concepts/"&gt;state machine&lt;/a&gt; differ in one respect: what the outputs depend on. It is the first design decision after deciding a machine is needed, and it trades response speed against clean, predictable timing.&lt;/p&gt;
&lt;h2 id="the-distinction"&gt;The Distinction&lt;a class="anchor" href="#the-distinction"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;Moore&lt;/strong&gt; machine&amp;rsquo;s outputs depend &lt;strong&gt;only on the current state&lt;/strong&gt;. The output logic looks at the state register and nothing else, so outputs change only &lt;em&gt;after&lt;/em&gt; a clock edge moves the machine to a new state.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;Mealy&lt;/strong&gt; machine&amp;rsquo;s outputs depend on the &lt;strong&gt;current state and the current inputs together&lt;/strong&gt;. An input change can ripple straight to an output within the same state, without waiting for a clock edge.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="the-trade-off"&gt;The Trade-off&lt;a class="anchor" href="#the-trade-off"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Because a Moore output is a function of the registered state alone, it is &lt;strong&gt;clean and glitch-free&lt;/strong&gt; — it changes synchronously, once per transition, and never twitches in response to a noisy input. The cost is a step of latency (the machine must clock into a new state before the output reflects an input) and sometimes more states, since distinctions that a Mealy machine draws with inputs must become separate states.&lt;/p&gt;</description></item><item><title>State Diagrams</title><link>https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/state-diagrams/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/state-diagrams/</guid><description>&lt;h1 id="state-diagrams"&gt;State Diagrams&lt;a class="anchor" href="#state-diagrams"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;A state diagram is how a &lt;a href="https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/fsm-concepts/"&gt;state machine&lt;/a&gt; is designed before any gates exist. States are drawn as bubbles and transitions as arrows labeled with the input condition that causes them. It is the specification the machine is reasoned about — the logic is &lt;em&gt;derived from&lt;/em&gt; the diagram, not the other way around.&lt;/p&gt;
&lt;h2 id="a-worked-example"&gt;A Worked Example&lt;a class="anchor" href="#a-worked-example"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The canonical example is a turnstile. It has two states — &lt;strong&gt;Locked&lt;/strong&gt; and &lt;strong&gt;Unlocked&lt;/strong&gt; — and two inputs: inserting a &lt;strong&gt;coin&lt;/strong&gt; and &lt;strong&gt;pushing&lt;/strong&gt; the arm.&lt;/p&gt;</description></item><item><title>State Encoding</title><link>https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/state-encoding/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/state-encoding/</guid><description>&lt;h1 id="state-encoding"&gt;State Encoding&lt;a class="anchor" href="#state-encoding"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Once a &lt;a href="https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/fsm-concepts/"&gt;state machine&lt;/a&gt;&amp;rsquo;s behavior is captured, each state has to be assigned a bit pattern in the &lt;a href="https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/storage/registers/"&gt;state register&lt;/a&gt;. The behavior is identical whatever the assignment, but the &lt;em&gt;encoding&lt;/em&gt; strongly affects how much logic the machine costs, how fast it runs, and how safely it fails — so it is a real design choice, not a formality.&lt;/p&gt;
&lt;h2 id="three-common-schemes"&gt;Three Common Schemes&lt;a class="anchor" href="#three-common-schemes"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Binary (sequential)&lt;/strong&gt; — number the states 0, 1, 2, … and store the number in ⌈log₂ N⌉ flip-flops. This uses the &lt;strong&gt;fewest flip-flops&lt;/strong&gt;, which mattered when flip-flops were expensive discrete parts. The cost is more complex next-state and output logic, and several bits can change on one transition — a source of decoding glitches.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gray code&lt;/strong&gt; — order the state codes so that &lt;strong&gt;adjacent states differ by a single bit&lt;/strong&gt;. Only one flip-flop changes per step, which reduces simultaneous switching and makes decoded outputs cleaner. It is most useful for machines that march through states in order, and for values that cross clock domains.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;One-hot&lt;/strong&gt; — give &lt;strong&gt;each state its own flip-flop&lt;/strong&gt;, with exactly one set at a time. It spends the most flip-flops (N of them for N states) but makes the next-state and output logic trivial and fast: &amp;ldquo;am I in state X&amp;rdquo; is just one flip-flop&amp;rsquo;s output, with no decoding. A one-hot machine is essentially a &lt;a href="https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/counting/ring-and-johnson-counters/"&gt;ring counter&lt;/a&gt; following the state diagram.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="choosing-one"&gt;Choosing One&lt;a class="anchor" href="#choosing-one"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The trade is flip-flops against logic. In the discrete and early-integrated eras, flip-flops were the scarce resource, so &lt;strong&gt;binary&lt;/strong&gt; encoding dominated. In an &lt;a href="https://applied-ee.github.io/digital-logic-notebook/docs/modern-world/fpgas/"&gt;FPGA&lt;/a&gt;, flip-flops come essentially free with every logic block while wide combinational logic is what&amp;rsquo;s precious — so &lt;strong&gt;one-hot&lt;/strong&gt; is frequently the default, trading spare flip-flops for smaller, faster logic and glitch-free decoding.&lt;/p&gt;</description></item><item><title>Sequencers</title><link>https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/sequencers/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/sequencers/</guid><description>&lt;h1 id="sequencers"&gt;Sequencers&lt;a class="anchor" href="#sequencers"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;A sequencer is a &lt;a href="https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/state-machines/fsm-concepts/"&gt;state machine&lt;/a&gt; in its most restricted, most common form: one that steps through a &lt;strong&gt;fixed sequence of states&lt;/strong&gt;, mostly marching forward rather than branching on inputs. Where a general FSM asks &amp;ldquo;given where I am and what just happened, where do I go?&amp;rdquo;, a sequencer mostly just asks &amp;ldquo;what is the next step?&amp;rdquo; That narrower job has simple, efficient realizations.&lt;/p&gt;
&lt;h2 id="how-theyre-built"&gt;How They&amp;rsquo;re Built&lt;a class="anchor" href="#how-theyre-built"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Counter plus decoder&lt;/strong&gt; — a &lt;a href="https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/counting/synchronous-counters/"&gt;synchronous counter&lt;/a&gt; advances through binary states and a &lt;a href="https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/selection/decoder/"&gt;decoder&lt;/a&gt; turns the current count into one active &amp;ldquo;step&amp;rdquo; line. Compact, and the count is also directly available.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ring or Johnson counter&lt;/strong&gt; — a &lt;a href="https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/counting/ring-and-johnson-counters/"&gt;ring counter&lt;/a&gt; is the simplest sequencer of all: the single circulating one-hot bit &lt;em&gt;is&lt;/em&gt; the current step, already decoded and glitch-free, with no separate decoder needed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A small FSM&lt;/strong&gt; — when a few input-dependent decisions are needed (wait here until ready, skip a step under some condition), a general state machine handles the branches the pure counter forms cannot.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="where-theyre-used"&gt;Where They&amp;rsquo;re Used&lt;a class="anchor" href="#where-theyre-used"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Sequencers run the parts of a system that must happen in a fixed order: multi-phase clock generation, memory and bus access cycles, stepper-motor phase drive, display and keypad scanning, and pattern or waveform generation. Their most consequential use is the &lt;strong&gt;control unit of a processor&lt;/strong&gt; — a microsequencer that steps an address counter through a ROM whose contents are the control signals for each step (microcode) and the address of the next step. That is how a great many CPUs turn an instruction into an ordered series of register-transfer operations: a sequencer, a memory, and the &lt;a href="https://applied-ee.github.io/digital-logic-notebook/docs/building-blocks/storage/registers/"&gt;datapath registers&lt;/a&gt; it steers. The counting family&amp;rsquo;s pattern circulators and the state-machine family&amp;rsquo;s controllers meet exactly here.&lt;/p&gt;</description></item></channel></rss>