SHARE
TWEET

OK KOD

a guest Sep 3rd, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company:
  4. // Engineer:
  5. //
  6. // Create Date: 01.04.2019 22:36:45
  7. // Design Name:
  8. // Module Name: draw_rect_ctl
  9. // Project Name:
  10. // Target Devices:
  11. // Tool Versions:
  12. // Description:
  13. //
  14. // Dependencies:
  15. //
  16. // Revision:
  17. // Revision 0.01 - File Created
  18. // Additional Comments:
  19. //
  20. //////////////////////////////////////////////////////////////////////////////////
  21.  
  22.  
  23. module dynamic_obst_ctl(
  24.    input wire clk,          //100 Hz
  25.    input wire rst,
  26.    output reg [11:0] xpos,
  27.    output reg [11:0] ypos
  28. );
  29.  
  30. localparam VER_PIXELS = 600;
  31. localparam RECT_HEIGHT = 50;
  32. //localparam v = 2;
  33.  
  34. localparam XPOS_INIT = 600;
  35. localparam YPOS_INIT = 1;
  36.  
  37. localparam DOWN = 2'b01, UP = 2'b10, CHANGE_DIRECTION = 2'b11;
  38.  
  39. reg [11:0] xpos_nxt, ypos_nxt;
  40. reg [15:0] t, t_nxt;  
  41. reg GO_UP;
  42. reg [1:0] state, state_nxt;
  43.  
  44. always @(posedge clk) begin
  45.     if(rst) begin
  46.         xpos <= 0;
  47.         ypos <= 0;  
  48.         state <= DOWN;  
  49.         t <= 0;
  50.     end
  51.     else begin
  52.         xpos <= xpos_nxt;
  53.         ypos <= ypos_nxt;
  54.         state <= state_nxt;
  55.         t <= t_nxt;
  56.     end
  57. end
  58.  
  59. /*
  60. If clock 100 Hz is applied to the module, then t is incremented each 10 ms.
  61. v = 1 pixels/10ms -> obstables moving 100 pixels in 1 sec
  62. */
  63.  
  64. always @* begin
  65.  
  66.     t_nxt = t + 1;
  67.     xpos_nxt = XPOS_INIT;
  68.  
  69.     case (state)
  70.    
  71.         DOWN: begin
  72.               ypos_nxt = YPOS_INIT + 1;
  73.               if (ypos >= (YPOS_INIT + 2*RECT_HEIGHT)) begin
  74.                   state_nxt =  CHANGE_DIRECTION;
  75.                   GO_UP = 1'b1;              
  76.               end
  77.               else begin
  78.                    state_nxt = DOWN;
  79.                    GO_UP = 1'b0;
  80.               end                
  81.         end
  82.        
  83.         UP: begin
  84.             ypos_nxt = ypos - 1;
  85.             if (ypos <= YPOS_INIT) begin
  86.                 state_nxt =  CHANGE_DIRECTION;
  87.                 GO_UP = 1'b0;              
  88.             end
  89.             else begin
  90.                  state_nxt = DOWN;
  91.                  GO_UP = 1'b1;
  92.             end    
  93.         end
  94.        
  95.         CHANGE_DIRECTION: begin
  96.             ypos_nxt = ypos;
  97.             t_nxt = 0;
  98.             state_nxt = GO_UP ? UP : DOWN;
  99.             GO_UP = 1'b0;
  100.         end
  101.        
  102.         default: begin
  103.             ypos_nxt = ypos;
  104.             t_nxt = 0;
  105.             state_nxt = DOWN;
  106.             GO_UP = 1'b0;
  107.        end
  108.     endcase
  109.    
  110. end
  111.  
  112. endmodule
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top