Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me fix a Verilog code for using switch with a clock

Status
Not open for further replies.

alierossi

Newbie level 6
Joined
Dec 7, 2009
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
malaysia
Activity points
1,375
verilog problem..

can you correct my code... i dont how to use switch with the clock. so that when i on the swicth the clock start j is start counting. plez help me.

module counter(
output reg [7:0] keluar,
input clk,
input switch,
);

// reg [5:0] result = 6'b000000;
reg en = 1'b0;
reg [2:0]i = 0;
integer j= 0;



always @ ( posedge clk)

begin

j <= j + 1;
if (j == 13'd4999)
begin
en <= 1'b1;
j <= 0;
end
else
en <= 1'b0;

end

always @ ( posedge en )

begin
i <= i + 1;
end

always @ (clk,i)

begin
keluar <= 8'b00000000;
case (i)

0 : keluar <= 8'b00000000;
1 : keluar <= 8'b00000001;
2 : keluar <= 8'b00000100;
3 : keluar <= 8'b00001010;
4 : keluar <= 8'b00010010;
5 : keluar <= 8'b00100010;
6 : keluar <= 8'b01000010;
7 : keluar <= 8'b11000010;


default:keluar<=8'bzzzzzzzz;
endcase


//assign keluar = result;
end

endmodule
 

Re: verilog problem..

i dont know what you are trying to do .... but your code seems almost incorrect in terms of synthesis..... you have multiple assignments of same registers in different blocks.... try to explain me more about your code so you might get helped

Regards

Ali Umair
 

Re: verilog problem..

you have multiple assignments of same registers in different blocks
I don't see a violation of Verilog rules. I don't understand however why the i counter is clocked by a ripple clock instead
of including it in the clk edge sensitive block.

The design can be expected to produce output data. But it's not clear what you try to achieve or what you're missing.
 

verilog problem..

Is there a reason why you are mixing edge sensitive clk and level sensitive clk?

As others have said, please explain in more detail what your code does, the expected results, and the results you are getting.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top