I have recently started using programmable logic devices (PLDs) in some of my projects. Below are the steps I am using, along with some challenges that I have encountered. As I learn more about PLDs, I will update this post.
My first use of PLDs was for address decode logic to CS/OE lines on my 65816 build. Most recently, I have configured a pair of PLDs for a video card that I am building. In both of these cases, I am using a Lattice GAL22V10D-15LP or -10LP PLD. I have attempted to use the -7LP PLDs, but my programmer fails to work with them (more on that later).
Video Card PLDs
While I will walk through using a PLD for my video card, these same general steps are used for my 65816 address decode logic.
As I looked into programming my PLDs, I found very few options to program them. The primary recommendation I found was to use WinCupl, a rather dated application. CUPL (Compiler for Universal Programmable Logic) is used in WinCupl to develop the logic for the PLD. The CUPL is compiled into a JEDEC file. This JEDEC file must then be written to the PLD. To get me moving along faster, I wanted to use a more graphical option than CUPL to create my logic. For this, I am using Digital, a logic designer and circuit simulator.
For me, the basic process to get a functioning PLD is:
Develop the logic in Digital
From Digital, generate the CUPL
Load the CUPL into WinCupl
From WinCupl, compile the CUPL into a JEDEC file
From Xgpro, load the JEDEC file and write it to the GAL22V10D PLD
Update: Digital has the ability to directly create a JEDEC file. Make sure to assign pin numbers to all inputs and outputs in Digital. Then choose Analysis, Create, GAL..., JEDEC. You can then skip steps 3 and 4 above!
For my video card, I wanted one PLD for generating horizontal timing and one PLD for generating vertical timing. See VGA Card for 65816 PC - Step 1: Basic Circuit. With this in mind, I created the following logic in Digital for the horizontal timing.
![](https://static.wixstatic.com/media/66a162_bd13280016c347648afba628234e432d~mv2.png/v1/fill/w_49,h_33,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/66a162_bd13280016c347648afba628234e432d~mv2.png)
To create the CUPL in Digital, the logic must be analyzed. The CUPL can then be saved.
![](https://static.wixstatic.com/media/66a162_ea8d19fa4cf949728d8667f0c6fca458~mv2.png/v1/fill/w_49,h_41,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/66a162_ea8d19fa4cf949728d8667f0c6fca458~mv2.png)
For the initial logic I posted earlier, this is where I ran into a problem. Digital cannot analyze circuits with loops -- in this case, the SR latches on the right. I worked around it by modifying the circuit as follows. This requires two pins on the PLD to be connected together -- a bit wasteful. (Is there a better way to do this?)
![](https://static.wixstatic.com/media/66a162_95192cbb062541afbd5dab4602e683bc~mv2.png/v1/fill/w_49,h_41,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/66a162_95192cbb062541afbd5dab4602e683bc~mv2.png)
The generated CUPL looks something like this:
![](https://static.wixstatic.com/media/66a162_b1ca1cd6010f43a6959a744fd4474ab9~mv2.png/v1/fill/w_49,h_38,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/66a162_b1ca1cd6010f43a6959a744fd4474ab9~mv2.png)
This CUPL can then be loaded into WinCupl. Unfortunately, this is where I encountered another issue. Directly opening the above CUPL in WinCupl causes it to crash -- no errors, the application just disappears. I worked around this by creating a new, blank file in WinCupl and pasting in the CUPL section by section.
Update: u/tmrob4 suggested moving the CUPL files to the WinCupl installation folder. This seems to be helping nicely!
I select the device and save the file. There was no option for my specific GAL22V10D, so I chose something that appeared to be the closest.
![](https://static.wixstatic.com/media/66a162_2b1f9e42aeb14a8aac6eea705595dc85~mv2.png/v1/fill/w_49,h_43,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/66a162_2b1f9e42aeb14a8aac6eea705595dc85~mv2.png)
![](https://static.wixstatic.com/media/66a162_6d3fe50542c240dbab8102b1bde18ca2~mv2.png/v1/fill/w_92,h_56,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/66a162_6d3fe50542c240dbab8102b1bde18ca2~mv2.png)
Then I run Device Dependent Compile. If I'm lucky, it will compile. More often than not, I get an error "Key is not unique in collection" and WinCupl crashes (which seems to be a common pattern with this software). I have not been able to pin down the root cause of this error yet. Whether or not it truly helps, I'm not sure, but if I restart Windows and try it again, I have better odds of getting WinCupl to generate the JEDEC file.
Update: u/tmrob4 suggested deselecting "Project" in the View menu. While I already had that deselected, if you're encountering this issue, it might be worth checking.
Assuming a JEDEC does get generated, it can then be programmed to the PLD device. I am using a TL866II-Plus with the manufacturer-provided software, Xgpro.
![](https://static.wixstatic.com/media/66a162_8aea9556ee88468ca423daf0a1ccdc2c~mv2.png/v1/fill/w_49,h_36,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/66a162_8aea9556ee88468ca423daf0a1ccdc2c~mv2.png)
Repeat the above steps for the vertical sync PLD.
I have had no issues programming GAL22V10D-15LP and GAL22V10D-10LP PLDs with my programmer. Unfortunately, I have not been able to get -7LP PLDs to program; I get errors on pin 2 (with different PLDs). I have reached out to the manufacturer of the programmer but have received no response; I can't imagine supporting end-of-life PLDs is high on their priority list (if it's even a programmer issue).
VHDL?
I notice in WinCupl there is an option to open VHDL. I have yet to determine if this is simply a text editor for VHDL or if the program is supposed to support converting VHDL to CUPL. With a little searching, I found some references to an add-in being required. Digital can export VHDL, but WinCupl crashes when I try to load VHDL -- and it deletes the source VHDL file in the process!
Converting Truth Tables to CUPL
Another nice feature of Digital that I used for my 65816 logic was to pull in a truth table from Excel. Digital can then generate the logic based on the truth table, along with the CUPL based on the truth table.
![](https://static.wixstatic.com/media/66a162_782d059745954deab2dadeb0be1b534c~mv2.png/v1/fill/w_49,h_22,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/66a162_782d059745954deab2dadeb0be1b534c~mv2.png)