Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2015
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module mojo_top(
  2.     // 50MHz clock input
  3.     input clk,
  4.     // Input from reset button (active low)
  5.     input rst_n,
  6.     // cclk input from AVR, high when AVR is ready
  7.     input cclk,
  8.     // Outputs to the 8 onboard LEDs
  9.     output[7:0]led,
  10.     // AVR SPI connections
  11.     output spi_miso,
  12.     input spi_ss,
  13.     input spi_mosi,
  14.     input spi_sck,
  15.     // AVR ADC channel select
  16.     output [3:0] spi_channel,
  17.     // Serial connections
  18.     input avr_tx, // AVR Tx => FPGA Rx
  19.     output avr_rx, // AVR Rx => FPGA Tx
  20.     input avr_rx_busy, // AVR Rx buffer full
  21.      
  22.      output reg[2:0] levels,
  23.      output reg[8:0] columns
  24.     );
  25.  
  26. wire rst = ~rst_n; // make reset active high
  27.  
  28. // these signals should be high-z when not used
  29. assign spi_miso = 1'bz;
  30. assign avr_rx = 1'bz;
  31. assign spi_channel = 4'bzzzz;
  32.  
  33. assign led = 8'b0;
  34.  
  35.  
  36. /* clk divider to reduce the LED blink speed to 1/10 of a second
  37. */
  38. reg[22:0] div;
  39. wire cube_clk = (div == 23'h4c4b40);
  40. always @ (posedge clk) begin
  41.     if(cube_clk)
  42.         div <= 23'b0;
  43.     else
  44.         div <= div + 1;
  45. end
  46.  
  47. wire [1:0] lvl; //level vector for the LED_counter driver
  48. wire [3:0] clm; //column vector for the LED_counter driver
  49. LED_counter cube(.clk(cube_clk), .level(lvl), .column(clm));
  50.  
  51. /* Depending on the count, turns on one of the levels.
  52. */
  53. always @ (lvl) begin
  54.     case(lvl)
  55.         0: levels <= 3'b001;
  56.         1: levels <= 3'b010;
  57.         2: levels <= 3'b100;
  58.         default: levels <= 3'b000;
  59.     endcase
  60. end
  61.  
  62.  
  63. /* Depending on the count, turns on one of the columns.
  64. */
  65. always @ (clm) begin
  66.     case(clm)
  67.         0: columns <= 9'd1;
  68.         1: columns <= 9'd2;
  69.         2: columns <= 9'd4;
  70.         3: columns <= 9'd8;
  71.         4: columns <= 9'd16;
  72.         5: columns <= 9'd32;
  73.         6: columns <= 9'd64;
  74.         7: columns <= 9'd128;
  75.         8: columns <= 9'd256;
  76.         default: columns <= 9'd0;
  77.     endcase
  78. end
  79.  
  80. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement