| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- `timescale 1ns/1ps
- // hthd-in-the-loop wrapper using production UART 217 clocks/bit (25 MHz / 115200).
- // Motor tick is still accelerated so seek-close/measure-open can finish in sim.
- // This does not modify production RTL sources.
- module prod2u_hthd_prod_uart_top (
- input wire host_uart_rx,
- output wire host_uart_tx,
- output wire [7:0] ptc_pwm_out,
- output wire [3:0] fan_pwm_out,
- output wire motor_en_n,
- output wire x_step,
- output wire x_dir,
- output wire y_step,
- output wire y_dir,
- output wire z_step,
- output wire z_dir,
- input wire x_limit_ls,
- input wire x_limit_hs,
- input wire y_limit_ls,
- input wire y_limit_hs,
- input wire z_limit_ls,
- input wire z_limit_hs,
- inout wire temp_scl,
- inout wire temp_sda
- );
- reg sys_clk = 1'b0;
- always #20 sys_clk = ~sys_clk;
- reg [6:0] tick_div = 7'd0;
- reg fast_tick = 1'b0;
- always @(posedge sys_clk) begin
- if (tick_div + 1'b1 >= 7'd100) begin
- tick_div <= 7'd0;
- fast_tick <= 1'b1;
- end else begin
- tick_div <= tick_div + 1'b1;
- fast_tick <= 1'b0;
- end
- end
- prod2u_p4_normal_v3_top u_dut (
- .sys_clk(sys_clk), .host_uart_rx(host_uart_rx), .host_uart_tx(host_uart_tx),
- .ptc_pwm_out(ptc_pwm_out), .fan_pwm_out(fan_pwm_out),
- .motor_en_n(motor_en_n),
- .x_step(x_step), .x_dir(x_dir), .y_step(y_step), .y_dir(y_dir),
- .z_step(z_step), .z_dir(z_dir),
- .x_limit_ls(x_limit_ls), .x_limit_hs(x_limit_hs),
- .y_limit_ls(y_limit_ls), .y_limit_hs(y_limit_hs),
- .z_limit_ls(z_limit_ls), .z_limit_hs(z_limit_hs),
- .temp_scl(temp_scl), .temp_sda(temp_sda)
- );
- defparam u_dut.u_uart_rx.CLKS_PER_BIT = 217;
- defparam u_dut.u_uart_tx.CLKS_PER_BIT = 217;
- // Production UART stays 217 clocks/bit. Icarus wall-clock for 27 I2C
- // TIMEOUT_CLKS=25000 reads exceeds hthd's 20s GET_TEMPERATURE budget
- // (must stay < firmware watchdog 30s). Shorten only the sim I2C bit
- // time / NACK timeout, same idea as the accelerated motor tick.
- defparam u_dut.u_temperature_i2c.HALF_PERIOD_CLKS = 2;
- defparam u_dut.u_temperature_i2c.TIMEOUT_CLKS = 16;
- defparam u_dut.u_temperature_i2c.impl.HALF_PERIOD_CLKS = 2;
- defparam u_dut.u_temperature_i2c.impl.TIMEOUT_CLKS = 16;
- initial begin
- force u_dut.tick_500us = fast_tick;
- end
- endmodule
|