All posts by estebon

GAL16V8 :2- Latches, SR Latch

Today we will explore the basic of SR Latch and how to build one with a GAL16V8.

The wikipedia definition of a latch is ” a circuit that has two stable states and can be used to store state information“.

The latch we want to implement today is the SR LATCH with two nor gates. the circuit is as follows.

Image result for sr latch

This latch have two inputs, Set (S) and Reset (r), and two exits, Q, which is the stored state, and !Q, which is the inverse of the stored state. Easy.

The truth table of this circuit is as follows.

Truth table of SD Latch

As we can see, as long as only one of either Set or Reset is on, the Q output will store the value of Set.

Note that when Set and Reset are off, Q and !Q keep their values, that is where the storage property comes in.
Also in this specific latch made out of NOR gates, when both Set and Reset are ON both Q and !Q are disabled, thus both are 0, this is an unstable state and the end value of Q and !Q when both Set and Reset are OFF again will be a race condition on which one is set last.

Now How will this looks in CUPL code? Well, we only need to define the following two equations.

Q = !(R # QN);
QN = !(S # Q);

As you can see, we are only describing the inputs of the NOR gates here, in the CUPL file it will look similar to this.

partNo 00;
Date 16/06/2016;
Revision 01;
Designer Esteban;
Company estebon;
Assembly None;
Location None;
Device g16v8ms;

PIN 2 = R;
PIN 3 = S;

PIN 12 = Q;
PIN 13 = QN;

Q = !(R # QN);
QN = !(S # Q);

Now we burn our gal and wire as follows. See the Make it blink tutorial on how to program our gal.

Wiring of SR Latch

And finally we can test it, Notice how the output led match the button pressed.

SR Latch with GAL16V8

That is all on this, hope you find it useful.

GAL16v8 :1- Jumpstarting, I want my gal to do something now!

Well, you can’t hahahah. just kidding.

This is a quick guide and I am assuming you can understand some basic boolean logic.

First you need 3 things:

1- A GAL16V8 of course. From EBAY? Sure.

2- A GAL programmer, from our chinese friends. This is the one I bought and seems to work fine so far and is kind of cheap.

3- winCUPL, you can get it from here

Fine, you installed all and got all the items. so what are we going to create? Well in this example we will create a pass thru and an inverter. basically a circuit like the following.

This is a circuit that have one Input, in leg 2 and two outputs, which is passthru in leg 12 and the negation operation in leg 13.

those follow the next boolean table


We are going to program this configuration with CUPL language using WinCUPL as follows.

Now Lets compile it using the Device Dependent Compile button, which will use the device specified in the Device tag, in this case g16v8 to create a jed file.

Success, now we will use the software that should have been included with your G540 Programmer as follows.

The next window will open and as long as it looks like this it should be good. just click ok.

Next step is to select your device, which if you bought the lattice gal GAL16V8D should be like this. First click the Select button and look for the device.

Finally, the programming window appear, place your gal in the programmer, (check that your programmer is conected to the pc) . Ensure the notch is in the correct direction and that the gal is placed at the base like this.

Then click Prog button and hopefully it will work.

Now Prepare a breadboard like this.

And test :3

the schematic is like this.


  • Resistor is 220 ohms
  • voltage is 5v, from an arduino :), bt any 5v source will do.
  • I didn’t put resistors in my LEDs but they may be needed ?

So this is the basic guide, I skip how to install the software, but hope it helps you to jumpstart into gals, I will explain more in detail in future post about this old and forgotten world of PLA (Programable logic Arrays) which GAL is part of :).

GAL 16V8 References :)

Have you decided you want to learn to code in gal but don’t know where to start. Well welcome, this page won’t explain a thing but here are nice links you can follow in your quest.

Good CUPL Language reference Guide

GAL16V8 DataSheet

The cheap gal programmer I bought, I have tried with GAL 16V8 from Lattice and works fine so far.

Where to download winCUPL “for windows” with bugs, but is free.