<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to INT_TO_WORD function not working</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/89918642cc/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/89918642cc/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/89918642cc/</id><updated>2024-01-26T11:42:17.847000Z</updated><subtitle>Recent posts to INT_TO_WORD function not working</subtitle><entry><title>INT_TO_WORD function not working</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/89918642cc/?limit=25#beb0" rel="alternate"/><published>2024-01-26T11:42:17.847000Z</published><updated>2024-01-26T11:42:17.847000Z</updated><author><name>Wiresplus</name><uri>https://forge.codesys.com/u/wiresplus/</uri></author><id>https://forge.codesys.com8f8db9037ae73f77c2a8759f7eeb86ed0164ae75</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;OK! PSA for others:&lt;/p&gt;
&lt;p&gt;Data type INT fails because it has no decimal places, and using it in the math when it is any value below 1 simply returns 0. As it will always calculate to 0.xxx in the first part of the math, only the 0 without any decimal places is passed to the second part of the math - and anything multiplied by 0 is 0!&lt;/p&gt;
&lt;p&gt;I changed PumpFillSpeed to REAL, and then used REAL_TO_WORD. &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>INT_TO_WORD function not working</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/89918642cc/?limit=25#85ed" rel="alternate"/><published>2024-01-26T07:33:31.368000Z</published><updated>2024-01-26T07:33:31.368000Z</updated><author><name>ojz0r</name><uri>https://forge.codesys.com/u/ojz0r/</uri></author><id>https://forge.codesys.com484ca915789e423c783e59b075e7ef777dfdf841</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;That calculation will not work the way you expect it to. If PumpFillSpeed is limitied to 0-50 then the only whole number would be 50/50 = 1 everything else is 0.0-0.9999... and since you are using word and integer only 50 would work since there is no representation for mantissa in integer values. Declare a temporary real variable and do the calculation and then do a REAL_TO_WORD in the DRV2Speed assignment.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>INT_TO_WORD function not working</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/89918642cc/?limit=25#c5ff" rel="alternate"/><published>2024-01-26T03:42:15.387000Z</published><updated>2024-01-26T03:42:15.387000Z</updated><author><name>Wiresplus</name><uri>https://forge.codesys.com/u/wiresplus/</uri></author><id>https://forge.codesys.com26131459da957075d3dcdbd6c885f6b7768432fb</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I need to take an INT input, and convert it to a WORD value.&lt;/p&gt;
&lt;p&gt;VAR&lt;br/&gt;
DRV2Speed : WORD; //IO card takes a WORD where 16000 = full 10V output (equivalent to 50Hz)&lt;br/&gt;
PumpFillSpeed : INT; //Users enter a value between 0 and 50&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;IF &amp;lt;conditions&amp;gt; THEN&lt;br/&gt;
    DRV2Speed :=INT_TO_WORD((PumpFillSpeed/50)*16000);&lt;br/&gt;
END_IF &amp;lt;/conditions&amp;gt;&lt;/p&gt;
&lt;p&gt;According to me this should work  - but it stays at 0, no matter what.&lt;/p&gt;
&lt;p&gt;What am I doing wrong?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>