J1939 TX signal conversion

Anonymous
2020-01-22
2020-01-24
  • Anonymous - 2020-01-22

    Originally created by: palej

    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?

     
  • i-campbell

    i-campbell - 2020-01-23

    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.

    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;
    
     
  • sgronchi - 2020-01-24

    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.

     

Log in to post a comment.