implenet buffer and controller
This commit is contained in:
parent
e9b57fae1e
commit
e1a3bc3d8b
89
ch4/controller.sv
Normal file
89
ch4/controller.sv
Normal file
@ -0,0 +1,89 @@
|
||||
module controller #(parameter N=21)
|
||||
(input logic clk,
|
||||
input logic reset,
|
||||
|
||||
input logic sensor_l,
|
||||
input logic sensor_m,
|
||||
input logic sensor_r,
|
||||
|
||||
input logic [N-1:0] count_in,
|
||||
output logic count_reset,
|
||||
|
||||
output logic motor_l_reset,
|
||||
output logic motor_l_direction,
|
||||
|
||||
output logic motor_r_reset,
|
||||
output logic motor_r_direction);
|
||||
|
||||
typedef enum logic [2:0] {Central, Forward, Gentle_l, Sharp_l, Gentle_r, Sharp_r} control_state;
|
||||
control_state state, next_state;
|
||||
|
||||
always_ff @(posedge clk) begin
|
||||
if(reset)
|
||||
state <= Central;
|
||||
else
|
||||
state <= next_state;
|
||||
end
|
||||
|
||||
assign sensors_lmr = {sensor_l, sensor_m, sensor_r};
|
||||
|
||||
always_comb begin
|
||||
case(state)
|
||||
Central: begin
|
||||
motor_l_reset = 1;
|
||||
motor_l_direction = 0;
|
||||
motor_r_reset = 1;
|
||||
motor_r_direction = 0;
|
||||
|
||||
case(sensors_lmr)
|
||||
3'b000, 3'b010, 3'b101, 3'b111: next_state = Forward;
|
||||
3'b001: next_state = Gentle_l;
|
||||
3'b011: next_state = Sharp_l;
|
||||
3'b100: next_state = Gentle_r;
|
||||
3'b110: next_state = Sharp_r;
|
||||
default: next_state = Central;
|
||||
endcase
|
||||
end
|
||||
Forward: begin
|
||||
motor_l_reset = 0;
|
||||
motor_l_direction = 0;
|
||||
motor_r_reset = 0;
|
||||
motor_r_direction = 1;
|
||||
end
|
||||
Gentle_l: begin
|
||||
motor_l_reset = 1;
|
||||
motor_l_direction = 0;
|
||||
motor_r_reset = 0;
|
||||
motor_r_direction = 1;
|
||||
end
|
||||
Sharp_l: begin
|
||||
motor_l_reset = 0;
|
||||
motor_l_direction = 1;
|
||||
motor_r_reset = 0;
|
||||
motor_r_direction = 1;
|
||||
end
|
||||
Gentle_r: begin
|
||||
motor_l_reset = 0;
|
||||
motor_l_direction = 0;
|
||||
motor_r_reset = 1;
|
||||
motor_r_direction = 0;
|
||||
end
|
||||
Sharp_r: begin
|
||||
motor_l_reset = 0;
|
||||
motor_l_direction = 0;
|
||||
motor_r_reset = 0;
|
||||
motor_r_direction = 0;
|
||||
end
|
||||
default: begin
|
||||
motor_l_reset = 1;
|
||||
motor_l_direction = 0;
|
||||
motor_r_reset = 1;
|
||||
motor_r_direction = 0;
|
||||
end
|
||||
endcase
|
||||
|
||||
end
|
||||
|
||||
|
||||
endmodule
|
||||
|
@ -8,5 +8,17 @@ module inputbuffer
|
||||
output logic sensor_r_out);
|
||||
|
||||
|
||||
logic [2:0]Q_a;
|
||||
|
||||
|
||||
always_ff @(posedge clk)
|
||||
begin
|
||||
Q_a[2] <= sensor_l_in;
|
||||
Q_a[1] <= sensor_m_in;
|
||||
Q_a[0] <= sensor_r_in;
|
||||
sensor_l_out <= Q_a[2];
|
||||
sensor_m_out <= Q_a[1];
|
||||
sensor_r_out <= Q_a[0];
|
||||
end
|
||||
|
||||
endmodule
|
@ -21,7 +21,6 @@ module motorcontrol #(parameter N=21)
|
||||
reset:
|
||||
begin
|
||||
pwm = 0;
|
||||
if (rst == 0)
|
||||
next_state = high;
|
||||
end
|
||||
high:
|
||||
|
13
ch4/robot.sv
Normal file
13
ch4/robot.sv
Normal file
@ -0,0 +1,13 @@
|
||||
module robot
|
||||
(input logic clk,
|
||||
input logic reset,
|
||||
|
||||
input logic sensor_l_in,
|
||||
input logic sensor_m_in,
|
||||
input logic sensor_r_in,
|
||||
|
||||
output logic motor_l_pwm,
|
||||
output logic motor_r_pwm);
|
||||
|
||||
|
||||
endmodule
|
@ -13,23 +13,53 @@
|
||||
# // is prohibited from disclosure under the Trade Secrets Act,
|
||||
# // 18 U.S.C. Section 1905.
|
||||
# //
|
||||
# OpenFile {C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/DSB/github/ch4/timebase.sv}
|
||||
# file mkdir Line_follower_DSB
|
||||
# OpenFile {C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/Q3_2024_2025/DSB/github/ch4/inputbuffer.sv}
|
||||
# Loading project Line_follower_DSB
|
||||
# Compile of inputbuffer.sv failed with 1 errors.
|
||||
# Compile of inputbuffer.sv failed with 1 errors.
|
||||
# Compile of inputbuffer.sv failed with 1 errors.
|
||||
# Compile of inputbuffer.sv was successful.
|
||||
# Error opening C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/DSB/github/ch4/timebase.sv
|
||||
# Path name 'C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/DSB/github/ch4/timebase.sv' doesn't exist.
|
||||
# Error opening C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/DSB/github/ch4/timebase_tb.sv
|
||||
# Path name 'C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/DSB/github/ch4/timebase_tb.sv' doesn't exist.
|
||||
# Compile of motorcontrol.sv was successful.
|
||||
# Compile of motorcontrol_tb.sv was successful.
|
||||
# Compile of timebase_tb.sv was successful.
|
||||
# Compile of timebase.sv was successful.
|
||||
# Load canceled
|
||||
vsim -novopt work.timebase_tb
|
||||
# vsim -novopt work.timebase_tb
|
||||
# Start time: 15:22:45 on Feb 10,2025
|
||||
# Start time: 09:15:44 on Feb 20,2025
|
||||
# ** Warning: (vsim-8891) All optimizations are turned off because the -novopt switch is in effect. This will cause your simulation to run very slowly. If you are using this switch to preserve visibility for Debug or PLI features please see the User's Manual section on Preserving Object Visibility with vopt.
|
||||
# Refreshing C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/DSB/github/ch4/work.timebase_tb
|
||||
# Refreshing C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/Q3_2024_2025/DSB/github/ch4/work.timebase_tb
|
||||
# Loading sv_std.std
|
||||
# Loading work.timebase_tb
|
||||
# Refreshing C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/DSB/github/ch4/work.timebase
|
||||
# Refreshing C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/Q3_2024_2025/DSB/github/ch4/work.timebase
|
||||
# Loading work.timebase
|
||||
run 200ns
|
||||
# ** Note: $finish : C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/DSB/github/ch4/timebase_tb.sv(22)
|
||||
# Time: 200 ns Iteration: 0 Instance: /timebase_tb
|
||||
# End time: 15:23:19 on Feb 10,2025, Elapsed time: 0:00:34
|
||||
run 400ns
|
||||
# ** Note: $finish : C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/Q3_2024_2025/DSB/github/ch4/timebase_tb.sv(22)
|
||||
# Time: 210 ns Iteration: 0 Instance: /timebase_tb
|
||||
# 1
|
||||
# Break in Module timebase_tb at C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/Q3_2024_2025/DSB/github/ch4/timebase_tb.sv line 22
|
||||
# Compile of motorcontrol.sv was successful.
|
||||
vsim -novopt work.motorcontrol_tb
|
||||
# End time: 09:24:08 on Feb 20,2025, Elapsed time: 0:08:24
|
||||
# Errors: 0, Warnings: 1
|
||||
# vsim -novopt work.motorcontrol_tb
|
||||
# Start time: 09:24:08 on Feb 20,2025
|
||||
# ** Warning: (vsim-8891) All optimizations are turned off because the -novopt switch is in effect. This will cause your simulation to run very slowly. If you are using this switch to preserve visibility for Debug or PLI features please see the User's Manual section on Preserving Object Visibility with vopt.
|
||||
# Refreshing C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/Q3_2024_2025/DSB/github/ch4/work.motorcontrol_tb
|
||||
# Loading sv_std.std
|
||||
# Loading work.motorcontrol_tb
|
||||
# Loading work.timebase
|
||||
# Refreshing C:/Users/Stan Oremus/OneDrive/Documenten/TU Delft Lasse Oremus/Q3_2024_2025/DSB/github/ch4/work.motorcontrol
|
||||
# Loading work.motorcontrol
|
||||
run 40ms
|
||||
quit -sim
|
||||
# End time: 09:25:22 on Feb 20,2025, Elapsed time: 0:01:14
|
||||
# Errors: 0, Warnings: 1
|
||||
# Compile of controller.sv failed with 2 errors.
|
||||
# Compile of controller.sv failed with 2 errors.
|
||||
# Compile of controller.sv failed with 2 errors.
|
||||
# Compile of controller.sv failed with 2 errors.
|
||||
# Compile of controller.sv was successful.
|
||||
|
Loading…
x
Reference in New Issue
Block a user