Category Archives: GAL 16v8

All you ever wonder of GAL 16v8

GAL16V8 :3- 4 bit counter using macrocell

We will construct a 4 bit counter using the GAL16V8, but instead of constructing the latch like in the previous post, LATCHES, SR LATCH. we will use the builtin flip flop of the MACROCELL.

As a quick reference, a D type flip flop is a device that can store one value, like the SR LATCH, however the value will only be stored on the rising edge of the clock. In reality it does the change using both the rising and falling edge of the clock. You can have a deeper insight of its works with this video from Ben Eater. https://www.youtube.com/watch?v=rXHSB5w7CyE

When configuring a macrocell you need to describe the equations which based in the current state, will change the next state.

When configuring the D-Latch you need to think on how the next state will be reached based on the current state. We can think of it as current state, Q and next state QNext.

In a 1 bit binary counter, when Q is 0, the next state is 1. and when Q is 1, we overflow and the next state is 0. Making it effectively that QNext is !Q, such equation would look like this.

``QNext = !Q;``

Lets see what would be the truth table for this 1 bit counter.

 Q Q Next 0 1 1 0

Now, the second less significant bit, Q2, will have its next state based on two values, the value of Q and the value of Q2. For the rest of the examples we will call Q as Q1.

The first condition of Q2 is that it will change every time Q1 transitions from 1 to 0, or effectively, every time !Q1.

We can see that in the following truth table.

 Q2 Q1 Q2Next Q1Next 0 0 0 1 0 1 1 0 1 0 1 1 1 1 0 0

`Q2Next = (Q2 and !Q1) or (!Q2 and Q1)`

In colloquial language this could be expressed as the following quote.

If Q1 is true, Q2Next will be complement of Q2, if Q1 is false, Q2 don’t change.

Now, the way to write this code in CUPL, to be able to progaram with our gal will be very similar, however CUPL does not have a QNext, instead it have a Q.d where d stands for DLatch. So our equation in CUPL will be like this for Q1 and Q2.

``````Q2.d = (!Q1 & Q0) # (Q1 & !Q0);
Q1.d = !Q0;``` ```

We can follow the same analysis for the other 2 bits. If we decide to do so we could get a CUPL code similar to this one. This code also includes a clr input, to reset the counter to 0 at any time.

``````Name  CCCCCC;
Partno XXXXXX;
Date XX/XX/XX;
Revision XX;
Designer XXXXXX;
Company XXXXXX;
Assembly XXXXXX;
Location XXXXXX;
Device g16v8ms
PIN 1 = clk;
PIN 2 = clr;
PIN 15 = Q0;
PIN 14 = Q1;
PIN 13 = Q2;
PIN 12 = Q3;
Q3.d = !clr & ((!Q3 & Q2 & Q1 & Q0) # (Q3 & !(Q2 & Q1 & Q0)));
Q2.d = !clr & ((!Q2 & Q1 & Q0) # (Q2 & !(Q1 & Q0)));
Q1.d = !clr & (!Q1 & Q0 # Q1 & !Q0);
Q0.d = !clr & !Q0;``````

This would be the wiring diagram.

The clock is being generated by an arduino, but it could be generated by any means, including a 555 timer as long as is a square wave between 0 and 5 volts. (for this circuit that is being powered by 5V).

Also here we can see the the circuit assembled in action, I added a small yellow led to see the state of the clock.

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.

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.

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.

 `Name SRLATCH; 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.

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

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.

https://www.ebay.com/itm/10PCS-IC-LATTICE-DIP-20-GAL16V8D-15LP/162777611072?hash=item25e64d3b40:g:uTUAAOSwy~BaHNPZ

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

https://www.microchip.com/design-centers/programmable-logic/spld-cpld/tools/software/wincupl

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

 Input Output Output_Inverse 0 0 1 1 1 0

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.

NOTES:

• 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 http://ee-classes.usc.edu/ee459/library/documents/CUPL_Reference.pdf

GAL16V8 DataSheet http://ee-classes.usc.edu/ee459/library/datasheets/16v8.pdf

The cheap gal programmer I bought, I have tried with GAL 16V8 from Lattice and works fine so far. https://www.amazon.com/Genius-Universal-Programmer-EPROM-FLASH/dp/B075TGDDJM

Where to download winCUPL “for windows” with bugs, but is free. https://www.microchip.com/design-centers/programmable-logic/spld-cpld/tools/software/wincupl