SHARE
TWEET

Obst_ctl

a guest Sep 3rd, 2019 81 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.         t <= 0;
  49.     end
  50.     else begin
  51.         xpos <= xpos_nxt;
  52.         ypos <= ypos_nxt;
  53.         t <= t_nxt;
  54.     end
  55. end
  56.  
  57. initial begin
  58.     ypos = YPOS_INIT;
  59.     xpos = XPOS_INIT;
  60. end
  61.  
  62. /*always @(*) begin
  63.         if ( ypos < 550 ) begin
  64.             xpos_nxt = xpos;
  65.             ypos_nxt = ypos+t+1;
  66.             t_nxt = t+1;
  67.         end
  68.         else if ( ypos >= 550 ) begin
  69.             xpos_nxt = xpos;
  70.             ypos_nxt = ypos-t-1;
  71.             t_nxt = t-1;
  72.         end
  73.         else begin
  74.             xpos_nxt = xpos;
  75.             ypos_nxt = ypos;
  76.         end
  77. end*/
  78.  
  79. /*
  80. If clock 100 Hz is applied to the module, then t is incremented each 10 ms.
  81. v = 1 pixels/10ms -> obstables moving 100 pixels in 1 sec
  82. */
  83.  
  84. always @* begin
  85.  
  86.     t_nxt = t + 1;
  87.  
  88.     case (state)
  89.    
  90.         DOWN: begin
  91.               if (ypos > 500 ) begin
  92.                 ypos_nxt = YPOS_INIT + ypos + t;
  93.                 state_nxt =  CHANGE_DIRECTION;
  94.                 GO_UP = 1'b1;              
  95.               end
  96.               else begin
  97.                 ypos_nxt = ypos + t + 1;
  98.                 state_nxt = DOWN;
  99.                 GO_UP = 1'b0;
  100.               end                
  101.         end
  102.        
  103.         UP: begin
  104.             if (ypos < 20 ) begin
  105.                 ypos_nxt = ypos - 1;
  106.                 state_nxt =  CHANGE_DIRECTION;
  107.                 GO_UP = 1'b0;              
  108.             end
  109.             else begin
  110.                 ypos_nxt = YPOS_INIT - ypos - 1;
  111.                 state_nxt = DOWN;
  112.                 GO_UP = 1'b1;
  113.             end    
  114.         end
  115.        
  116.         CHANGE_DIRECTION: begin
  117.             ypos_nxt = ypos;
  118.             state_nxt = GO_UP ? UP : DOWN;
  119.             t_nxt = 1;
  120.         end
  121.        
  122.     endcase
  123. end
  124.  
  125. 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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top