The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> wreal: reaction to a signal change is not working properly
https://designers-guide.org/forum/YaBB.pl?num=1442493664

Message started by Zorro on Sep 17th, 2015, 5:41am

Title: wreal: reaction to a signal change is not working properly
Post by Zorro on Sep 17th, 2015, 5:41am

Hi Community,

I am having a problem that I cannot understand.

This simulation uses wreal only.

I have 2 internal signals which should react to a variation in the signal iload.

If iload > value the response signal should be high, otherwise the response signal should be low.

Example 1 (working as expected)
I am varying iload in steps of 1m.
Let's say value=100m
If iload  is 100m or higher, then the response signal should be high
If iload is 99m or lower then the response signal should be low
-> this is working fine


The problem occurs if I use another "value", let's say value=50m

Example 2 (not working as expected)
I am varying iload in steps of 1m.
Let's say value=50m
If iload  is 50m or higher, then the response signal should be high
If iload is 49m or lower then the response signal should be low
-> this is not working fine. When iload decreases the response signal should become low when iload=49m, but this is ocurring when iload=50m and this is not correct


This is the code that I am using:

     real        high_current_overload;
     real      low_current_overload;
     
     always @(iload) begin
     
           if (iload >= 100m) begin
                 high_current_overload = 1.0;
           end else begin
                 high_current_overload = 0.0;
           end
     
     end      
     
     always @(iload) begin
     
           if (iload >= 50m) begin
                 low_current_overload = 1.0;
           end else begin
                 low_current_overload = 0.0;
           end
     
     end      

     
See Picture 1.

Please any suggestion to understand what is causing this problem?      

Thank you!

Zorro.

Title: Re: wreal: reaction to a signal change is not working properly
Post by Zorro on Sep 17th, 2015, 5:41am

Picture 1.

Title: Re: wreal: reaction to a signal change is not working properly
Post by boe on Sep 17th, 2015, 8:57am


Zorro wrote on Sep 17th, 2015, 5:41am:
Hi Community,
...
Example 2 (not working as expected)
I am varying iload in steps of 1m.
Let's say value=50m
If iload  is 50m or higher, then the response signal should be high
If iload is 49m or lower then the response signal should be low
-> this is not working fine. When iload decreases the response signal should become low when iload=49m, but this is ocurring when iload=50m and this is not correct
...
Please any suggestion to understand what is causing this problem?
Accumulation of numerical errors. I am sure your code will behave as expected if you use 49.995m as threshold.
- B O E

Title: Re: wreal: reaction to a signal change is not working properly
Post by Zorro on Sep 17th, 2015, 10:59am

Hi boe,

thanks for your reply.

Your suggestions partly solves the problem. To understand it properly could you please tell me what you mean when you say "Accumulation of numerical errors" ???

If I use value=49.995m as you suggests it works fine, as expected. See Picture 2.

But the question is: how do I know when I need to subtract that small delta from my threshold value???

As an example, if I use value=60m it works fine, without needing to subtract any delta. See Picture 3.

Thank you.

Zorro.

Title: Re: wreal: reaction to a signal change is not working properly
Post by Zorro on Sep 17th, 2015, 11:00am

Picture 2.

Title: Re: wreal: reaction to a signal change is not working properly
Post by Zorro on Sep 17th, 2015, 11:00am

Picture 3.

Title: Re: wreal: reaction to a signal change is not working properly
Post by boe on Sep 21st, 2015, 2:16am


Zorro wrote on Sep 17th, 2015, 10:59am:
Hi boe,

thanks for your reply.

Your suggestions partly solves the problem. To understand it properly could you please tell me what you mean when you say "Accumulation of numerical errors" ???

If I use value=49.995m as you suggests it works fine, as expected. See Picture 2.

But the question is: how do I know when I need to subtract that small delta from my threshold value???

As an example, if I use value=60m it works fine, without needing to subtract any delta. See Picture 3.

Thank you.

Zorro.
Zorro,
the simulator (usually) uses a binary representation for numbers, and the binary representation of 1m is infinite. Therefore, numerical errors occur and propagate through your calculation.
You may want to try the following (pseudo-)code

Code:
sum = 0
for i = 1 to 10000
  sum = sum + 1m
  print i, ": ", sum - 0.001*i

- B O E

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.