Beng Hons Electrical & Electronic Engineering
Beng Hons Electrical & Electronic Engineering
This report will demonstrate the steps that were required to program the DE0-Nano board
from Intel, the required design was to implement a crossing control using sequential logic, the
crossing control consist of a switch that represent the train signal with a rest button, the whole
system consist of the pedestrian cross (Red and Green LEDs), a flashing Red and a green
LED for the train with a Green and Red LEDs for the traffic.
Testbench and sublimation for the code and block diagrams are included in the report and
discussed.
The code was approached using modular approach apart from the Length statement.
The assignment was done individually, there is no task splitting, all done by the one student.
Figure one shows the inputs that has being used in the code which are, the clk (clock to run
the code cycle), rstn (active low push button that rests the cycle) and a start_sequance (push
button that signal the train and starts the sequence).
Figure 2: finite-state machine
The sequential circuit above shows the mechanism whose output (LEDs) behaviour
depending on the of the systems and the dataflow.
The code with the comments and headers (Appendix 1 , has the code for copy and paste
purpose).
1) Library declaration,
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity crossing_control5 is
generic(
);
port(
train_line_clear_n: in std_logic; -- Tells that train is gone and line is cleared -- active low
-- 0 bit -> flashing red light
led_traffic: out std_logic_vector(1 downto 0); -- Amber and flashing red light for traffic
led_train: out std_logic_vector(1 downto 0); -- Red and Green led for the trains
led_pedestrian: out std_logic_vector(1 downto 0) -- Red and green leds for the pedestrians
);
end crossing_control5;
3) The architecture,
begin
------ Debouncing for the start sequence button
process(clk,rstn,start_sequence,train_line_clear_n) begin
if(rstn = '0') then
debounce_count <= (others => '0');
start_seq_reg1 <= '0';
start_seq_reg2 <= '0';
train_line_clear_n_reg <= '0';
elsif rising_edge(clk) then
if(debounce_count = to_unsigned(debounce_delay, debounce_count'length)) then -- push the
button for atleast 1ms
start_seq_reg1 <= start_sequence;
train_line_clear_n_reg <= train_line_clear_n;
debounce_count <= (others => '0');
else
start_seq_reg1 <= start_seq_reg1;
train_line_clear_n_reg <= train_line_clear_n_reg;
debounce_count <= debounce_count + 1;
end if;
start_seq_reg2 <= start_seq_reg1;
end if;
end process;
-- one clock cycle flag for the start sequency button
start_seq_flag <= start_seq_reg1 AND (NOT start_seq_reg2);
end arch_crossing_control;
The Testbench code:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity testbench is
end testbench;
begin
-- Design under test
dut: entity work.crossing_control
-- for simulation run them fast
generic map(
debounce_delay => 0,
flashing_delay => 1
)
port map(
clk => clk,
rstn => rstn,
start_sequence => start_sequence,
train_line_clear_n => train_line_clear_n,
led_traffic => led_traffic,
led_train => led_train,
led_pedestrian => led_pedestrian
);
-- CLock Generator
clk <= not clk after (clk_period/2) when sim_finish /= '1' else '0';
-- Testing
process begin
-- Initialize the values
rstn <= '1';
start_sequence <= '0';
train_line_clear_n <= '0';
-- Apply reset
wait for 100 ns;
rstn <= '0';
wait for 100 ns;
rstn <= '1';
wait for 100 ns;
-- Apply simulation
start_sequence <= '1';
wait for 200 ns;
-- Train is here
train_line_clear_n <= '1';
wait for 200 ns;
-- Train passed
train_line_clear_n <= '0';
start_sequence <= '0';
The Testbench clearly shows the outputs of the code, rest is active hight meanwhile the
start_sequance and clearnow are active low which makes the outputs (LEDs)