antlhem
Member level 1
Hello, I need some help on pressing a button to select a number, but only when I press the button (negedge), the button can be pressed long time with no more changes on the number selected. So far what I get is that when I press the button for 4 clk cycles (in the simulator) it immediately select 4 numbers, or verilog (Quartus 13) assumes that the button is activated always and automatically select the for numbers. What I need is to select the number only when I press the button. The code is the following:
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 module num_selec(clk, select, num, led); input wire clk, select; input wire [6:0] num; output reg led; reg [6:0] a = 7'd10, b = 7'd10, c = 7'd10, d = 7'd10; reg [6:0] a2 = 7'd10, b2 = 7'd10, c2 = 7'd10, d2 = 7'd10; reg [27:0] y, y2; reg [6:0] num2 [3:0]; reg [2:0] i = 3'd0; reg select2 = 1'b0; //code in this question********** always @ (negedge select) if(!select) select2 <= 1'b1; else select2 <= 1'b0; //******************************* always @ (posedge clk) begin //when I put 'negedge select' it does nothing //still need to add rst y = {a,b,c,d}; y2 = {num2[0],num2[1],num2[2],num2[3]}; if(i==4) begin if(y == y2)//comparing two concatenated values led = 1'b1;//the numbers are the same else led = 1'b0;//not the same end else begin if(select2) begin //changed from select num2[i] <= num; i = i + 3'd1;//index register end end end endmodule
Last edited by a moderator: