module mefi8x8a(input CLK, input [7:0] BCOL_IN, output [7:0] BCOL_OUT, output [7:0] BROW, input [63:0] LEDS2LIT, output [63:0] PIECES_ON_BOARD ); reg [63:0] PIECES; assign PIECES_ON_BOARD = PIECES; reg [7:0] BCOL_IN_S = 8'b0; // The multiplexed row, one-hot in 8-bit shift register: reg [7:0] sel_row = 8'b00000001; // 50 MHz/50Hz = 1 million ~= 2^20 parameter msb = 15; // Use 26; for a little over second. reg [msb+3:0] whole_cycle = 0; parameter kuuw = 2; wire [kuuw:0] kuu = whole_cycle[msb:msb-kuuw]; wire [2:0] row_ind = whole_cycle[msb+3:msb+1]; wire [msb:0] row_period = whole_cycle[msb:0]; // We turn the 1/8th time the row signals completely off // (after switch from one row to next), so that we don't // get dim, but superfluous "pre-" and "afterglows" below and // on the top of each LED that should glow. // (This because the slowness of the optoisolators // in the interface module). assign BROW = ((~|kuu) ? 8'b00000000 : sel_row); wire [5:0] rowbit0 = {row_ind,3'b000}; wire [5:0] rowbit1 = {row_ind,3'b001}; wire [5:0] rowbit2 = {row_ind,3'b010}; wire [5:0] rowbit3 = {row_ind,3'b011}; wire [5:0] rowbit4 = {row_ind,3'b100}; wire [5:0] rowbit5 = {row_ind,3'b101}; wire [5:0] rowbit6 = {row_ind,3'b110}; wire [5:0] rowbit7 = {row_ind,3'b111}; assign BCOL_OUT = {LEDS2LIT[rowbit7],LEDS2LIT[rowbit6],LEDS2LIT[rowbit5],LEDS2LIT[rowbit4], LEDS2LIT[rowbit3],LEDS2LIT[rowbit2],LEDS2LIT[rowbit1],LEDS2LIT[rowbit0]}; always @(posedge CLK) begin whole_cycle <= whole_cycle+1; // Wraps around, eventually. BCOL_IN_S <= BCOL_IN; // Synchronized input. if(kuu) begin PIECES[rowbit0] <= ~BCOL_IN_S[0]; PIECES[rowbit1] <= ~BCOL_IN_S[1]; PIECES[rowbit2] <= ~BCOL_IN_S[2]; PIECES[rowbit3] <= ~BCOL_IN_S[3]; PIECES[rowbit4] <= ~BCOL_IN_S[4]; PIECES[rowbit5] <= ~BCOL_IN_S[5]; PIECES[rowbit6] <= ~BCOL_IN_S[6]; PIECES[rowbit7] <= ~BCOL_IN_S[7]; end if(0 == row_period) // Time to switch to the next row? sel_row <= {sel_row[6],sel_row[5],sel_row[4],sel_row[3],sel_row[2],sel_row[1],sel_row[0],sel_row[7]}; end endmodule