Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
152
0
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: 31.03.2020 13:05:10
  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 draw_rect_ctl(
  24.     input wire clk,
  25.     input wire mouse_left,
  26.     input wire [11:0] mouse_xpos,
  27.     input wire [11:0] mouse_ypos,
  28.     output reg [11:0] xpos,
  29.     output reg [11:0] ypos
  30.     );
  31.    
  32.     localparam
  33.         licznik = 1000000,
  34.         final_y = 535;
  35.    
  36.     reg [19:0] counter = 0;
  37.     reg [19:0] counter_nxt = 0;
  38.    
  39.     reg [11:0] time_counter = 0;
  40.     reg [11:0] time_counter_nxt = 0;
  41.    
  42.     reg [11:0] initial_x, initial_y;
  43.     reg [11:0] current_y, current_x;
  44.    
  45.     reg movement = 0;
  46.    
  47.     always @(posedge mouse_left)
  48.     begin
  49.         initial_y = mouse_ypos;
  50.     end
  51.    
  52.     always @*
  53.     begin
  54.         counter_nxt = counter;
  55.        
  56.         if ((counter == licznik)  && (mouse_left == 1) && (movement == 1))
  57.         begin
  58.             counter_nxt = 0;
  59.             time_counter_nxt = time_counter + 1;
  60.         end
  61.        
  62.         if (mouse_left == 1)
  63.         begin
  64.             current_y = initial_y + time_counter;
  65.         end
  66.        
  67.         if ((current_y >= final_y) && (mouse_left == 1))
  68.         begin
  69.             //position_counter_nxt = 12'b000000000000;
  70.             movement = 0;
  71.             current_y = final_y;
  72.         end
  73.        
  74.         if (mouse_left == 1'b0)
  75.         begin
  76.             current_x = mouse_xpos;
  77.             current_y = mouse_ypos;
  78.             time_counter_nxt = 0;
  79.             counter_nxt = 0;
  80.             movement = 1;
  81.         end
  82.     end
  83.    
  84.     always @(posedge clk)
  85.     begin
  86.         counter <= counter_nxt + 1;
  87.         time_counter <= time_counter_nxt;
  88.         ypos <= current_y;
  89.         xpos <= current_x;
  90.     end
  91.    
  92. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement