CPLD VHDL intro 3: Inverse LED toggle
From DP
Contents |
Overview
In tutorial 3 we build on the simple push button example in tutorial 2. We'll add logic that inverts the output of button 1 on LED D2.
Button PB | LED D1 | LED D2 |
---|---|---|
Pressed | OFF | ON |
NOT pressed | ON | OFF |
Schematic
In this demo we'll use both LEDs and the push button connected to the CPLD.
IO | pin connection |
---|---|
LED D1 | P39 |
LED D2 | P38 |
Button BP | P18 |
The XC2C64A CPLD has internal pullup resistors R1 is unpopulated on the XC2C64A development board
VHDL
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity light_LED_PB is Port (BUTTON: in STD_LOGIC:='1'; LED : out STD_LOGIC:='0'; LED_INV: out STD_LOGIC:='0'); end light_LED_PB; architecture Behavioral of light_LED_PB is begin LED <= BUTTON; LED_INV <= not (BUTTON); end Behavioral;
LED_INV is set to be the opposite (not) of BUTTON.
UCF
XC9572 UCF
#PIN MAP OF DANGEROUSPROTOTYPES.COM CPLD BREAKOUT BOARDS #lICENSE: CC-0 (CREATIVE COMMONS 0) #http://dangerousprototypes.com/docs/XC9500XL_CPLD_breakout_board #http://dangerousprototypes.com/docs/CoolRunner-II_CPLD_breakout_board NET "LED" LOC = "P39"; NET "BUTTON" LOC = "P18"; NET "LED_INV" LOC = "P38";
Input and outputs from the module 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.
We mapped the BUTTON input market to pin 18. The LED output marker connects to pin 39 (D1), and LED_INV connects to pin 38 (D2).
XC2C64A
#PIN MAP OF DANGEROUSPROTOTYPES.COM CPLD BREAKOUT BOARDS #lICENSE: CC-0 (CREATIVE COMMONS 0) #http://dangerousprototypes.com/docs/XC9500XL_CPLD_breakout_board #http://dangerousprototypes.com/docs/CoolRunner-II_CPLD_breakout_board NET "LED" LOC = "P39"; NET "LED_INV" LOC = "P38"; NET "BUTTON" LOC = "P18"; NET "BUTTON" PULLUP;
The XC2C64A version is the same, except we use the internal pull-up resistor instead of R1 on the development board.