Hi All,
This has probably been asked for in some shape or form. It's not a problem I've come across as I rarely do float maths, but the PID library I'm using is doing just that.
The PID library (arm_pid_f32) returns a float32_t of value between -1.0 and 1.0. I limit the lower to 0.0.
I need to map this onto a 12-bit uint16_t, so 1.0 = 4095
Casting the float into a double offers a 11 bit exponent which isn't enough to do a *4095 operation.
float32_t value = arm_pid_f32(&pid, motion.target - motion.kph); if (value < 0.0) { value = 0.0; } printf("target %f \n", value);