SHARE
TWEET

Untitled

a guest Sep 4th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. always @(posedge clk) begin
  2.     if(rst) begin
  3.         xpos <= 0;
  4.         ypos <= 0;  
  5.         state <= DOWN;  
  6.     end
  7.     else begin
  8.         xpos <= xpos_nxt;
  9.         ypos <= ypos_nxt;
  10.         state <= state_nxt;
  11.     end
  12. end
  13.  
  14. always @* begin
  15.  
  16.     xpos_nxt = XPOS_INIT;
  17.    
  18.     case (state)
  19.    
  20.     DOWN: begin
  21.    
  22.         ypos_nxt = ypos + 1;
  23.        
  24.         if ( ypos >= 300) begin
  25.             GO_UP = 1'b1;
  26.             state_nxt = CHANGE_DIRECTION;
  27.         end
  28.         else begin
  29.             GO_UP = 1'b0;
  30.             state_nxt = DOWN;
  31.         end
  32.        
  33.     end
  34.    
  35.     UP: begin
  36.        
  37.         ypos_nxt = ypos - 1;
  38.        
  39.         if ( ypos <= 1) begin
  40.             state_nxt = CHANGE_DIRECTION;
  41.             GO_UP = 1'b0;
  42.         end
  43.         else begin
  44.             GO_UP = 1'b1;
  45.             state_nxt = UP;
  46.         end
  47.     end
  48.    
  49.     CHANGE_DIRECTION: begin
  50.    
  51.         ypos_nxt = ypos;
  52.         state_nxt = GO_UP ? UP : DOWN;
  53.         GO_UP = 1'b0;      
  54.              
  55.     end
  56.    
  57.     default: begin
  58.         GO_UP = 1'b0;
  59.         state_nxt = DOWN;
  60.     end
  61.    
  62. endcase
  63. end
  64.  
  65. 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