b.koerts

03-26-2016, 05:48 AM

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

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