Convert data type for PID controller

10 visualizaciones (últimos 30 días)
Hal Der
Hal Der el 27 de Feb. de 2022
Respondida: Yash el 7 de Feb. de 2024
Hi everyone,
I would like to do a PID controller for temperature. My temperature is read by an ADC 12bit then I would like to do the convertion to degree Celcius then feed it to the PID controller.
I checked how they did it on the example "f28379D_DCDC_Buck" and I am quiet sure to really understand it:
They first used a fixdt(0,16,12). This means :
  • Unsigned data type,
  • 16 bit,
  • 12 fraction length.
Why did they choose Stored Integer (SI)? and why they choose 12 fraction length? This will give RealWorldValue = StoredInteger ✕ 2−FractionLength
Then the second converter is fixdt(1,32,24) means
  • now it's signed data type,
  • 32 bit, my guess is it because the PID controller require 32bit data type
  • 24 fraction length, why did they choose fraction lengthÉ
I was curious and try on my board to feed 1V signal with 1V offset and check after each conversion the result:
As you can see the ADC conversion is good, peak is at 2700 ADC count, then 2700*2^(-12) gives 0.6592. But then I dont see any difference for the last conversion?!? What is it supposed to do?
Thank you

Respuestas (1)

Yash
Yash el 7 de Feb. de 2024
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!

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by