Forum Discussion
Altera_Forum
Honored Contributor
14 years ago --- Quote Start --- Just noticed you are adding 3 to ones yet the code adds 3 to all in bits. Shouldn't you say: if in(8:5) > 4 out(8:5) = out(8:5)+3; as the tens --- Quote End --- Oh my, I can;t believe I didn't spot that in two days! It's working much better now. Still not working great but I can work on that in the morning. Thanks so much! Update: I removed the final add3 now it works perfectly. Here's the final code in working order.
module bcd(in, out);
input in;
output out;
wire w0,w1,w2,w3;
assign w0 = in;
add3 (.in(w0<<3), .out(w1));
add3 (.in(w1<<1), .out(w2));
assign w3 = w2 << 1;
assign out = w3;
endmodule module add3(in, out);
input in;
output out;
reg out;
always@(*)
begin
out = in;
if(in>4) out = in + 3;
if(in>4) out = in + 3;
end
endmodule