Forum Discussion
Altera_Forum
Honored Contributor
15 years agoBinary to Binary coded deicmal help
Hi guys,
I'm having trouble implementing a double dabble algorithm in verilog. These modules are supposed to produce 8bit BCD output from 5bit binary input. However, it seems like the binary goes through unchanged! Which I assume means +3 never happens... But why? Any ideas? Thanks in advance, the code I've got so far is below.module bcd(binary, bcd);
input binary;
output bcd;
wire w0,w1,w2,w3;
assign w0 = binary;
add3 (.in(w0<<3), .out(w1));
add3 (.in(w1<<1), .out(w2));
add3 (.in(w2<<1), .out(w3));
assign bcd = w3;
endmodule
module add3( in, out);
input in;
output out;
reg out;
always@(in)
begin
out = in;
if(in>4) out = out + 3;
if(in>4) out = out + 3;
end
endmodule14 Replies
- Altera_Forum
Honored Contributor
Don't know where you get the algorithm, but it seems not to do what it should. Check with pencil and paper! Perhaps you can give a numerical example of what you want to achieve.
There should be no principle problem to implement the algorithm completely asynchronously. - Altera_Forum
Honored Contributor
if you just insert clock only in add3:
always @ (posedge clock) ... than that should register the signal assignments and should be ok to make your design synchronous. The clock must be available as input if you are testing actual hardware. - Altera_Forum
Honored Contributor
--- Quote Start --- Just a wild gues. Your design is without clock (asynchronous) and could be running into logic hazards. --- Quote End --- I tried adding a clock to the sensitivity list in "add3". That didn't help, or did I do it wrong? - Altera_Forum
Honored Contributor
Just a wild gues. Your design is without clock (asynchronous) and could be running into logic hazards.