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.

implementing equations

Status
Not open for further replies.

pritin

Newbie level 3
Newbie level 3
Joined
Feb 15, 2006
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,307
how to implement the following function in verilog

Δ = clip ( -c , c , ((q0-p0)<<2 + (p1-q1)+4)>>3)
where clip(a,b,c) is a clipping function that clips c to a value b/w a and b.
 

Your equation is somewhat unclear, needs more parenthesis.
You didn't say what type variables those are. I'll assume 16-bit signed values.

How about this?
Code:
module top (c, p0, q0, p1, q1, delta);
  input signed   [15:0] c, p0, q0, p1, q1;
  wire signed    [15:0] temp;
  output signed  [15:0] delta;

  assign temp = (((q0 - p0 + 0) <<< 2) + p1 - q1 + 4) >>> 3;
  assign delta = (temp < -c) ? -c : (temp > c) ? c : temp;
endmodule
Or maybe this:
Code:
module top (c, p0, q0, p1, q1, delta);
  input signed   [15:0] c, p0, q0, p1, q1;
  output signed  [15:0] delta;

  function signed [15:0] clip;
    input signed [15:0] a, b, c;
    clip = (c < a) ? a : (c > b) ? b : c;
  endfunction

  assign delta = clip(-c, c, (((q0 - p0 + 0) <<< 2) + p1 - q1 + 4) >>> 3);
endmodule
Beware, hastily-written and untested!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top