aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Woods2023-02-27 12:37:16 -0500
committerBrian Woods2023-02-27 12:47:00 -0500
commit0b4c108c32e57d5b37ff58b8ecdd68b13f8ce510 (patch)
tree4df0613d9c3743abd6c0e251745fcb8413e0fa90
parent84a6b2e55134ef392aa068c38f1981ead54e7a4b (diff)
averaging_filer: Add Octave simulation top fileaveraging_filter
Add a top simulation file and add comments in the makefile for it. This allows an input file from Octave and output a file to generate a graph.
-rw-r--r--averaging_filter/Makefile3
-rw-r--r--averaging_filter/simulation_octave.vhd106
2 files changed, 108 insertions, 1 deletions
diff --git a/averaging_filter/Makefile b/averaging_filter/Makefile
index 69a09ca..d29a152 100644
--- a/averaging_filter/Makefile
+++ b/averaging_filter/Makefile
@@ -4,6 +4,7 @@
# this is for ghdl-gcc, I've not tested it on ghdl-llvm but it will not
# work with ghdl-mcode
+# use simulation_octave.vhd for file I/O
SRC=simulation.vhd top.vhd averaging_filter.vhd
OBJ=$(SRC:.vhd=.o)
TOP=simulation
@@ -12,7 +13,7 @@ WAVE_DUMP=$(TOP).ghw
WAVE_CONF=$(TOP).gtkw
WORKLIB=work
FLAGS=--std=08 --work=$(WORKLIB)
-TIME=1us
+TIME=12us
.PHONY: all clean sim
diff --git a/averaging_filter/simulation_octave.vhd b/averaging_filter/simulation_octave.vhd
new file mode 100644
index 0000000..65d59cc
--- /dev/null
+++ b/averaging_filter/simulation_octave.vhd
@@ -0,0 +1,106 @@
+-- SPDX-FileCopyrightText: 2023 Brian Woods
+-- SPDX-License-Identifier: GPL-2.0-or-later
+
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.numeric_std.all;
+use std.textio.all;
+
+entity simulation is
+end;
+
+architecture sim of simulation is
+ component top is
+ port(
+ input: in signed(17 downto 0);
+ output: out signed(17 downto 0);
+ en: in std_logic;
+ dr: out std_logic;
+ clr: in std_logic;
+ clk: in std_logic
+ );
+ end component;
+
+ signal input: signed(17 downto 0) := (others => '0');
+ signal output: signed(17 downto 0);
+ signal en: std_logic := '0';
+ signal dr: std_logic := '0';
+ signal clr: std_logic := '1';
+ signal clk: std_logic := '0';
+ signal int_input: integer := 0;
+ signal int_output: integer;
+
+begin
+ dut: top port map(
+ input => input,
+ output => output,
+ en => en,
+ dr => dr,
+ clr => clr,
+ clk => clk
+ );
+
+ clk <= not clk after 5 ns;
+
+ int_output <= to_integer(output);
+ --int_output <= 42;
+ input <= to_signed(int_input, input'length);
+
+ input_proc: process
+ file read_file: text open read_mode is "sim_input.txt";
+ variable read_line: line;
+ variable read_input: integer;
+ begin
+ -- at 0 ns
+ int_input <= 0;
+ en <= '0';
+ clr <= '1';
+ wait for 10 ns;
+
+ -- at 10 ns
+ int_input <= 0;
+ en <= '0';
+ clr <= '1';
+ wait for 10 ns;
+
+ -- at 20 ns
+ int_input <= 0;
+ en <= '0';
+ clr <= '0';
+ wait for 10 ns;
+
+ while not endfile(read_file) loop
+ readline(read_file, read_line);
+ read(read_line, read_input);
+
+ int_input <= read_input;
+ en <= '1';
+ clr <= '0';
+ wait for 10 ns;
+ end loop;
+
+ --wait for anything to happen
+ int_input <= 0;
+ en <= '0';
+ clr <= '0';
+ wait for 100 ns;
+
+ -- end sim
+ wait;
+ end process;
+
+ -- for writing output to a file
+ output_proc: process(clk, dr)
+ file write_file: text open write_mode is "sim_output.txt";
+ variable write_line: line;
+ variable write_output: integer;
+ begin
+ if (clk='1' and clk'event) then
+ if (dr='1') then
+ write_output := int_output;
+ write(write_line, write_output);
+ writeline(write_file, write_line);
+ end if;
+ end if;
+ end process;
+end sim;