P
Paul
Guest
Hi
I've been coding a rs-232 rx/tx module. after 3 days, I've finally
track down a weird bug. May be someone here can help explain this.
input RXD; reg RXD_r;
output [7:0] din; reg [7:0] din_r;
reg [7:0] step;
always @(posedge clk) begin
RXD_r<=~RXD;
.....
.....
din_r<=din_r+(1<<(step-1))*(~RXD_r); // bugged version
din_r[step-1]<=(~RXD_r); // finally the correct
version
In the bugged version, "din_r" always return "2" bigger than what was
actually sent. (note: for both versions, din_r was properly at "0"
before each byte was sampled. so it's not that din_r was not properly
zeroed out. the two versions have only the one line difference.)
Although my module is working, I still can't explain why...
Thanks
I've been coding a rs-232 rx/tx module. after 3 days, I've finally
track down a weird bug. May be someone here can help explain this.
input RXD; reg RXD_r;
output [7:0] din; reg [7:0] din_r;
reg [7:0] step;
always @(posedge clk) begin
RXD_r<=~RXD;
.....
.....
din_r<=din_r+(1<<(step-1))*(~RXD_r); // bugged version
din_r[step-1]<=(~RXD_r); // finally the correct
version
In the bugged version, "din_r" always return "2" bigger than what was
actually sent. (note: for both versions, din_r was properly at "0"
before each byte was sampled. so it's not that din_r was not properly
zeroed out. the two versions have only the one line difference.)
Although my module is working, I still can't explain why...
Thanks