CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Wed Feb 19, 2020 7:48 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Jan 22, 2020 9:32 am 
Offline

Joined: Wed Oct 31, 2018 6:57 pm
Posts: 10
Hi,

I am sending broadcast message and within PGN there is 12 bit signal (Codesys 3.5 SP11+ 32 bit) with conversion info:
Conversion: TRUE
Raw data type: Signed
Byte order: Little endian
Scaling 1
Offset 0
IEC datatype: INT
(min and max values are -180 to 180)
And when "online" the value is e.g. -175.

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?

The "reading" controller PGN signal conversions are same :
Conversion: TRUE
Raw data type: Signed
Byte order: Little endian
Scaling 1
Offset 0
IEC datatype: INT

"Reading" controller is with Codesys 3.5 SP15 Patch 1 + (64 Bit)

Why the value is like it's Unsigned UINT? What I am doing wrong or is it a bug?


Top
   
PostPosted: Thu Jan 23, 2020 11:10 pm 
Offline

Joined: Tue Mar 26, 2019 4:28 pm
Posts: 91
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.

You can write a FUNCTION to convert the two data types.

Code:
FUNCTION SIGNED12_TO_INT : INT
VAR_INPUT
    Signed12 : INT;
END_VAR

//IF Bit 12 is already on, then we know it is a negative number and must convert
IF Signed12.12 THEN
    SIGNED12_TO_INT := TO_INT(TO_UINT(Signed12) OR 16#F000); //SET the highest 4 bits
ELSE
    SIGNED12_TO_INT := Signed12;
END_IF;


Top
   
PostPosted: Fri Jan 24, 2020 2:03 pm 
Offline

Joined: Wed Jan 08, 2020 1:50 pm
Posts: 19
And if you set "Raw data type" (a.k.a. on the wire) as "Unsigned" and set "Offset" as -180?
It is also more idiomatic (by the J1939 standard, all quantities on the wire are, or at least should be, unsigned).
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.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 3 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited