Advertisement
DarthAurelius

Flashy flashy

Mar 18th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Module to receive USART letters from the PC and toggle
  2. // 4 leds.
  3. // Rafael Arce Nazario 2017
  4.  
  5. module top
  6. (
  7.     input wire          clk,
  8.     input wire          ftdi_rx,
  9.      output reg [3:0]   led = 4'b0001
  10. );
  11.  
  12. wire uart_valid;
  13.  
  14. wire [7:0] uart_data_rx;
  15.  
  16. wire letter_a, letter_s, letter_d, letter_f;
  17.  
  18.  
  19.  
  20. // Combinational logic
  21. assign letter_a = uart_valid && (uart_data_rx == 8'h61);
  22. assign letter_s = uart_valid && (uart_data_rx == 8'h73);
  23. assign letter_d = uart_valid && (uart_data_rx == 8'h64);
  24. assign letter_f = uart_valid && (uart_data_rx == 8'h66);
  25.  
  26. // Module instantiation
  27. uart_rx rx0 (
  28.     .clk(clk),
  29.     .rst(1'b0),
  30.     .din(ftdi_rx),
  31.     .data_out(uart_data_rx),
  32.     .valid(uart_valid)
  33. );
  34.  
  35. reg  [24:0]count = 0;
  36. reg  speed = 32000000;
  37.  
  38.  
  39.  
  40. //flash rot(.f(letter_s) , .s(letter_a) , .clk(clk) , .count(count), .speed(speed) );
  41.  
  42.  
  43. // Whenever the signals letter_a, etc pulse then
  44. // toggle the corresponding output.
  45.  
  46. //always @(posedge clk)
  47. //  begin
  48.    
  49. /*
  50.     if (letter_a)
  51.             led[0] <= ~led[0];
  52.        
  53.     if (letter_s)
  54.             led[1] <= ~led[1];
  55.        
  56.     if (letter_d)
  57.             led[2] <= ~led[2];
  58.        
  59.     if (letter_f)
  60.             led[3] <= ~led[3];
  61. */
  62. //  end
  63.  
  64.     always @(posedge clk)
  65.         begin
  66.        
  67.         if(letter_s)
  68.             speed <= speed << 1;
  69.            
  70.         if(letter_a)
  71.             speed <= speed >> 1;
  72.        
  73.        
  74.         count <= count + 1;
  75.         if (count == speed)
  76.             begin
  77.                 led <= {led[2:0], led[3]};
  78.                 count <= 0;
  79.             end
  80.         end
  81.        
  82.         /*
  83.         led[0] <= out[0];
  84.    
  85.         led[1] <= out[1];
  86.        
  87.         led[2] <= out[2];
  88.        
  89.         led[3] <= out[3];
  90.        
  91.        
  92.         end
  93.         */
  94.  
  95.  
  96.  
  97. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement