1
\$\begingroup\$

I am having a problem here can't make this code compile. It is a 4x4 keypad scanner with a 20ms debouncer. It gives error "Error: 'col' has not been declared" Any suggestion?

module keyboardScanner (input clk, input wait20, ,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;
reg start = 0;
//state register
always@(posedge clk) begin
 state <= nextState;
end
//output CL
always@(posedge clk) begin
 if(start == 0)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;
 endcase
 end
 if (col != 4'b0000)
 start = 1;
 if ((col != 4'b0000) && (wait20 == 1) && (start == 0)) begin
 keyCode <= {row[1],row[2],row[3],row[0], col[0],col[1],col[2],col[3]};
 start = 0;
 end
end
//next state CL
always @(posedge clk) begin
 if(start == 0)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;
 endcase
 end
end
endmodule
asked Nov 8, 2015 at 22:42
\$\endgroup\$
7
  • 1
    \$\begingroup\$ You have an extra comma (,) in your module declaration just before where the col input is declared. If you wrote it out neatly with each input/output on its own line rather than mushing everything up into one line, this would be obvious. Neat code = easy debug. \$\endgroup\$ Commented Nov 8, 2015 at 22:52
  • \$\begingroup\$ Thank you very much. I am really tired of designing FSMs and coding. Thanks a lot. It helped me! :D \$\endgroup\$ Commented Nov 8, 2015 at 22:56
  • 2
    \$\begingroup\$ Possible duplicate of 4x4 keyboard matrix not generating unique keycodes \$\endgroup\$ Commented Nov 8, 2015 at 23:29
  • \$\begingroup\$ As in your last question: what device/keypad do you use? My research shows that you must swap the pin directions of columns and rows. \$\endgroup\$ Commented Nov 8, 2015 at 23:32
  • \$\begingroup\$ @Paebbels I am using basys2 fpga. Why should I do that? It's the same thing. \$\endgroup\$ Commented Nov 9, 2015 at 0:04

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.