<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to J1939 TX signal conversion</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/ad6368cd3b/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/ad6368cd3b/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/ad6368cd3b/</id><updated>2020-02-27T22:11:25.328000Z</updated><subtitle>Recent posts to J1939 TX signal conversion</subtitle><entry><title>J1939 TX signal conversion</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/ad6368cd3b/?limit=25#aad6" rel="alternate"/><published>2020-02-27T22:11:25.328000Z</published><updated>2020-02-27T22:11:25.328000Z</updated><author><name>sgronchi</name><uri>https://forge.codesys.com/u/sgronchi/</uri></author><id>https://forge.codesys.com790f2087777a9abb0a6f2d4f19edbb0c32f2da4a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;And if you set "Raw data type" (a.k.a. on the wire) as "Unsigned" and set "Offset" as -180?&lt;br/&gt;
It is also more idiomatic (by the J1939 standard, all quantities on the wire are, or at least should be, unsigned).&lt;br/&gt;
By the way, if it is an angle, have you checked the standard angle scalings? There is SAEad04 which uses two bytes, 1/128 deg/bit, and offset -200, for a total range of -200 .. +301.99 degrees.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>J1939 TX signal conversion</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/ad6368cd3b/?limit=25#519d" rel="alternate"/><published>2020-02-27T22:11:23.791000Z</published><updated>2020-02-27T22:11:23.791000Z</updated><author><name>i-campbell</name><uri>https://forge.codesys.com/u/i-campbell/</uri></author><id>https://forge.codesys.coma48589cdb408a3d158c8c33bd46f4ca5d56eee81</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hmm, it is clear you have a 12bit 2's compliment signed integer, whose data is stored in 16 bit 2's compliment signed integer.&lt;/p&gt;
&lt;p&gt;You can write a FUNCTION to convert the two data types.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;FUNCTION&lt;/span&gt; &lt;span class="nv"&gt;SIGNED12_TO_INT&lt;/span&gt; : &lt;span class="nv"&gt;INT&lt;/span&gt;
&lt;span class="nv"&gt;VAR_INPUT&lt;/span&gt;
    &lt;span class="nv"&gt;Signed12&lt;/span&gt; : &lt;span class="nv"&gt;INT&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="nv"&gt;Bit&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;already&lt;/span&gt; &lt;span class="nv"&gt;on&lt;/span&gt;, &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="nv"&gt;we&lt;/span&gt; &lt;span class="nv"&gt;know&lt;/span&gt; &lt;span class="nv"&gt;it&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;negative&lt;/span&gt; &lt;span class="nv"&gt;number&lt;/span&gt; &lt;span class="nv"&gt;and&lt;/span&gt; &lt;span class="nv"&gt;must&lt;/span&gt; &lt;span class="nv"&gt;convert&lt;/span&gt;
&lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="nv"&gt;Signed12&lt;/span&gt;.&lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
    &lt;span class="nv"&gt;SIGNED12_TO_INT&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;TO_INT&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;TO_UINT&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Signed12&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;OR&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;#&lt;span class="nv"&gt;F000&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;; //SET the highest 4 bits&lt;/span&gt;
&lt;span class="k"&gt;ELSE&lt;/span&gt;
    &lt;span class="nv"&gt;SIGNED12_TO_INT&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;Signed12&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_IF&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>J1939 TX signal conversion</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/ad6368cd3b/?limit=25#33df" rel="alternate"/><published>2020-02-27T22:11:19.493000Z</published><updated>2020-02-27T22:11:19.493000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com74401ac0b489154ff962d3374917719033a16fd9</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; palej&lt;/p&gt;
&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am sending broadcast message and within PGN there is 12 bit signal  (Codesys 3.5 SP11+ 32 bit) with conversion info:&lt;br/&gt;
Conversion: TRUE&lt;br/&gt;
Raw data type: Signed&lt;br/&gt;
Byte order: Little endian&lt;br/&gt;
Scaling 1&lt;br/&gt;
Offset 0&lt;br/&gt;
IEC datatype: INT&lt;br/&gt;
(min and max values are -180 to 180)&lt;br/&gt;
And when "online" the value is e.g. -175.&lt;/p&gt;
&lt;p&gt;When I am reading that CAN message from other controller and I am watching it Online, the values coming are fine for 0..+180 (same 0..+180), but negative values from -1 to -180 are 3917 to 4095 ?? It's like the Signed is not working?&lt;/p&gt;
&lt;p&gt;The "reading" controller PGN signal conversions are same :&lt;br/&gt;
Conversion: TRUE&lt;br/&gt;
Raw data type: Signed&lt;br/&gt;
Byte order: Little endian&lt;br/&gt;
Scaling 1&lt;br/&gt;
Offset 0&lt;br/&gt;
IEC datatype: INT&lt;/p&gt;
&lt;p&gt;"Reading" controller is with Codesys 3.5 SP15 Patch 1 + (64 Bit)&lt;/p&gt;
&lt;p&gt;Why the value is like it's Unsigned UINT? What I am doing wrong or is it a bug?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>