Page 1 of 1

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

PostPosted: Sun Jul 29, 2018 11:14 pm
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 1166 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

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

PostPosted: Mon Jul 30, 2018 10:43 am
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

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

PostPosted: Mon Jul 30, 2018 11:20 am
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.