Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What's wrong with the verilog code?

Status
Not open for further replies.

corgan

Member level 3
Joined
Jan 15, 2002
Messages
55
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
319
I would like to design a first order IIR high filter with equeation y[n] = x[n] - x[n-1] + a * y[n-1]
I wrote the following verilog code, but the result is not correct . Can any one tell me why?


input wire signed [15:0] Xn,
output reg signed [16:0] Yn,

parameter a = 0.9;

reg signed [15:0] Xn-1;
wire signed [16:0] diff = Xn-Xn-1;

always @(posedge clk or negedge reset) begin
if (reset) begin
Xn-1 <= 0;
Yn <= 0;
end
else begin
Xn-1 <= Xn;
Yn <= diff + a*Yn;
end
end
 

You need to update the diff = xn-xn-1 in the process instead of at the declaration.
 

CDRCDR said:
You need to update the diff = xn-xn-1 in the process instead of at the declaration.

Xn-1 is updated every cycle. diff is updated every cycle too.
It's not necessary to put diff in the always block.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top