From: Thomas Pietrzak Date: Tue, 11 Dec 2018 15:23:54 +0000 (+0100) Subject: new testbench X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=db570d72fc81cf435660fc25bbbfe295b9df5db0;p=forcefader.git new testbench --- diff --git a/fpga/forcefader.srcs/sim_1/new/testbench.v b/fpga/forcefader.srcs/sim_1/new/testbench.v new file mode 100644 index 0000000..80796d1 --- /dev/null +++ b/fpga/forcefader.srcs/sim_1/new/testbench.v @@ -0,0 +1,258 @@ +`timescale 1ns / 1ns + +module testbench( + ); + /* + // Input + reg sysclk; + + //Outputs + wire en; + wire dir; + wire overflow; + + forcefader forcefader_instance ( + .sysclk(sysclk), + .input_touch(0), + .en(en), + .dir(dir), + .overflow(overflow), + .vp_in(0), + .vn_in(0), + .xa_p(0), + .xa_n(0) + ); + */ + + // Input + reg sysclk; + reg [9:0] input_pos; + reg [7:0] stiffness; + reg [9:0] endposition; + + // Temp + wire signed [16:0] outputforce = 0; + + //Outputs + wire en; + wire dir; + wire overflow; + + spring test_spring( + .position(input_pos), + .endposition(endposition), + .stiffness(stiffness), + .outputforce(outputforce) + ); + + //converts force to pwm + direction + forceconverter forceconverter_instance( + .sysclk(sysclk), + .input_forcevalue(outputforce), + .output_direction(dir), + .output_pwm(en), + .output_overflow(overflow) + ); + + + always + #83 sysclk = ~sysclk; + + initial begin + //init + sysclk = 0; + stiffness = 8'h3; + endposition = 10'b0111111111; + input_pos = 0; + + //wait + #100; + + //test + input_pos = 10'h010; + #10000; + + input_pos = 10'h020; + #10000; + + input_pos = 10'h030; + #10000; + + input_pos = 10'h040; + #10000; + + input_pos = 10'h050; + #10000; + + input_pos = 10'h060; + #10000; + + input_pos = 10'h070; + #10000; + + input_pos = 10'h080; + #10000; + + input_pos = 10'h090; + #10000; + + input_pos = 10'h0a0; + #10000; + + input_pos = 10'h0b0; + #10000; + + input_pos = 10'h0c0; + #10000; + + input_pos = 10'h0d0; + #10000; + + input_pos = 10'h0e0; + #10000; + + input_pos = 10'h0f0; + #10000; + + input_pos = 10'h100; + #10000; + + input_pos = 10'h110; + #10000; + + input_pos = 10'h120; + #10000; + + input_pos = 10'h130; + #10000; + + input_pos = 10'h140; + #10000; + + input_pos = 10'h150; + #10000; + + input_pos = 10'h160; + #10000; + + input_pos = 10'h170; + #10000; + + input_pos = 10'h180; + #10000; + + input_pos = 10'h190; + #10000; + + input_pos = 10'h1a0; + #10000; + + input_pos = 10'h1b0; + #10000; + + input_pos = 10'h1c0; + #10000; + + input_pos = 10'h1d0; + #10000; + + input_pos = 10'h1e0; + #10000; + + input_pos = 10'h1f0; + #10000; + + input_pos = 10'h210; + #10000; + + input_pos = 10'h220; + #10000; + + input_pos = 10'h230; + #10000; + + input_pos = 10'h240; + #10000; + + input_pos = 10'h250; + #10000; + + input_pos = 10'h260; + #10000; + + input_pos = 10'h270; + #10000; + + input_pos = 10'h280; + #10000; + + input_pos = 10'h290; + #10000; + + input_pos = 10'h2a0; + #10000; + + input_pos = 10'h2b0; + #10000; + + input_pos = 10'h2c0; + #10000; + + input_pos = 10'h2d0; + #10000; + + input_pos = 10'h2e0; + #10000; + + input_pos = 10'h2f0; + #10000; + + input_pos = 10'h310; + #10000; + + input_pos = 10'h320; + #100; + + input_pos = 10'h330; + #100; + + input_pos = 10'h340; + #100; + + input_pos = 10'h350; + #100; + + input_pos = 10'h360; + #100; + + input_pos = 10'h370; + #100; + + input_pos = 10'h380; + #100; + + input_pos = 10'h390; + #100; + + input_pos = 10'h3a0; + #100; + + input_pos = 10'h3b0; + #100; + + input_pos = 10'h3c0; + #100; + + input_pos = 10'h3d0; + #100; + + input_pos = 10'h3e0; + #100; + + input_pos = 10'h3f0; + #100; + + input_pos = 10'h3ff; + #100; + end +endmodule diff --git a/fpga/forcefader.v b/fpga/forcefader.v index 9a8a5ca..b5cbb88 100644 --- a/fpga/forcefader.v +++ b/fpga/forcefader.v @@ -18,7 +18,10 @@ module forcefader ( wire enable; reg [6:0] address_in = 7'h14; wire ready; - wire [11:0] input_pos; + wire [9:0] input_pos; + wire [15:0] data; + + assign input_pos = data[15:6]; adc adc_instance ( .daddr_in(address_in), @@ -30,7 +33,7 @@ module forcefader ( .vauxn4(xa_n), .busy_out(), .channel_out(), - .do_out(input_pos), + .do_out(data), .drdy_out(ready), .eoc_out(enable), .eos_out(), @@ -43,7 +46,7 @@ module forcefader ( //compute spring force spring spring_instance( - .position(input_pos[11:2]), + .position(input_pos), .endposition(10'b0111111111), .stiffness(8'b00000011), .outputforce(outputforce) diff --git a/fpga/forcefader.xpr b/fpga/forcefader.xpr index d999f87..e44a6a5 100644 --- a/fpga/forcefader.xpr +++ b/fpga/forcefader.xpr @@ -32,7 +32,7 @@