Friday 21 October 2016

verilog - 4x4 keyboard matrix not generating unique keycodes


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;
end

//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;
endcase
if (col != 4'b0000) begin
keyCode <= {row[0],row[1],row[2],row[3], col[0],col[1],col[2],col[3]};

end
end

//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;
endcase
end

endmodule

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



Answer



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


No comments:

Post a Comment

arduino - Can I use TI&#39;s cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...