I would like to create a module that can change the value of a register passed to it (+/- 1) using an inout port. I wrote this:
module tune( input clk, input read, input [15:0] x, inout [15:0] y, input plus, input minus ); reg [15:0] a; reg [15:0] b; assign y = read ? a:'bz; always@(posedge clk) begin b<=y; a<=x; if (plus) b<=b+1; end endmodule
When read is HIGH, I expect y to be initialized to the value of x. When read is LOW, I expect to output the value of b (which can be decremented or incremented by using minus or plus). Currently however, plus does not do anything, and read toggles y between 0xFFFF and 2 (when I pass 2'd42 to x).
I admit I do not have a good grasp of non-blocking assignments. What should I change to make my code work, or is there a better way to implement the desired behavior?