Logic Machine Forum
Changing negative value to zero - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Changing negative value to zero (/showthread.php?tid=3397)



Changing negative value to zero - RagingBull - 02.06.2021

Hi,

I have a variable that can range from 40...-10 and I'd like to make a script with the FB editor that checks if the value goes to below zero, and when it does I'll rewrite it to 0. I tried using the 'less than' block comparing the value to 0 but with no luck. Is there any easy IF type of block I could import to the fb editor or any other suggestions how to go around?


RE: Changing negative value to zero - admin - 02.06.2021

Use maximum function:
   


RE: Changing negative value to zero - RagingBull - 02.06.2021

Thanks for a quick advice.

The variable (modbus register) my heatpump is calculating is degree minutes for my cooling system. So it calculates positive values when the temperature in my buffer tank is above my setpoint and the cooling activation treshold is 10 DM. Highest DM it calculates is 40 and lowest is -10. I basically want to get rid of the negative DM's so I can get my cooling cycle to start earlier.

So I put the same address for the input and the output, but it didn't work. (tried both 5sec timer and event) It's a mystery to me what happens but after I activate the script the seems like the heatpump isn't able to write the new variable which it calculates and the script overwrites the variable with the last value so it doesn't change. Even after I deactivate the script it does something odd very long until it recovers.

   

Here is a log of the variable and at this page the script is already been deactivated. It seems the heatpump tries to overwrite the next calculated value which is 3, but the script somehow stays with the 2. When the heatpump tries to write the value 10, my cooling cycle starts and after it I think the system recovers from the script somehow and now the heatpump can write reasonable values to variable.

Any advice on that? Do I need to make the timer time longer or do I need some kind of middle step where I compare the output of the maximum value and the modbus register and only rewrite it if they differ?


RE: Changing negative value to zero - admin - 02.06.2021

You must use a different object for the output. Right now you've created an infinite loop.


RE: Changing negative value to zero - RagingBull - 02.06.2021

How can I do that when the the modbus register is the same where I read the data which my heatpump calculates and where I should write the corrected value?


RE: Changing negative value to zero - Daniel - 02.06.2021

You can't do it this way. Your heat pump should have dedicated object for this. Feadback as status and control object.


RE: Changing negative value to zero - RagingBull - 02.06.2021

With this arrangement I can delay the message a bit, but it still messes a bit with the DM calculation of the heatpump because the delay can only be set to 60sec. Is there any way that I can prevent the data being sent to bus when the DM gets above 0 or run this script only when the DM is below zero?

   


RE: Changing negative value to zero - admin - 02.06.2021

If you don't want to use a separate object then you need to read the Modbus register via a script and do the conversion before writing to the object. But that's a lot more complicated than using a separate object.