[SOLVED] How to manipulate signals within certain time period in testbench in modelsim?

Status
Not open for further replies.

nervecell_23

Member level 1
Joined
Apr 26, 2013
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,565
For instance, I want to figure out how many times SignalA becomes active during 100ns and 200ns, instead of counting in the waveform, how to achieve it by HDL in the testbench?

I need to set up a counter first, then how to make it count only within a specified time period?

Thanks!
 

used this rising of falling edge of your signal as clock to increment your counter.

- - - Updated - - -

in verilog you could used variable $now to know when you could enable your counter.
 

Assuming your timescale is 1 ns in Verilog

Code:
integer counter;
initial begin
           count = 0;
           fork
            #100 begin : counter
                       forever @(posedge SignalA) count = count + 1;
                    end
            #200 disable counter;
          join
          $display("SignalA went high %0d times", count);
        end
This would be slightly easier in SystemVerilog which ModelSim does support
Code:
int counter;
initial begin
           count = 0;
           fork
            #100ns forever @(posedge SignalA) count++;
            #200ns;
          join_any
          disable fork;
          $display("SignalA went high %0d times", count);
        end
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…