I have a 4x4 keybord matrix fsm scanner but it generates only high keycode setting all last 4 bits to 1 and second and fourth digits to high. Is there anything wrong in my code here?

module keyboardScanner (input clk, input [3:0] col,output reg [3:0] row, output reg [7:0] keyCode);
reg [1:0]state=2'b00;
reg [1:0]nextState=2'b00;

//state register
always@(posedge clk) begin
    state <= nextState;

//output CL
always@(posedge clk) begin
    case (state)
    2'b00: row <= 4'b0001;
    2'b01: row <= 4'b0010;
    2'b10: row <= 4'b0100;
    2'b11: row <= 4'b1000;
    default: row <= 4'b0001;
    if (col != 4'b0000) begin
    keyCode <= {row[0],row[1],row[2],row[3], col[0],col[1],col[2],col[3]};

//next state CL
always @(posedge clk) begin
        case (state)
            2'b00: nextState <= 2'b01;
            2'b01: nextState <= 2'b10;
            2'b10: nextState <= 2'b11;
            2'b11: nextState <= 2'b00;
            default: nextState <= 2'b00;


Please help me. It used to work 2 days ago, but now... :/

  • \$\begingroup\$ Do you have any documentation or schematic for us? \$\endgroup\$
    – Paebbels
    Commented Nov 8, 2015 at 18:27
  • \$\begingroup\$ Are you using the Digilent keypad as a Pmod device? There is the possibiliy of floating inputs ... you should enable pullups in the FPGA's IOBs. \$\endgroup\$
    – Paebbels
    Commented Nov 8, 2015 at 20:43
  • \$\begingroup\$ I found the original Digilent example code for the 4×4 keypad. You have to drive column and read row! This prevents you from having floating inputs. \$\endgroup\$
    – Paebbels
    Commented Nov 8, 2015 at 21:06
  • \$\begingroup\$ Ok, I have found a board picture, but I can't find any schematic. Have a look at the Digilent PmodKYPD and its schematic. As you can see the columns have no pullup or pulldown resistor, whereas the rows have. That means columns have to be driven and rows to read. Please compare it to your beti board schematic. \$\endgroup\$
    – Paebbels
    Commented Nov 9, 2015 at 6:50
  • \$\begingroup\$ There is no resistor in either of them in beti board so its quite different. No matter if you choose row or col as driver it will be the same. Thanks for information, it will be helpful knowledge :) \$\endgroup\$
    – anon
    Commented Nov 9, 2015 at 11:55

1 Answer 1


I found the answer. It was a clock halt problem. Clock was grounded and it destroyed the thing. Now it works fine!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.