![]() ![]() For example, in their documentation a holding register at address 1001 is referred to by “41001”. In the standard documents, holding register addresses are given a prefix of “4” to distinguish them from other register types. These issues generally don’t cause problems if you are using existing Modbus software or devices. If you used a double float, 1.2500037 could be stored more accurately as 1.2500036999999999398.īut using the integer method I said above, it would be exact and probably take less storage and CPU cycles.This article should be useful if you are writing your own Modbus communication software. ![]() Printf, if told to expect an integer with w, will interpret the binary number above as an integer (unsigned) and give you 1067450399. because 1.2500037 cannot be stored exactly in a 32 bit float. That will take less code, and give more precision that 32 bit float. ![]() Then to display it, you need to put the decimal place 7 places to the left, 1.2500037. I shifted the 0.0012219 decimal place 7 steps to the left right to make it a whole number. For instance, 1023 * 12219 = 12500037 would be your maximum value in integers. Float can store very small to very large numbers, but only to a few useful digits of precision.ĭouble (64 bit float) is better, or do what I usually do and use integers by scaling all the values by powers of ten. Note that 32 bit floating point is quite limited in resolution, due to having to store the exponent too. So, if you pass a float to printf but have told printf to expect an integer (with w), printf will just display the 32 bits as if it is a simple integer and the result will be strange. Floats are stored as a sign bit, an exponent, and a mantissa within the 32 bits. It's not to do with w specifying unsigned, it is to do with it specifying integer.Ī floating point number is stored completely differently to an integer. Set_adc_channel(7) // Sets a/d channel to number 7Īdcvalue = read_adc() // gets value of 0-1023 Setup_adc(ADC_CLOCK_INTERNAL) // Built-in A/D setup function Setup_adc_ports(sAN4|sAN5|sAN6|sAN7|VSS_VDD) The software i am using is CCS PIC-C 5.083 The code i am using is, i have taken out the code that was commented out Hi and thandks, i will have a look at it later. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |