Line follower chapter 5

This commit is contained in:
lasse 2025-02-13 12:19:44 +01:00
parent 04ae50199e
commit 993ca7d0bf
4 changed files with 120 additions and 10 deletions

43
ch4/motorcontrol.sv Normal file
View File

@ -0,0 +1,43 @@
module motorcontrol #(parameter N=21)
(input logic clk,
input logic rst,
input logic direction,
input logic [N-1:0] count_in,
output logic pwm);
typedef enum logic[1:0] {reset, high, low} pwm_state;
pwm_state state, next_state;
always_ff @(posedge clk)
if (rst)
state <= reset;
else
state <= next_state;
always_comb
begin
case (state)
reset:
begin
pwm = 0;
if (rst == 0)
next_state = high;
end
high:
begin
pwm = 1;
if (direction == 0 && count_in >= 21'd100_000)
next_state = low;
else if ( direction == 1 && count_in >= 21'd200_000)
next_state = low;
else
next_state = state;
end
low:
begin
pwm = 0;
next_state = state;
end
endcase
end
endmodule

29
ch4/motorcontrol_tb.sv Normal file
View File

@ -0,0 +1,29 @@
`timescale 1ns/1ps
module motorcontrol_tb();
logic clk;
logic rst;
logic direction;
logic [20:0] count;
logic pwm;
timebase test1 (clk, rst, count);
motorcontrol test2 (clk, rst, direction, count, pwm);
always
#5 clk = ~clk; // period 10ns (100 MHz)
initial
clk = 0;
initial begin
rst = 1; direction = 0;
#10; rst = 0;
#19999990; rst = 1; direction = 1;
#10; rst = 0;
#19999990; rst = 1;
#10; rst = 0;
end
endmodule

48
ch4/vish_stacktrace.vstf Normal file
View File

@ -0,0 +1,48 @@
# Current time Thu Feb 13 11:59:20 2025
# Program = vish
# Id = "10.6g"
# Version = "2019.08"
# Date = "Aug 3 2019"
# Platform = win64
Exception c0000005 has occurred at address 50862f76. Traceback:
# 0 0x50862f76: 'Tk_UpdatePointer + 0x7ad6'
# 1 0x50864aa0: 'Tk_GetSelection + 0x160'
# 2 0x507e71c9: 'TkClipInit + 0xac9'
# 3 0x50976c03: 'TclNRRunCallbacks + 0x63'
# 4 0xef010bfa: 'Itcl_EvalMemberCode + 0x3ba'
# 5 0xef011dbb: 'Itcl_ExecMethod + 0x23b'
# 6 0xef019879: 'Itcl_EvalArgs + 0x1c9'
# 7 0xef014b51: 'Itcl_HandleInstance + 0x2c1'
# 8 0x50976c03: 'TclNRRunCallbacks + 0x63'
# 9 0xef010bfa: 'Itcl_EvalMemberCode + 0x3ba'
# 10 0xef011dbb: 'Itcl_ExecMethod + 0x23b'
# 11 0xef019879: 'Itcl_EvalArgs + 0x1c9'
# 12 0xef014b51: 'Itcl_HandleInstance + 0x2c1'
# 13 0x50976c03: 'TclNRRunCallbacks + 0x63'
# 14 0x5097586c: 'TclCleanupCommand + 0x88c'
# 15 0x50978d4f: 'Tcl_EvalEx + 0x1f'
# 16 0x507b431a: 'Tk_BindEvent + 0x91a'
# 17 0x507ebd41: 'TkBindEventProc + 0x291'
# 18 0x507fc614: 'Tk_HandleEvent + 0x2f4'
# 19 0x507b12d5: 'TkStringToKeysym + 0x2bd5'
# 20 0x507b21a8: 'TkStringToKeysym + 0x3aa8'
# 21 0x50976c03: 'TclNRRunCallbacks + 0x63'
# 22 0x5097586c: 'TclCleanupCommand + 0x88c'
# 23 0x50978d4f: 'Tcl_EvalEx + 0x1f'
# 24 0x507b431a: 'Tk_BindEvent + 0x91a'
# 25 0x507ebd41: 'TkBindEventProc + 0x291'
# 26 0x507fc614: 'Tk_HandleEvent + 0x2f4'
# 27 0x507fb2da: 'TkDeleteThreadExitHandler + 0x31a'
# 28 0x50a1d41c: 'Tcl_ServiceEvent + 0x9c'
# 29 0x50a1d0b4: 'Tcl_DoOneEvent + 0x124'
# 30 0x507faee5: 'Tk_MainLoop + 0x25'
# 31 0x5083d282: 'Tk_MainEx + 0x932'
# 32 0x401d3a00: 'Mtirpc_Init + 0x223c0'
# 33 0x401d60a8: 'Mtirpc_Init + 0x24a68'
# 34 0x405f1a6f: 'Tclsqlite_Init + 0x1a5f'
# 35 0x2708259d: 'BaseThreadInitThunk + 0x1d'
# 36 0x2806af38: 'RtlUserThreadStart + 0x28'
StackWalk failed 0
# End of Stack Trace

View File

@ -1,10 +0,0 @@
module motorcontrol
(input logic clk,
input logic reset,
input logic direction,
input logic [?:0] count_in,
output logic pwm);
endmodule