DtrReset.v 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Generates reset pulse for 10 cycles on falling edge of DTR.
  3. * Assumes incoming DTR signal is stabilized.
  4. */
  5. module DtrReset (
  6. input clk, dtr,
  7. output reg dtrRst
  8. );
  9. reg [1:0] state;
  10. parameter s_idle = 0;
  11. parameter s_pulse = 1;
  12. reg dtr_prev; //previous dtr value to check for falling edge
  13. reg [3:0] pulse_counter; //counter for keeping reset high
  14. //Make unstable signal stable at the base clock
  15. always @(posedge clk)
  16. begin
  17. case (state)
  18. s_idle:
  19. begin
  20. if (dtr_prev && !dtr) //falling edge
  21. begin
  22. state <= s_pulse;
  23. pulse_counter <= 4'b1111;
  24. dtrRst <= 1'b1;
  25. end
  26. end
  27. s_pulse:
  28. begin
  29. pulse_counter <= pulse_counter - 1'b1;
  30. if (pulse_counter == 4'd0)
  31. begin
  32. dtrRst <= 1'b0;
  33. state <= s_idle;
  34. end
  35. end
  36. default:
  37. begin
  38. state <= s_idle;
  39. end
  40. endcase
  41. dtr_prev <= dtr;
  42. end
  43. initial
  44. begin
  45. dtrRst <= 1'b0;
  46. dtr_prev <= 1'b0;
  47. state <= s_idle;
  48. pulse_counter <= 4'd0;
  49. end
  50. endmodule