diff --git a/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar.vhd b/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v0.vhd similarity index 94% rename from LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar.vhd rename to LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v0.vhd index 6382814..0c92830 100644 --- a/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar.vhd +++ b/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v0.vhd @@ -1,3 +1,7 @@ +-- File: KittCar_v0.vhd +-- Description: This file implements the KittCar entity +-- Known problem: The counter is not working properly + ---------- DEFAULT LIBRARY --------- LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; diff --git a/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v1.1.vhd b/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v1.1.vhd new file mode 100644 index 0000000..16117b5 --- /dev/null +++ b/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v1.1.vhd @@ -0,0 +1,95 @@ +-- File: KittCar_v1.vhd +-- Description: Better asyncronous logic handling & unsigned n_period +-- Known problem: Not yet tested + +---------- DEFAULT LIBRARY --------- +LIBRARY IEEE; +USE IEEE.STD_LOGIC_1164.ALL; +USE IEEE.NUMERIC_STD.ALL; +------------------------------------ + +ENTITY KittCar IS + GENERIC ( + + CLK_PERIOD_NS : POSITIVE RANGE 1 TO 100 := 10; -- clk period in nanoseconds + MIN_KITT_CAR_STEP_MS : POSITIVE RANGE 1 TO 2000 := 1; -- Minimum step period in milliseconds (i.e., value in milliseconds of Delta_t) + + NUM_OF_SWS : INTEGER RANGE 1 TO 16 := 16; -- Number of input switches + NUM_OF_LEDS : INTEGER RANGE 1 TO 16 := 16 -- Number of output LEDs + + ); + PORT ( + + ------- Reset/Clock -------- + reset : IN STD_LOGIC; + clk : IN STD_LOGIC; + ---------------------------- + + -------- LEDs/SWs ---------- + sw : IN STD_LOGIC_VECTOR(NUM_OF_SWS - 1 DOWNTO 0); -- Switches avaiable on Basys3 + led : OUT STD_LOGIC_VECTOR(NUM_OF_LEDS - 1 DOWNTO 0) -- LEDs avaiable on Basys3 + ---------------------------- + + ); +END KittCar; + +ARCHITECTURE Behavioral OF KittCar IS + CONSTANT MIN_KITT_CAR_STEP_NS : UNSIGNED(63 DOWNTO 0) := to_unsigned(MIN_KITT_CAR_STEP_MS * 1000000, 64); -- 64bits is more than needed, just for test purposes (47 bits are enough) + + SIGNAL leds_sr : STD_LOGIC_VECTOR(led'RANGE) := (OTHERS => '0'); + SIGNAL n_period : UNSIGNED(sw'RANGE) := 1; + SIGNAL up : STD_LOGIC := '1'; +BEGIN + + -- Sincronous logic + PROCESS (clk, reset) + VARIABLE counter : UNSIGNED(63 DOWNTO 0) := (OTHERS => '0'); -- 64bits is more than needed, just for test purposes (47 bits are enough) + BEGIN + IF reset = '1' THEN + leds_sr <= (OTHERS => '0'); + counter := (OTHERS => '0'); + ELSIF rising_edge(clk) THEN + + -- Reset the leds + IF unsigned(leds_sr) = 0 THEN + leds_sr(0) <= '1'; + END IF; + + -- Increment the counter + counter := counter + to_unsigned(CLK_PERIOD_NS, counter'LENGTH); + + -- Calculate the number of periods + IF counter >= (MIN_KITT_CAR_STEP_NS * n_period) THEN + + -- Shift the leds + IF up = '1' THEN + leds_sr <= leds_sr(NUM_OF_LEDS - 2 DOWNTO 0) & '0'; + ELSIF up = '0' THEN + leds_sr <= '0' & leds_sr(NUM_OF_LEDS - 1 DOWNTO 1); + END IF; + + -- Reset the counter + counter := (OTHERS => '0'); + END IF; + END IF; + END PROCESS; + + -- Kitt logic + PROCESS (leds_sr) + BEGIN + IF leds_sr(led'HIGH) = '1' THEN + up <= '0'; + ELSIF leds_sr(led'LOW) = '1' THEN + up <= '1'; + END IF; + END PROCESS; + + -- Handle the switch + PROCESS (sw) + BEGIN + n_period <= unsigned(sw) + 1; + END PROCESS; + + led <= leds_sr; + +END Behavioral; \ No newline at end of file diff --git a/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v1.vhd b/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v1.vhd new file mode 100644 index 0000000..995fc5c --- /dev/null +++ b/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v1.vhd @@ -0,0 +1,95 @@ +-- File: KittCar_v1.vhd +-- Description: Better asyncronous logic handling +-- Known problem: The counter is not working properly + +---------- DEFAULT LIBRARY --------- +LIBRARY IEEE; +USE IEEE.STD_LOGIC_1164.ALL; +USE IEEE.NUMERIC_STD.ALL; +------------------------------------ + +ENTITY KittCar IS + GENERIC ( + + CLK_PERIOD_NS : POSITIVE RANGE 1 TO 100 := 10; -- clk period in nanoseconds + MIN_KITT_CAR_STEP_MS : POSITIVE RANGE 1 TO 2000 := 1; -- Minimum step period in milliseconds (i.e., value in milliseconds of Delta_t) + + NUM_OF_SWS : INTEGER RANGE 1 TO 16 := 16; -- Number of input switches + NUM_OF_LEDS : INTEGER RANGE 1 TO 16 := 16 -- Number of output LEDs + + ); + PORT ( + + ------- Reset/Clock -------- + reset : IN STD_LOGIC; + clk : IN STD_LOGIC; + ---------------------------- + + -------- LEDs/SWs ---------- + sw : IN STD_LOGIC_VECTOR(NUM_OF_SWS - 1 DOWNTO 0); -- Switches avaiable on Basys3 + led : OUT STD_LOGIC_VECTOR(NUM_OF_LEDS - 1 DOWNTO 0) -- LEDs avaiable on Basys3 + ---------------------------- + + ); +END KittCar; + +ARCHITECTURE Behavioral OF KittCar IS + CONSTANT MIN_KITT_CAR_STEP_NS : UNSIGNED(63 DOWNTO 0) := to_unsigned(MIN_KITT_CAR_STEP_MS * 1000000, 64); + + SIGNAL leds_sr : STD_LOGIC_VECTOR(led'RANGE) := (OTHERS => '0'); + SIGNAL n_period : POSITIVE RANGE 1 TO (2 ** NUM_OF_SWS) := 1; + SIGNAL up : STD_LOGIC := '1'; +BEGIN + + -- Sincronous logic + PROCESS (clk, reset) + VARIABLE counter : UNSIGNED(63 DOWNTO 0) := (OTHERS => '0'); + BEGIN + IF reset = '1' THEN + leds_sr <= (OTHERS => '0'); + counter := (OTHERS => '0'); + ELSIF rising_edge(clk) THEN + + -- Reset the leds + IF unsigned(leds_sr) = 0 THEN + leds_sr(0) <= '1'; + END IF; + + -- Increment the counter + counter := counter + to_unsigned(CLK_PERIOD_NS, counter'LENGTH); + + -- Calculate the number of periods + IF counter >= (MIN_KITT_CAR_STEP_NS * n_period) THEN + + -- Shift the leds + IF up = '1' THEN + leds_sr <= leds_sr(NUM_OF_LEDS - 2 DOWNTO 0) & '0'; + ELSIF up = '0' THEN + leds_sr <= '0' & leds_sr(NUM_OF_LEDS - 1 DOWNTO 1); + END IF; + + -- Reset the counter + counter := (OTHERS => '0'); + END IF; + END IF; + END PROCESS; + + -- Kitt logic + PROCESS (leds_sr) + BEGIN + IF leds_sr(led'HIGH) = '1' THEN + up <= '0'; + ELSIF leds_sr(led'LOW) = '1' THEN + up <= '1'; + END IF; + END PROCESS; + + -- Handle the switch + PROCESS (sw) + BEGIN + n_period <= to_integer(unsigned(sw)) + 1; + END PROCESS; + + led <= leds_sr; + +END Behavioral; \ No newline at end of file diff --git a/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v2.1.vhd b/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v2.1.vhd new file mode 100644 index 0000000..482bb90 --- /dev/null +++ b/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v2.1.vhd @@ -0,0 +1,99 @@ +-- File: KittCar_v2.vhd +-- Description: Counter prescaler & unsigned n_period +-- Known problem: Not yet tested + +---------- DEFAULT LIBRARY --------- +LIBRARY IEEE; +USE IEEE.STD_LOGIC_1164.ALL; +USE IEEE.NUMERIC_STD.ALL; +------------------------------------ + +ENTITY KittCar IS + GENERIC ( + + CLK_PERIOD_NS : POSITIVE RANGE 1 TO 100 := 10; -- clk period in nanoseconds + MIN_KITT_CAR_STEP_MS : POSITIVE RANGE 1 TO 2000 := 1; -- Minimum step period in milliseconds (i.e., value in milliseconds of Delta_t) + + NUM_OF_SWS : INTEGER RANGE 1 TO 16 := 16; -- Number of input switches + NUM_OF_LEDS : INTEGER RANGE 1 TO 16 := 16 -- Number of output LEDs + + ); + PORT ( + + ------- Reset/Clock -------- + reset : IN STD_LOGIC; + clk : IN STD_LOGIC; + ---------------------------- + + -------- LEDs/SWs ---------- + sw : IN STD_LOGIC_VECTOR(NUM_OF_SWS - 1 DOWNTO 0); -- Switches avaiable on Basys3 + led : OUT STD_LOGIC_VECTOR(NUM_OF_LEDS - 1 DOWNTO 0) -- LEDs avaiable on Basys3 + ---------------------------- + + ); +END KittCar; + +ARCHITECTURE Behavioral OF KittCar IS + SIGNAL leds_sr : STD_LOGIC_VECTOR(led'RANGE) := (OTHERS => '0'); + SIGNAL n_period : UNSIGNED(sw'RANGE) := 1; + SIGNAL up : STD_LOGIC := '1'; +BEGIN + + -- Sincronous logic + PROCESS (clk, reset) + VARIABLE counter_ns : INTEGER := 0; + VARIABLE counter_ms : INTEGER := 0; + BEGIN + IF reset = '1' THEN + leds_sr <= (OTHERS => '0'); + counter_ns := 0; + counter_ms := 0; + ELSIF rising_edge(clk) THEN + + -- Reset the leds + IF unsigned(leds_sr) = 0 THEN + leds_sr(0) <= '1'; + END IF; + + -- Handle counters + counter_ns := counter_ns + CLK_PERIOD_NS; + IF counter_ns >= 1000000 THEN + counter_ms := counter_ms + 1; + counter_ns := 0; + END IF; + + -- Calculate the number of periods + IF counter_ms >= (MIN_KITT_CAR_STEP_MS * to_integer(n_period)) THEN + + -- Shift the leds + IF up = '1' THEN + leds_sr <= leds_sr(NUM_OF_LEDS - 2 DOWNTO 0) & '0'; + ELSIF up = '0' THEN + leds_sr <= '0' & leds_sr(NUM_OF_LEDS - 1 DOWNTO 1); + END IF; + + -- Reset the counter + counter_ms := 0; + END IF; + END IF; + END PROCESS; + + -- Kitt logic + PROCESS (leds_sr) + BEGIN + IF leds_sr(led'HIGH) = '1' THEN + up <= '0'; + ELSIF leds_sr(led'LOW) = '1' THEN + up <= '1'; + END IF; + END PROCESS; + + -- Handle the switch + PROCESS (sw) + BEGIN + n_period <= unsigned(sw) + 1; + END PROCESS; + + led <= leds_sr; + +END Behavioral; \ No newline at end of file diff --git a/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v2.vhd b/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v2.vhd new file mode 100644 index 0000000..7bd6c0b --- /dev/null +++ b/LAB1/lab1_kit_car/lab1_kit_car.srcs/sources_1/new/KittCar_v2.vhd @@ -0,0 +1,99 @@ +-- File: KittCar_v2.vhd +-- Description: Counter prescaler +-- Known problem: Not yet tested + +---------- DEFAULT LIBRARY --------- +LIBRARY IEEE; +USE IEEE.STD_LOGIC_1164.ALL; +USE IEEE.NUMERIC_STD.ALL; +------------------------------------ + +ENTITY KittCar IS + GENERIC ( + + CLK_PERIOD_NS : POSITIVE RANGE 1 TO 100 := 10; -- clk period in nanoseconds + MIN_KITT_CAR_STEP_MS : POSITIVE RANGE 1 TO 2000 := 1; -- Minimum step period in milliseconds (i.e., value in milliseconds of Delta_t) + + NUM_OF_SWS : INTEGER RANGE 1 TO 16 := 16; -- Number of input switches + NUM_OF_LEDS : INTEGER RANGE 1 TO 16 := 16 -- Number of output LEDs + + ); + PORT ( + + ------- Reset/Clock -------- + reset : IN STD_LOGIC; + clk : IN STD_LOGIC; + ---------------------------- + + -------- LEDs/SWs ---------- + sw : IN STD_LOGIC_VECTOR(NUM_OF_SWS - 1 DOWNTO 0); -- Switches avaiable on Basys3 + led : OUT STD_LOGIC_VECTOR(NUM_OF_LEDS - 1 DOWNTO 0) -- LEDs avaiable on Basys3 + ---------------------------- + + ); +END KittCar; + +ARCHITECTURE Behavioral OF KittCar IS + SIGNAL leds_sr : STD_LOGIC_VECTOR(led'RANGE) := (OTHERS => '0'); + SIGNAL n_period : POSITIVE RANGE 1 TO (2 ** NUM_OF_SWS) := 1; + SIGNAL up : STD_LOGIC := '1'; +BEGIN + + -- Sincronous logic + PROCESS (clk, reset) + VARIABLE counter_ns : INTEGER := 0; + VARIABLE counter_ms : INTEGER := 0; + BEGIN + IF reset = '1' THEN + leds_sr <= (OTHERS => '0'); + counter_ns := 0; + counter_ms := 0; + ELSIF rising_edge(clk) THEN + + -- Reset the leds + IF unsigned(leds_sr) = 0 THEN + leds_sr(0) <= '1'; + END IF; + + -- Handle counters + counter_ns := counter_ns + CLK_PERIOD_NS; + IF counter_ns >= 1000000 THEN + counter_ms := counter_ms + 1; + counter_ns := 0; + END IF; + + -- Calculate the number of periods + IF counter_ms >= (MIN_KITT_CAR_STEP_MS * n_period) THEN + + -- Shift the leds + IF up = '1' THEN + leds_sr <= leds_sr(NUM_OF_LEDS - 2 DOWNTO 0) & '0'; + ELSIF up = '0' THEN + leds_sr <= '0' & leds_sr(NUM_OF_LEDS - 1 DOWNTO 1); + END IF; + + -- Reset the counter + counter_ms := 0; + END IF; + END IF; + END PROCESS; + + -- Kitt logic + PROCESS (leds_sr) + BEGIN + IF leds_sr(led'HIGH) = '1' THEN + up <= '0'; + ELSIF leds_sr(led'LOW) = '1' THEN + up <= '1'; + END IF; + END PROCESS; + + -- Handle the switch + PROCESS (sw) + BEGIN + n_period <= to_integer(unsigned(sw)) + 1; + END PROCESS; + + led <= leds_sr; + +END Behavioral; \ No newline at end of file diff --git a/LAB1/lab1_kit_car/lab1_kit_car.xpr b/LAB1/lab1_kit_car/lab1_kit_car.xpr index b245740..700d1a7 100644 --- a/LAB1/lab1_kit_car/lab1_kit_car.xpr +++ b/LAB1/lab1_kit_car/lab1_kit_car.xpr @@ -6,7 +6,7 @@ -