---
title: Step‑by‑Step Guide: Building a Flash‑Based State Machine Using Programmable Logic Arrays
siteUrl: https://logzly.com/palflashlogic
author: palflashlogic (PAL Flash Logic)
date: 2026-06-17T13:08:27.313739
tags: [programmablelogic, flashmemory, statemachine]
url: https://logzly.com/palflashlogic/stepbystep-guide-building-a-flashbased-state-machine-using-programmable-logic-arrays
---


Ever wondered why your coffee‑maker seems to “know” when to stop brewing? That little piece of magic is a tiny state machine tucked inside a flash‑based programmable logic array (PLA). In today’s fast‑moving world of IoT gadgets, being able to design such a machine yourself can save you time, money, and a lot of head‑scratching. Let’s walk through the whole process, from concept to a working prototype, in plain language and with a few stories from my own lab bench.

## What is a Flash‑Based State Machine?  

A state machine is simply a circuit that moves through a series of defined conditions, called states, based on inputs it receives. Think of it as a flowchart that lives in silicon. When we say “flash‑based,” we mean the logic is stored in non‑volatile flash memory, so the device remembers its configuration even when power is removed. A PLA is a type of programmable logic device that lets you implement any Boolean function by programming a set of AND and OR planes. Combining flash with a PLA gives you a compact, low‑power way to run a state machine without a full microcontroller.

## Why Use a PLA for This Project?  

- **Simplicity** – No need to write firmware; the logic is hard‑wired.  
- **Speed** – Changes happen at the speed of a gate, not a CPU instruction.  
- **Power** – Flash‑based PLAs draw far less current than a tiny MCU running a loop.  
- **Flexibility** – You can re‑program the flash if you need to tweak the state table later.  

When I was a graduate student, I built a traffic‑light controller using a tiny CPLD (a cousin of the PLA). The first time I saw the lights change without any code running, I felt like a wizard. That thrill is exactly what we’ll aim for here.

## Step 1: Define the State Diagram  

Start by listing every condition your system can be in and how it moves from one to another. For illustration, let’s design a simple three‑state machine that controls an LED strip:

1. **OFF** – LED off, waiting for a button press.  
2. **FADE_IN** – LED brightness ramps up.  
3. **FADE_OUT** – LED brightness ramps down, then returns to OFF.

Draw the diagram on paper or a whiteboard. Label each transition with the input that triggers it (e.g., button press, timer overflow). Keep the number of states low; PLAs handle a few dozen states comfortably.

## Step 2: Choose Your Flash Memory  

You need a flash cell that can be programmed in‑system (SPI flash works well). Make sure it supports the voltage levels of your PLA (usually 3.3 V). I like the 8 Mb SPI flash from Winbond because it’s cheap and has a simple command set, making it suitable for a [low‑power flash‑based state machine](/palflashlogic/stepbystep-guide-designing-a-lowpower-flashbased-state-machine-using-programmable-logic-arrays). The flash will store the truth table that the PLA reads each clock cycle.

## Step 3: Translate the State Table to a PLA Truth Table  

A PLA works with binary inputs and outputs. Create a table where each row represents a possible combination of current state bits and input bits, and each column shows the next state bits and output bits.

| Current State (2 bits) | Input (1 bit) | Next State (2 bits) | LED Output (1 bit) |
|-----------------------|---------------|---------------------|--------------------|
| 00 (OFF)              | 0             | 00 (OFF)            | 0                  |
| 00 (OFF)              | 1             | 01 (FADE_IN)        | 0                  |
| 01 (FADE_IN)          | 0             | 01 (FADE_IN)        | 1                  |
| 01 (FADE_IN)          | 1             | 10 (FADE_OUT)       | 1                  |
| 10 (FADE_OUT)         | 0             | 10 (FADE_OUT)       | 1                  |
| 10 (FADE_OUT)         | 1             | 00 (OFF)            | 0                  |

