This code isn't going to work.
I think you need to find a non-antiquated tutorial. It is the end of 2016 and Verilog 2001 came out over 15 year ago...you can use C style module port syntax...it works on every single tool I've used in the past 5+ years.
Your reset code should not be implemented in a separate always block this will likely result in multiple driver errors.
you never assign next_state to state, you have a always block running off of the posedge of rst (do you expect rst to be a clock?) Oh wait I see you've got a backward way of describing the two always block FSM (you are assigning the next_state register with the current state value, which isn't from a FF, this is completely backward from the standard naming conventions, better go reread you antiquated tutorial site). Opinions vary but I am on the side of don't do this, use a single process/always block FSM style. The best reason for using the two process/always style was ancient tools were really bad at extracting FSMs that were written in a single clocked process/always. But as it is now 2016 and there are no ancient versions of synopsys dc being used it won't be problem (back in the early 90's it was sometimes a problem in our VHDL FSM code, so we always used two process FSMs). Your FSM though doesn't comply with any known one/two/three process/always FSM style, so the synthesis will probably generate garbage.
$display is not synthesizable, so don't use it in your code.
Your
always @ (posedge clk) begin is missing an end to finish off the always block. Easy to do with lousy formatting of code.
You have a missing endcase for the case(coin) statement.
- - - Updated - - -
Why do you need a 2D array for the product, it doesn't make sense to me.
I'm assuming the A, B, C, D are the products so why is there an array for each product (16 dispensable items per product)?
If you have four of each product you only need a 1D array for each product.
Maybe you were supposed to implement a 2D array of the_products:
Code Verilog - [expand] |
1
2
| reg [3:0] the_products [0:3] // [3:0] => four of the product that can be bought,
// [0:3] => 4 total types of product (instead of A-D) |