Need some Help for VERILOG code

Status
Not open for further replies.

Adnan86

Full Member level 2
Joined
Apr 4, 2013
Messages
121
Helped
26
Reputation
52
Reaction score
26
Trophy points
1,308
Activity points
2,153
Hi
I write below code for define 4 type of address, the code work correctly. but I want something more to add.
I want to Reset signal (func), anytime that (func) change. In this code if I change func, (addr) will be change until reach 100. But I want to reset (addr), anytime (func) change.
thanks for consideration and giving your time.
Code:
always @ (posedge clk) begin
	if (rst)
		addr <= 0;
	else if (addr < 100)
		addr <= addr + 1;
	else
		addr <= 0;
end

// -- define wave
always @ (posedge clk ) begin
	case (func)
		2'b00 : begin			// sin wave
					addra <= addr + 0;
				  end
		2'b01 : begin			// square wave
					addra <= addr + 100;
				  end
		2'b10 : begin			// triangler wave
					addra <= addr + 200;
				  end
		2'b11 : begin			// sawtooth wave
					addra <= addr + 300;
				  end
		default : addra <= 0;
	endcase
 

how about this:

Code:
func_r <= func;

if (rst || ( func != func_r)) then
  addr <= 0;
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…