DSP "Not Equal To" not acting consistant? (plus help)

DSP related issues, mathematics, processing and techniques
Post Reply
User avatar
aronb
Posts: 154
Joined: Sun Apr 17, 2011 3:08 am
Location: Florida, USA
Contact:

DSP "Not Equal To" not acting consistant? (plus help)

Post by aronb »

Hi,

I cannot get the DSP "Not Equal To" working.

I have 2 signals which start off unequal and become equal, and yet the output of the DSP "Not Equal To" operator (!=) is incorrect, as far as I can tell in one DSP Code module, but working in another :?

I have been looking at this way toooooo long :oops:

Here is the FSM, can someone please take a look?
Ramp_Help_01.fsm
"Not Equal To" issue?
(78.02 KiB) Downloaded 1437 times

Also, can someone help me solve my other needs, which again I cannot seem to figure out - mainly how to initialize the ramp value to 1, after the trigger occurs (only), that way the ramp can count down (NOTE: the ramp resting / final value must be 0, so I cannot change it at the end of the function), and since it is after a trigger, I cannot use stage(0) :(

Thank you,

Aron
User avatar
Spogg
Posts: 3368
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England
Contact:

Re: DSP "Not Equal To" not acting consistant? (plus help)

Post by Spogg »

Hi Aron

This needs a greater mind than mine to explain, but it appears to be the way the != operator deals with bools.

I’ve changed the test1 output evaluation to take this into account. You can now get the pulse at the start and the end from test1 output.

Also I changed your demo DSP box to illustrate the situation. If either bool is true it works but if both are true it doesn’t, and you still get an “incorrect” output of 1 in this situation.

Maybe Martin can explain the proper way to compare bools in DSP and why we get this counterintuitive behaviour. I'm sure he could help with the other points too.

Cheers

Spogg
Attachments
Ramp_Help_01-1 spogged 1 .fsm
(238.62 KiB) Downloaded 1388 times
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: DSP "Not Equal To" not acting consistant? (plus help)

Post by KG_is_back »

It's actually very simple. "=!" operator in DSP is specifically made to compare float in point NUMERIC values ie actual numbers. It behaves differently for nonnumeric values, which include +infinity, -infinity, various forms of NaN (Not a Number). Boolean true happens to be one of those values (boolean false happens to be identical to 0). If you want to compare boolean values using "=!" you should do something like this:

Code: Select all

result=(boolX & 1) != (boolY & 1);

This will ensure that you always compare numbers, instead of some weird non-numeric values that boolean variables can acquire.

Also another tip: Don't use streamboolean. Its behaviour is very incosistent - it is pretty much identical to stream except the connector restrictions (which you can override by holding ctrl). This is especially confuising when connecting green booleans to stream. green bool true value actually gets converted to float value 1 when connected to stream boolean, instead of the expected "true" value.
Post Reply