Notice we used two bits for the state because three states fit comfortably in a 2‑bit binary code. The PLA will implement the Boolean equations that generate the next‑state bits and the LED output from the current state and input.

## Step 4: Derive the Boolean Equations  

From the table, write the logic for each next‑state bit (NS1, NS0) and the output (LED). Use a Karnaugh map or a simple truth‑table reduction. For this example the equations turn out to be:

- **NS1 = (S0 AND I) OR (S1 AND NOT I)**
- **NS0 = (NOT S1 AND NOT S0 AND I) OR (S1 AND NOT I)**
- **LED = S1 OR S0**

Here, `S1` and `S0` are the current state bits, and `I` is the button input. “NOT” means logical inversion, “AND” means both conditions true, “OR” means either condition true.

## Step 5: Program the PLA  

Most PLAs have a simple programming interface: you supply a list of product terms for the AND plane and a list of sums for the OR plane. Use the flash memory to store these lists. The steps are:

1. **Create a binary file** that encodes the product‑term matrix. Each row corresponds to a minterm (a specific combination of inputs) and each column to an output line.  
2. **Load the file** into the flash using a SPI programmer. Many hobbyist programmers (like the CH341A) work fine.  
3. **Verify** the flash contents by reading them back and comparing to the original file.

If you prefer a graphical tool, the open‑source “pla‑designer” utility lets you draw the logic and export the binary file directly, and you can learn more about [low‑power PLA design](/palflashlogic/designing-a-low-power-pla-for-battery-operated-projects) in our dedicated guide.

## Step 6: Wire Up the Circuit  

Here’s a quick parts list:

- 1 × 8 Mb SPI flash (3.3 V)  
- 1 × PLA chip (e.g., Lattice ispMACH)  
- 1 × push‑button (debounced with a 10 kΩ resistor)  
- 1 × LED strip with a MOSFET driver  
- Power supply (3.3 V regulator)  
- Breadboard and jumper wires  

Connect the flash’s SPI pins (MOSI, MISO, SCK, CS) to the PLA’s configuration pins. Tie the button to a PLA input pin, and route the LED output pin through the MOSFET to the strip. Don’t forget a pull‑up resistor on the button line so the PLA sees a clean high when the button is not pressed.

## Step 7: Test and Debug  

Power the board and press the button. You should see the LED strip fade in, then fade out, then turn off. If nothing happens:

- **Check the flash** – is it correctly programmed? Re‑read the data.  
- **Verify the wiring** – a loose wire on the button can cause a stuck input.  
- **Look at the PLA pins** – some PLAs require a reset pulse after power‑up.

A handy trick I use is to add a “debug LED” that lights whenever the PLA’s internal state bits are both high. That gives you a visual cue that the state machine is actually moving.

## Step 8: Refine and Expand  

Now that the basic machine works, you can add more states (e.g., a “blink” mode) or more inputs (like a temperature sensor). Just update the state table, regenerate the Boolean equations, and re‑program the flash. For another flash‑based project, see our guide on [building a flash‑based bootloader](/palflashlogic/stepbystep-guide-to-building-a-flashbased-bootloader-for-arm-cortexm-microcontrollers) for ARM Cortex‑M microcontrollers. Because the flash is non‑volatile, the new logic stays in place even if you unplug the board.

## A Little Personal Note  

When I first tried to build a flash‑based controller for a solar‑tracker, I spent an entire weekend soldering the wrong pins on the PLA. The result was a faint smell of burnt plastic and a very patient lab partner. After swapping the chip, the tracker followed the sun like a loyal dog. That mishap taught me two things: always double‑check pinouts, and never underestimate the joy of seeing a circuit finally behave as you imagined.

Building a flash‑based state machine with a PLA is a rewarding blend of digital logic and hands‑on hardware. It gives you the speed of hardware with the flexibility of software updates, all while keeping the design simple enough for a weekend project. Grab a PLA, a flash chip, and start mapping out those states – your next smart gadget is just a few logic equations away.