Skip to content

Commit

Permalink
simplify charlieplexer
Browse files Browse the repository at this point in the history
  • Loading branch information
dpiegdon committed Aug 8, 2019
1 parent 297d0b0 commit f917d94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
22 changes: 4 additions & 18 deletions charlieplexer.v
Expand Up @@ -78,24 +78,10 @@ module charlieplexer(

function [INDEXBITS-1:0] LedIndex(input integer x, input integer y, input integer pinCount);
// Returns the index of the LED at grid-position x/y.
// This is a stupid solution, but I am not very versatile with
// verilog so far, so I did not really come up with a better
// solution.
integer ix, iy, stop;
begin
LedIndex = 0;
stop = 0;
for(ix = 0; ix < pinCount; ix++) begin
for(iy = 0; iy < pinCount; iy++) begin
if((ix != iy) && (stop == 0)) begin
if((x == ix) && (y == iy)) begin
stop = 1;
end else begin
LedIndex = LedIndex+1;
end
end
end
end
if(x > y) begin
LedIndex = (pinCount-1)*x + y;
end else begin
LedIndex = (pinCount-1)*x + y-1;
end
endfunction

Expand Down
2 changes: 1 addition & 1 deletion charlieplexer_tb.v
Expand Up @@ -21,7 +21,7 @@ along with verilog-buildingblocks. If not, see <https://www.gnu.org/licenses/>.

// testbench for charlieplexer.
module charlieplexer_tb();
localparam PINCOUNT=17;
localparam PINCOUNT=33;
localparam INDEXBITS=$clog2(PINCOUNT * (PINCOUNT-1));


Expand Down

0 comments on commit f917d94

Please sign in to comment.