From 77523166517ba95f945f554fb54dcbfbabb15418 Mon Sep 17 00:00:00 2001 From: xeovalyte Date: Thu, 20 Feb 2025 12:57:17 +0100 Subject: [PATCH] Fixed code not working --- ch4/controller.sv | 16 ++++++++++++++++ ch4/inputbuffer.sv | 2 ++ ch4/robot.sv | 2 ++ ch4/robot_tb.sv | 5 +++++ 4 files changed, 25 insertions(+) diff --git a/ch4/controller.sv b/ch4/controller.sv index 4719fdb..3f15abb 100644 --- a/ch4/controller.sv +++ b/ch4/controller.sv @@ -1,3 +1,5 @@ +`timescale 1ns/1ps + module controller #(parameter N=21) (input logic clk, input logic reset, @@ -25,6 +27,8 @@ always_ff @(posedge clk, posedge count_reset, posedge reset) begin state <= next_state; end +logic [2:0] sensors_lmr; + assign sensors_lmr = {sensor_l, sensor_m, sensor_r}; always_comb begin @@ -54,36 +58,48 @@ always_comb begin motor_l_direction = 1; motor_r_reset = 0; motor_r_direction = 0; + + next_state = state; end Gentle_l: begin motor_l_reset = 1; motor_l_direction = 0; motor_r_reset = 0; motor_r_direction = 0; + + next_state = state; end Sharp_l: begin motor_l_reset = 0; motor_l_direction = 0; motor_r_reset = 0; motor_r_direction = 0; + + next_state = state; end Gentle_r: begin motor_l_reset = 0; motor_l_direction = 1; motor_r_reset = 1; motor_r_direction = 0; + + next_state = state; end Sharp_r: begin motor_l_reset = 0; motor_l_direction = 1; motor_r_reset = 0; motor_r_direction = 1; + + next_state = state; end default: begin motor_l_reset = 1; motor_l_direction = 0; motor_r_reset = 1; motor_r_direction = 0; + + next_state = state; end endcase diff --git a/ch4/inputbuffer.sv b/ch4/inputbuffer.sv index d0a647c..ead5d1b 100644 --- a/ch4/inputbuffer.sv +++ b/ch4/inputbuffer.sv @@ -1,3 +1,5 @@ +`timescale 1ns/1ps + module inputbuffer (input logic clk, input logic sensor_l_in, diff --git a/ch4/robot.sv b/ch4/robot.sv index ef8b055..d9f267f 100644 --- a/ch4/robot.sv +++ b/ch4/robot.sv @@ -1,3 +1,5 @@ +`timescale 1ns/1ps + module robot (input logic clk, input logic reset, diff --git a/ch4/robot_tb.sv b/ch4/robot_tb.sv index 932d974..86280a6 100644 --- a/ch4/robot_tb.sv +++ b/ch4/robot_tb.sv @@ -29,6 +29,9 @@ module robot_tb(); end initial begin + $dumpfile("output.vcd"); + $dumpvars; + #0ms; sensors = 3'b000; // Forward #70ms; sensors = 3'b001; // Gentle left #40ms; sensors = 3'b010; // Forward @@ -37,6 +40,8 @@ module robot_tb(); #40ms; sensors = 3'b101; // Forward #40ms; sensors = 3'b110; // Sharp right #40ms; sensors = 3'b111; // Forward + + #40ms; $finish; end endmodule