DavidS
Hello,

I am trying to read in and convert the value from a thermister to degC.

However I am continually running into data type errors when trying to do the math in ST, It seems that for nearly every math operator it requires a different data type.

Here is the math I am trying to use,

Temp := log(((10240000/RawADC) -10000));
Temp := 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp := Temp -273.15; // Convert Kelvinto Celcius

Also, I cannot seem to find a data type that will allow me to do something as simple as 1/0.12.

Is there another way I should be doing math with this platform ? I have pasted the same bit of math into codesys and it simulated OK using the REAL data type.

 
Reply 0 0
thiagoralves
IEC 61131-3 is very strict about operations between different data types. Some vendors decide to internally make the necessary conversions but this can lead to erroneous calculations (like 1/0.12 can be evaluated as INT/INT division or REAL/REAL division, which one is the right one the user intended?). So to avoid confusions, the standard defines that the compiler should throw an error if the operation is made between two different data types. Therefore, before starting any math operation you need to ensure that all operands are of the same type. For example, 1/0.12 should be written as 1.0/0.12 (both are REAL constants in this case) if you want to produce a REAL output. Same is true for all the other cases dealing with variables. You can’t divide a REAL by an INT. Both operands must be either INT or REAL or something else. You can use the available data type conversion blocks, like INT_TO_REAL() to make the necessary adjustments on your operations
Reply 0 0
DavidS
Hello, Thank you for the reply.

Please see my attached screen shot, Var A ,B and C are REAL , B, C are constants.

exited with status 1 (pid 17289)
/home/david/Documents/ESP_Test/build/plc.st:98-17..98-17: error: Initial value has incompatible data type.
In section: PROGRAM Thing
0098: B : REAL := 1;
1 error(s) found. Bailing out!

Error : IEC to C compiler returned 1
PLC code generation failed !

Am I going about this the wrong way or do I have a buggy installation ?
Reply 0 0
DavidS
Ahh, Ok please disregard.

If I change Var B's value from 1 to 1.0 it compiles !

I see where I am going wrong as opposed to the way codesys does things, Thanks for the info.
Reply 0 0
Reply