I'm reaching my wits end trying to figure out why the simulated output is all X's. From looking up verilog issues all over the web it appears to me that most issues stem from reg vs wire mishaps however if feel it may still be the root of my woes.
If anyone could please tell what I'm doing wrong writing my module and the module's test bench it would be VERY appreciated.
The module is of piggy bank that increments it's credits in terms of coins or removes credits in terms of items purchased. I'm using an 8 bit accumulator.
The test bench is far from complete but I was just trying to get something besides "x"'s to no avail. Thanks again for you help.
module piggyBank(clk, reset, penny, nickel, dime, quarter, apple, banana, carrot, date, credit);
input clk, reset, penny, nickel, dime, quarter;
input apple, banana, carrot, date;
output [7:0] credit;
reg [7:0] tmp;
always @(posedge clk or posedge reset)
begin
if (reset)
tmp = 8'b00000000;
if (penny || nickel || dime || quarter)
tmp = tmp + penny + (5 * nickel) + (10 * dime) + (25 * quarter);
if (apple || banana || carrot || date)
tmp = tmp - (apple * 75) - (20 * banana) - (30 * carrot) - (40 * date);
end
assign credit = tmp;
endmodule
module testPiggyB();
reg clk;
reg reset, penny, nickel, dime, quarter;
reg apple, banana, carrot, date;
wire [7:0] credit;
initial begin
clk <= 0;
forever #5 clk <= ~clk;
reset <= 0;
penny <= 0; nickel <= 0; dime <= 0; quarter <= 0;
apple <= 0; banana <= 0; carrot <= 0; date <= 0;
#5quarter <= 1;
#40 quarter <= 0;
end
piggyBank pb(.clk(clk), .reset(reset), .penny(penny) ,.nickel(nickel), .dime(dime), .quarter(quarter), .apple(apple), .banana(banana), .carrot(carrot), .date(date), .credit(credit));
endmodule
Have you looked at the inputs to your simulation to make sure they are being toggled as you expect?
Your piggyBank module seems ok, but I guess that your testbench may not be advancing beyond the forever clock statement, as it will keep executing this line forever and not advance beyond to the below statements. Therefore the quarter is never entered, and the module stays in it's unreset/unmodified state forever.
Try putting the clock into a separate initial block.
initial begin
clk = 0;
forever #5 clk = ~clk;
end
Also you never seem to assert the reset.
Finally, you seem to be mixing up the blocking and nonblocking statements, though it shouldn't be fatal to the simulation in your case. Generally you would want your flip-flop to be using nonblocking assignments (<=), and your testbench sequential code to use blocking assignments (=).