# Fixed-point calculation using CMSIS_library

Hi.

I'm a robot engineer and I usually use MCUs such as nrf52832(cortex-M4f) or ST32f407(cortex) to use various sensors.

Since those MCUs have an FPU inside, calculating time was quite fast without any burdensome optimizations.

The problem is, I have to use nrf52810(cortex-M4 without FPU) and calculate fractional numbers and trigonometric functions.

I'm worried about computational time is not enough to fast handling multiple sensors with nrf52810.

As I know, the CMSIS DSP library is very powerful in calculating fixed-point variables and trigonometric functions.

The library has Q31 or Q15 format but I'm confused about using it right.

Do I have to map each variable to Q31 and bear the mapped variables in mind?

For example, multiplying 30.02f and 12.76f using CMSIS DSP in that way would like this

float32_t ValA=30.02f;

float32_t ValB=12.76f;

float32_t Outcome;

q31_t ValA_Q31, ValB_Q31, Outcome_Q31;

arm_float_to_q31(ValA/1000, &ValA_Q31,1);  // Since range of Q31 is between -1 and 1

arm_float_to_q31(ValB/1000, &ValA_Q31,1);  // Since range of Q31 is between -1 and 1

arm_mult_q31(&ValA_Q31,&ValB_Q31,Outcome_Q31,1);

arm_q31_to_float(&Outcome,&Outcome_Q31,1);

printf("Sensordata: %f",Outcome*1000*1000);

Is it correct to use CMSIS DSP in that way?

If there are other ways please let me know...

This is all the functions that I use. (sine, cosine, square root, addition, subtraction, division, multiplication)

This is the simplified calculation example for handling sensor output.

int32_t ValA = 300;  // Integer Sensor value

float ValA_float;

float Outcome;

ValA_float= (float)ValA/1000.0f;

Outcome=20.0f+1.32f*sin(ValA_float);

printf("Sensordata: %f",Outcome);

The actual code is more complicated than above.

How can I use the CMSIS DSP in that case above to reduce the computational time?

More questions in this forum

283 views
3 replies
Latest

81 views
Latest

254 views
2 replies
Latest

344 views
3 replies
Latest
by