CPLD intro 2: Toggle a LED with a button

From DP

Jump to: navigation , search



In tutorial 2 we extend the first CPLD design by controlling the LED with a push button.

  • Press the button to turn off the LED
  • Release the button to turn on the LED
Tutorial 2 truth table
Button PB LED D1
Pressed OFF
NOT pressed ON



The development boards have a simple push button (PB) connected to pin P18 of the CPLD.

PB truth table
Button P18
Pressed LOW (0)
NOT pressed HIGH (1)

A pull-up resistor (R1) holds P18 high when the button is NOT pressed. When pressed, the button connects P18 to ground and produces a low/0 state. See the truth table above.

The XC2C64A CPLD has internal pullup resistors
R1 is unpopulated on the XC2C64A development board

In this demo we'll use the input on pin P18 to control the LED D1 connected to pin P39. Due to the inverse logic of the button, the LED will turn off when the button is pressed.



The XC9572XL schematic is a simple variant on tutorial 1. Instead of connecting the LED directly to the power supply, we connect it to the input from the button.

  • BUTTON is an input marker. This is where the push button input will enter the CPLD. We assign this to a specific pin number in the UCF file below
  • IBUF is an input buffer that connects the external BUTTON signal to logic inside the CPLD. All external signals must enter the CPLD through an input buffer
  • The input buffer is connected directly to an output buffer (OBUF). Output buffers connect internal CPLD signals to an external pin. All inputs and outputs from the CPLD must be attached to a buffer element
  • LED is an output marker. This is where the CPLD will output to the LED. We assign this to a specific pin in the UCF file



The XC2C64A schematic is slightly different than the XC9572XL version. The CoolRunner-II family (XC2C) is newer and has some advanced features like configurable pull-up resistors.

  • Like the XC9572XL schematic, but internal pull-up resistor added to the BUTTON signal before the input buffer (IBUF)


The XC2C64A development board takes advantage of the CoolRunner-II internal resistors and omits external resistor R1. This doesn't save a lot of money, but it provides a nice contrast between the devices.

TIP: To enable the in internal pull-up resistors in a new project go to fit and change default pin type to float or pull-up. Keeper and pull-ups are mutually exclusive in a single design.


NET "LED"            LOC =  "P39";
NET "BUTTON"        LOC =  "P18";

Input and output markers in the schematic are mapped to actual CPLD pin numbers in the UCF file. This is an example UCF file that defines the three IO connections on the development boards.

  • The Pxx numbers are the actual pin number on the CPLD. Easy.
  • ISE has a GUI utility to assign pin numbers, but it doesn't work with CoolRunner-II CPLDs.

We mapped the BUTTON input market to pin 18 and the LED output marker to pin 39.