Clock divider-verilog codes
Clock divider-verilog codes
output [3:0]q;
Reg[3:0]q=4’b0;
Reg newclk;
Reg[27:0]count=0;
always@(posedge clk)
begin
count=count+1;
end
always@(posedge newclk)
begin
if(rst)
q=0;
else
end
endmodule
Input jk [1:0];
Output q,qb;
Reg newclk;
Reg[27:0]count=0;
always@(posedge clk)
begin
count=count+1;
end
initial
begin
q=1’b0; q=1’b1;
end
always@(posedge newclk) // new clk corresponds to 2 hz used for jk flip flop operation
begin
if(rst)
q=0;
else
case(jk)
2’b00: q=q;
2’b01:q=0;
2’b10:q=1;
2’b11:q=0;
endcase
Qb=~q;
end
endmodule
Input t;
Input, clk;
Output q,qb;
Reg newclk;
Reg[27:0]count=0;
always@(posedge clk)
begin
count=count+1;
initial
begin
q=1’b0; q=1’b1;
end
always@(posedge newclk) // new clk corresponds to 2 hz used for T flip flop operation
begin
if(t=0)
q=0;
else
q=1;
end
qb=~t;
endmodule
Output q;
Output reg[2:0]q;
Reg newclk;
Reg[27:0]count=0;
always@(posedge clk)
begin
count=count+1;
end
always@(posedge newclk) // new clk corresponds to 2 hz used for ripple counter operation
begin
q[0]=~q[0];
q[1]=~q[1];
q[2]=~q[2];
end
endmodule
Universal shift register to perform shift right, shift left, parallel and
load operation
Input [N-1:0]din;
Output reg[N-1:0]q;
Reg newclk;
Reg[27:0]count=0;
always@(posedge clk)
begin
count=count+1;
always@(posedge newclk or reset) // new clk corresponds to 2 hz used for shift register operation
if(!rst)
q={N{1’b0}};
else
case({s1,s0})
2’b00:q=q; // no change
endcase
endmodule