Constraint

Hi,

I have two block, lets A and B. And block A output prog_out[7:0] is connected to B block input prog_in[7:0] so i do not have control over prog_in.

I Created the top_level (block A + Block B).

class transaction;
  rand bit[7:0] prog_trim; // another input to block A and B (i.e input to top level)
  bit [7:0] prog_out; // output of block A
  rand bit [3:0]   step      ;  // input to top_level

constraint c_prog_trim_value {
                               prog_trim <=(prog_out -  step) ; }
   
endclass

I have written a constraint so that prog_trim should have always less then (prog_trim-step).
prog_trim <=(prog_out - step).

But I am not getting the expected result (i can see prog_trim is greater then (prog_out -step))

Could anyone help me here ?

In reply to rkg_:

It would really help to show a complete example showing the behavior you are seeing.

Did you account for overflow conditions?

In reply to cgales:

Hi,

Thanks for replying.
Did you account for overflow conditions? → No
I have tried to keep my short design and transaction code into edaplayground site.

Design (Block B) has limitation it will only generate the desired output only when
prog_trim <=(prog_out_fll - freq_dec_step).

Thus I am trying to write constraint to generate the prog_trim value as per the above specification.

Edit code - EDA Playground.

The problem here is prog_out_fll is the output of block A so how can we retrieve the value of prog_out_fll in transaction class during constraint writing?

In reply to rkg_:

The example you posted doesn’t compile. It’s difficult to give assistance when you don’t provide all of the information concerning what you are currently doing.

It seems like you are trying to randomize a class with a set of constraints. One of the inputs seems to be an output from a design block. Since the class doesn’t connect to signals, you need to provide this when calling randomize.

You can either set the value of prog_out prior to calling randomize(), or make prog_out a random variable and use the ‘with’ statement to constrain it when the randomize() call is made.

In reply to cgales:

Thank you for reply.

I believe, your hint will work for me.