|
| 1 | +-- PROJECT TOP. |
| 2 | +-- Counts the number of rising edges on pin 1 of the PMOD connector. |
| 3 | +-- With each rising edge, it turns on the next onboard LED in sequence, |
| 4 | +-- continuously cycling from D1 to D4. |
| 5 | + |
| 6 | +library ieee; |
| 7 | +use ieee.std_logic_1164.all; |
| 8 | +use ieee.numeric_std.all; |
| 9 | + |
| 10 | +entity LedCounter is |
| 11 | + -- Inputs/Outputs for the top module. |
| 12 | + port ( |
| 13 | + io_pmod_1 : in std_logic; -- Clock signal from PMOD pin 1 |
| 14 | + o_led_1 : out std_logic; -- Output to onboard LED 1 |
| 15 | + o_led_2 : out std_logic; -- Output to onboard LED 2 |
| 16 | + o_led_3 : out std_logic; -- Output to onboard LED 3 |
| 17 | + o_led_4 : out std_logic); -- Output to onboard LED 4 |
| 18 | +end entity; |
| 19 | + |
| 20 | +architecture RTL of LedCounter is |
| 21 | + |
| 22 | + -- Count up to 4 (the number of onboard LEDs). |
| 23 | + constant COUNT_LIMIT : natural := 4; |
| 24 | + |
| 25 | + -- Wires connecting the two modules RisingEdgeCounter and LedDriver. |
| 26 | + signal w_sel0 : std_logic; |
| 27 | + signal w_sel1 : std_logic; |
| 28 | + signal w_sel2 : std_logic; |
| 29 | + signal w_sel3 : std_logic; |
| 30 | + |
| 31 | +begin |
| 32 | + -- Module tracking the number of rising edges on pmod_1 in a local |
| 33 | + -- register, and activating the corresponding output signals. |
| 34 | + RisingEdgeCounterInstance: entity work.RisingEdgeCounter |
| 35 | + generic map (COUNT_LIMIT => COUNT_LIMIT) |
| 36 | + port map ( |
| 37 | + i_clk => io_pmod_1, |
| 38 | + o_sel0 => w_sel0, |
| 39 | + o_sel1 => w_sel1, |
| 40 | + o_sel2 => w_sel2, |
| 41 | + o_sel3 => w_sel3); |
| 42 | + |
| 43 | + -- Module activating the correct LED based on the control signals. |
| 44 | + -- A module is overkill here, but I wanted to experiment with wires. |
| 45 | + LedDriverInstance: entity work.LedDriver |
| 46 | + port map ( |
| 47 | + i_sel0 => w_sel0, |
| 48 | + i_sel1 => w_sel1, |
| 49 | + i_sel2 => w_sel2, |
| 50 | + i_sel3 => w_sel3, |
| 51 | + o_data0 => o_led_1, |
| 52 | + o_data1 => o_led_2, |
| 53 | + o_data2 => o_led_3, |
| 54 | + o_data3 => o_led_4); |
| 55 | + |
| 56 | +end architecture; |
0 commit comments