Fixed code not working
This commit is contained in:
parent
39b767629c
commit
7752316651
@ -1,3 +1,5 @@
|
|||||||
|
`timescale 1ns/1ps
|
||||||
|
|
||||||
module controller #(parameter N=21)
|
module controller #(parameter N=21)
|
||||||
(input logic clk,
|
(input logic clk,
|
||||||
input logic reset,
|
input logic reset,
|
||||||
@ -25,6 +27,8 @@ always_ff @(posedge clk, posedge count_reset, posedge reset) begin
|
|||||||
state <= next_state;
|
state <= next_state;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
logic [2:0] sensors_lmr;
|
||||||
|
|
||||||
assign sensors_lmr = {sensor_l, sensor_m, sensor_r};
|
assign sensors_lmr = {sensor_l, sensor_m, sensor_r};
|
||||||
|
|
||||||
always_comb begin
|
always_comb begin
|
||||||
@ -54,36 +58,48 @@ always_comb begin
|
|||||||
motor_l_direction = 1;
|
motor_l_direction = 1;
|
||||||
motor_r_reset = 0;
|
motor_r_reset = 0;
|
||||||
motor_r_direction = 0;
|
motor_r_direction = 0;
|
||||||
|
|
||||||
|
next_state = state;
|
||||||
end
|
end
|
||||||
Gentle_l: begin
|
Gentle_l: begin
|
||||||
motor_l_reset = 1;
|
motor_l_reset = 1;
|
||||||
motor_l_direction = 0;
|
motor_l_direction = 0;
|
||||||
motor_r_reset = 0;
|
motor_r_reset = 0;
|
||||||
motor_r_direction = 0;
|
motor_r_direction = 0;
|
||||||
|
|
||||||
|
next_state = state;
|
||||||
end
|
end
|
||||||
Sharp_l: begin
|
Sharp_l: begin
|
||||||
motor_l_reset = 0;
|
motor_l_reset = 0;
|
||||||
motor_l_direction = 0;
|
motor_l_direction = 0;
|
||||||
motor_r_reset = 0;
|
motor_r_reset = 0;
|
||||||
motor_r_direction = 0;
|
motor_r_direction = 0;
|
||||||
|
|
||||||
|
next_state = state;
|
||||||
end
|
end
|
||||||
Gentle_r: begin
|
Gentle_r: begin
|
||||||
motor_l_reset = 0;
|
motor_l_reset = 0;
|
||||||
motor_l_direction = 1;
|
motor_l_direction = 1;
|
||||||
motor_r_reset = 1;
|
motor_r_reset = 1;
|
||||||
motor_r_direction = 0;
|
motor_r_direction = 0;
|
||||||
|
|
||||||
|
next_state = state;
|
||||||
end
|
end
|
||||||
Sharp_r: begin
|
Sharp_r: begin
|
||||||
motor_l_reset = 0;
|
motor_l_reset = 0;
|
||||||
motor_l_direction = 1;
|
motor_l_direction = 1;
|
||||||
motor_r_reset = 0;
|
motor_r_reset = 0;
|
||||||
motor_r_direction = 1;
|
motor_r_direction = 1;
|
||||||
|
|
||||||
|
next_state = state;
|
||||||
end
|
end
|
||||||
default: begin
|
default: begin
|
||||||
motor_l_reset = 1;
|
motor_l_reset = 1;
|
||||||
motor_l_direction = 0;
|
motor_l_direction = 0;
|
||||||
motor_r_reset = 1;
|
motor_r_reset = 1;
|
||||||
motor_r_direction = 0;
|
motor_r_direction = 0;
|
||||||
|
|
||||||
|
next_state = state;
|
||||||
end
|
end
|
||||||
endcase
|
endcase
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
`timescale 1ns/1ps
|
||||||
|
|
||||||
module inputbuffer
|
module inputbuffer
|
||||||
(input logic clk,
|
(input logic clk,
|
||||||
input logic sensor_l_in,
|
input logic sensor_l_in,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
`timescale 1ns/1ps
|
||||||
|
|
||||||
module robot
|
module robot
|
||||||
(input logic clk,
|
(input logic clk,
|
||||||
input logic reset,
|
input logic reset,
|
||||||
|
@ -29,6 +29,9 @@ module robot_tb();
|
|||||||
end
|
end
|
||||||
|
|
||||||
initial begin
|
initial begin
|
||||||
|
$dumpfile("output.vcd");
|
||||||
|
$dumpvars;
|
||||||
|
|
||||||
#0ms; sensors = 3'b000; // Forward
|
#0ms; sensors = 3'b000; // Forward
|
||||||
#70ms; sensors = 3'b001; // Gentle left
|
#70ms; sensors = 3'b001; // Gentle left
|
||||||
#40ms; sensors = 3'b010; // Forward
|
#40ms; sensors = 3'b010; // Forward
|
||||||
@ -37,6 +40,8 @@ module robot_tb();
|
|||||||
#40ms; sensors = 3'b101; // Forward
|
#40ms; sensors = 3'b101; // Forward
|
||||||
#40ms; sensors = 3'b110; // Sharp right
|
#40ms; sensors = 3'b110; // Sharp right
|
||||||
#40ms; sensors = 3'b111; // Forward
|
#40ms; sensors = 3'b111; // Forward
|
||||||
|
|
||||||
|
#40ms; $finish;
|
||||||
end
|
end
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
Loading…
x
Reference in New Issue
Block a user