Sar

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

module sar(clk,rst,d0,d1,d2,d3);

input clk,rst;
output d0,d1,d2,d3;
reg d0,d1,d2,d3;
integer i;
initial
begin
i=3;
d0 = 1'b0;
d1=1'b0;
d2=1'b0;
d3=1'b0;
end
always @(posedge clk)
begin
if(i==3)
begin
if(rst ==1'b0)
d3 = 1'b0;
else
d3 =1'b1;
i=i-1;
end
else if (i==2)
begin
if(rst==1'b0)
d2 = 1'b0;
else
d2 = 1'b1;
i=i-1;
end
else if(i==1)
begin
if(rst ==1'b0)
d1 = 1'b0;
else
d1 =1'b1;
i=i-1;
end
else
begin
if(rst == 1'b0)
d0 =1'b0;
else
d0 =- 1'b1;
i=3;
end
end
endmodule

You might also like