Hello,
Your understanding of the fixed-point data types and their behavior in the context of ADC conversion and PID control is quite correct. Here is a brief understanding of both the converters and the observed behaviour.
For the "fixdt(0,16,12)":
- Unsigned data type: The temperature value is likely to be positive, so there's no need for a sign bit.
- 16 bit: This provides a reasonable range of representable values. With 12 bits used for the fractional part, the integer part is limited to 4 bits.
- 12 fraction length: The fractional length is chosen based on the desired precision and the range of the ADC input. With a 12-bit ADC, using a 12-bit fractional part directly maps the ADC counts to the fractional part of the fixed-point representation.
For the "fixdt(1,32,24)":
- Signed data type: The PID controller may need to represent negative values for the control error (difference between the setpoint and the measured temperature).
- 32 bit: A larger word size is used for the PID calculations to maintain precision and to prevent overflow during intermediate calculations.
- 24 fraction length: This provides a high level of precision for the PID controller's calculations which may involve small error values and require fine adjustments.
Conversion Observations:
- The ADC value (2700 counts) is scaled down by the 12-bit fraction length, resulting in a real-world decimal value (0.6592).
- The last conversion might not show a visible difference if the input is already within the range and precision that can be represented by both fixed-point configurations. The purpose of this conversion is likely to adjust the data type and scaling for compatibility with the PID controller's expected input format.
In practice, the conversion to 32-bit signed with a 24-bit fraction length is likely there to ensure that when the value is used in subsequent calculations (such as within the PID controller), there is enough precision and range to handle the intermediate values without loss of information or overflow.
Regarding the confusion on Stored Integer and Real World Value, given below is a brief description:
- Stored Integer (SI): This is the actual numerical value stored in memory. It's an integer that represents the scaled version of the real-world value. For example, if you have a temperature sensor reading that you've scaled up by a factor of 100 to maintain precision, the SI is that scaled-up value.
- Real World Value (RWD): This is the value that the stored integer represents in real-world units. It's the value you'd use in calculations that relate to physical quantities, like temperature in degrees Celsius. To get the RWD from the SI, you scale it down by the factor you used when storing it.
Hope this helps!