prod2u_hthd_prod_uart_top.v 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. `timescale 1ns/1ps
  2. // hthd-in-the-loop wrapper using production UART 217 clocks/bit (25 MHz / 115200).
  3. // Motor tick is still accelerated so seek-close/measure-open can finish in sim.
  4. // This does not modify production RTL sources.
  5. module prod2u_hthd_prod_uart_top (
  6. input wire host_uart_rx,
  7. output wire host_uart_tx,
  8. output wire [7:0] ptc_pwm_out,
  9. output wire [3:0] fan_pwm_out,
  10. output wire motor_en_n,
  11. output wire x_step,
  12. output wire x_dir,
  13. output wire y_step,
  14. output wire y_dir,
  15. output wire z_step,
  16. output wire z_dir,
  17. input wire x_limit_ls,
  18. input wire x_limit_hs,
  19. input wire y_limit_ls,
  20. input wire y_limit_hs,
  21. input wire z_limit_ls,
  22. input wire z_limit_hs,
  23. inout wire temp_scl,
  24. inout wire temp_sda
  25. );
  26. reg sys_clk = 1'b0;
  27. always #20 sys_clk = ~sys_clk;
  28. reg [6:0] tick_div = 7'd0;
  29. reg fast_tick = 1'b0;
  30. always @(posedge sys_clk) begin
  31. if (tick_div + 1'b1 >= 7'd100) begin
  32. tick_div <= 7'd0;
  33. fast_tick <= 1'b1;
  34. end else begin
  35. tick_div <= tick_div + 1'b1;
  36. fast_tick <= 1'b0;
  37. end
  38. end
  39. prod2u_p4_normal_v3_top u_dut (
  40. .sys_clk(sys_clk), .host_uart_rx(host_uart_rx), .host_uart_tx(host_uart_tx),
  41. .ptc_pwm_out(ptc_pwm_out), .fan_pwm_out(fan_pwm_out),
  42. .motor_en_n(motor_en_n),
  43. .x_step(x_step), .x_dir(x_dir), .y_step(y_step), .y_dir(y_dir),
  44. .z_step(z_step), .z_dir(z_dir),
  45. .x_limit_ls(x_limit_ls), .x_limit_hs(x_limit_hs),
  46. .y_limit_ls(y_limit_ls), .y_limit_hs(y_limit_hs),
  47. .z_limit_ls(z_limit_ls), .z_limit_hs(z_limit_hs),
  48. .temp_scl(temp_scl), .temp_sda(temp_sda)
  49. );
  50. defparam u_dut.u_uart_rx.CLKS_PER_BIT = 217;
  51. defparam u_dut.u_uart_tx.CLKS_PER_BIT = 217;
  52. // Production UART stays 217 clocks/bit. Icarus wall-clock for 27 I2C
  53. // TIMEOUT_CLKS=25000 reads exceeds hthd's 20s GET_TEMPERATURE budget
  54. // (must stay < firmware watchdog 30s). Shorten only the sim I2C bit
  55. // time / NACK timeout, same idea as the accelerated motor tick.
  56. defparam u_dut.u_temperature_i2c.HALF_PERIOD_CLKS = 2;
  57. defparam u_dut.u_temperature_i2c.TIMEOUT_CLKS = 16;
  58. defparam u_dut.u_temperature_i2c.impl.HALF_PERIOD_CLKS = 2;
  59. defparam u_dut.u_temperature_i2c.impl.TIMEOUT_CLKS = 16;
  60. initial begin
  61. force u_dut.tick_500us = fast_tick;
  62. end
  63. endmodule