The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Apr 24th, 2024, 2:21pm
Pages: 1
Send Topic Print
wreal: reaction to a signal change is not working properly (Read 4170 times)
Zorro
Community Member
***
Offline



Posts: 63

wreal: reaction to a signal change is not working properly
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.
Back to top
 
 
View Profile   IP Logged
Zorro
Community Member
***
Offline



Posts: 63

Re: wreal: reaction to a signal change is not working properly
Reply #1 - Sep 17th, 2015, 5:41am
 
Picture 1.
Back to top
 

response_to_iload_picture_1.PNG
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: wreal: reaction to a signal change is not working properly
Reply #2 - 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
Back to top
 
 
View Profile   IP Logged
Zorro
Community Member
***
Offline



Posts: 63

Re: wreal: reaction to a signal change is not working properly
Reply #3 - 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.
Back to top
 
 
View Profile   IP Logged
Zorro
Community Member
***
Offline



Posts: 63

Re: wreal: reaction to a signal change is not working properly
Reply #4 - Sep 17th, 2015, 11:00am
 
Picture 2.
Back to top
 

response_to_iload_picture_2.PNG
View Profile   IP Logged
Zorro
Community Member
***
Offline



Posts: 63

Re: wreal: reaction to a signal change is not working properly
Reply #5 - Sep 17th, 2015, 11:00am
 
Picture 3.
Back to top
 

response_to_iload_picture_3.PNG
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: wreal: reaction to a signal change is not working properly
Reply #6 - 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
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.