Results 1 to 5 of 5

Thread: type conversion

  1. #1
    Join Date
    Jun 2015
    Location
    Netherlands
    Posts
    20

    Default type conversion

    Hi all,

    I am struggling with this. I want to multiply a INT (signed 16 bit) with an UINT (unsigned 16 bit), divide this by a CONSTANT and the result needs to go in a REAL.

    This is what I tried amongst many others but can't get it to work:

    r_nwv_weegplaat_1_kg := INT_TO_REAL (s16_weegplaat_1_netto * UINT_TO_INT(u16_weegplaat_1_omrekenfactor)) / 10000000;

    I am using a cr0401 and a cr0451. The above line is in the cr0401 and the REAL r_nwv_weegplaat_1_kg is sent to the display. If I set this variable to 12.34 with a constant I see that the display shows 12.34 just as expected. If I let the calculation set the value in the REAL variable than the result is jumpy by large numbers and also the sign changes from positive to negative and back. This value comes from an analogue input connected to a potmeter for now. I guess it is a problem with overload at some point because the type conversion is wrong.

    What am I doing wrong?

    Bert
    Last edited by b.koerts; 03-26-2016 at 09:57 AM.

  2. #2
    Join Date
    Aug 2009
    Location
    ifm Exton, PA
    Posts
    196

    Default

    First, convert all values to REALS. Second, you may run into issues when transmitting a real value over the CAN network. My recommendation is to multiply it by the number of decimal places you want to see (x100 for x.xx) convert into a word or dword then divide on the diplay side to getthe proper formatting.

  3. #3

    Default

    What kind of problems can I expect when transmitting reals via network variables?

    I'm doing this for years and experiencing no problems

  4. #4
    Join Date
    May 2009
    Location
    Minneapolis, MN
    Posts
    300

    Default

    Quote Originally Posted by NLex View Post
    What kind of problems can I expect when transmitting reals via network variables?

    I'm doing this for years and experiencing no problems
    The issue is the byte order may not be the same when dealing with REALs.

  5. #5
    Join Date
    Jun 2015
    Location
    Netherlands
    Posts
    20

    Default

    Sorry for my late reply. I had to finish the software quickly so I did it by trial and error. I did break up the long line to several lines and analyzed what was going on until it all started to make sense and then went back to one line step by step. I liked to send only bytes or words to keep the data load low for the can bus to avoid other issues data rate, crossing network variable boundaries until I learn more about that. Thanks for your answers, especially about sending real in network variables.

    Bert

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •