Skip to main content
AIsma
Associate II
August 13, 2019
Solved

How do I go from an integer value to a q31_t? Do I need to normalize the in32_t to a value between -1 and 1 and then pass to arm_pid_q31 to complete the calculation?

  • August 13, 2019
  • 1 reply
  • 4079 views

I am using the arm pid library and I do not know how to use the arm_pid_q31 call. I need to give it an error as a q31_t, however, I am not entirely sure how to go from an int32_t to a q31_t. Do I need to normalize the in32_t to a value between -1 and 1 and then pass to arm_pid_q31 to complete the calculation?

This topic has been closed for replies.
Best answer by Tesla DeLorean

You're expect to pass an array with numbers in your selected fixed point format.

Review the "data representation" expectations and diagrams.

Values are going to need to be less than 1

If you have a 12-bit signed ADC value

q31 = adc12i << 20;

q31 = (q31_t)(fltvalue * ((float)(1 << 31)));

1 reply

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
August 13, 2019

You're expect to pass an array with numbers in your selected fixed point format.

Review the "data representation" expectations and diagrams.

Values are going to need to be less than 1

If you have a 12-bit signed ADC value

q31 = adc12i << 20;

q31 = (q31_t)(fltvalue * ((float)(1 << 31)));

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
AIsma
AIsmaAuthor
Associate II
August 13, 2019

I don't understand entirely, so I wanted to clarify a few things:

  1. You said the expectation is to pass an array with numbers, however, arm_pid_q31 accepts a q31_t, not a q31_t*. Are you saying arm_pid_q31 needs to be called multiple times.
  2. You mentioned reviewing expectations and diagrams, could you point me to them?
  3. Thanks for the help :)
Tesla DeLorean
Guru
August 13, 2019

It is passed an array of q31 values https://www.keil.com/pack/doc/CMSIS/DSP/html/structarm__pid__instance__q31.html

You understand how bits are held in bytes and word, and how floating point and fixed point values are held, and data in memory?

https://www.tutorialspoint.com/fixed-point-and-floating-point-number-representations

With q31 you've got 1 sign bit, and 31 fractional bits. Given this is entirely fractional bits holding the value, it will need to always be less than ONE (positive or negative), it could arguably represent -1 but unhelpfully.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..