Monday, November 09, 2009

baud rate receiver

baud rate receiver

module rx(rxd, bclkx8, sysclk, rst, rdrf, rdr, setrdrf, setoe, setfe);

input rxd;

input bclkx8;

input sysclk;

input rst;

input rdrf;

output [7:0] rdr;

output setrdrf;

output setoe;

output setfe;

reg [1:0]state,nextstate;

reg [7:0] rsr,rdr;

reg [2:0]ct1;

reg[3:0]ct2;

reg clr1,clr2,inc1,inc2,loadrdr,shftrsr;

reg bclkx8dlayed;

reg setrdrf,setoe,setfe;

wire bclkrising;

assign bclkx8rising= bclkx8 & (~bclkx8dlayed);

always@(state,rxd,rdrf,ct1,ct2,bclkx8rising)

begin

inc1=1'b0;

inc2=1'b0;

clr1=1'b0;

clr2=1'b0;

shftrsr=1'b0;

loadrdr=1'b0;

setrdrf=1'b0;

setoe=1'b0;

setfe=1'b0;

case(state)

2'b00:begin

if(rxd==1'b0)

nextstate=2'b01;

else

nextstate=2'b00;

end

2'b01:begin

if(bclkrising==1'b0)

nextstate=2'b01;

else if(rxd==1'b1)

begin

clr1=1'b1;nextstate=2'b00;

end

else if(3'b011)

begin

clr1=1'b0;nextstate=2'b10;

end

else

begin

inc1=1'b1;nextstate=2'b01;

end

end

2'b10:begin

if(bclkrising==1'b0)

nextstate=2'b10;

else

begin

inc1=1'b1;

if(ct1!=3'b111)

nextstate=2'b10;

else if(ct2!=4'b1000)

begin

shftrsr=1'b1;inc2=1'b1;clr1=1'b1;

nextstate=2'b10;

end

else

begin

nextstate=2'b00;setrdrf=1'b1;

clr1=1'b1;

clr2=1'b1;

if(rdrf==1'b1)

setoe=1'b1;

else if(rxd==1'b0)

setfe=1'b1;

else

loadrdr=1'b1;

end

end

end

endcase

end

always@(posedge sysclk or negedge rst)

begin

if(!rst)

begin

state=2'b00; bclkx8dlayed=1'b0;

clr1=1'b0;

clr2=1'b0;

end

else

begin

state=nextstate;

if(clr1==1'b1)

ct1=1'b0;

else if(inc1==1'b1)

ct1=ct1+1'b1;

if(clr2==1'b1)

ct2=1'b0;

else if(inc2==1'b1)

ct2=ct2+1'b1;

if(shftrsr==1'b1)

rsr={rxd,rsr[7:1]};

if(loadrdr==1'b1)

rdr=rsr;

bclkx8dlayed=bclkx8;

end

end

endmodule

No comments:

Post a Comment

Popular Posts