1

Dependencies:   mbed-dev-f303 FastPWM3

Revision:
54:4c9415402628
Parent:
45:aadebe074af6
--- a/math_ops.cpp	Tue Sep 15 08:59:03 2020 +0000
+++ b/math_ops.cpp	Thu Sep 17 07:49:27 2020 +0000
@@ -1,5 +1,6 @@
 
-#include "math_ops.h"
+#include "../math_ops.h"
+
 
 float fmaxf(float x, float y){
     /// Returns maximum of x, y ///
@@ -35,9 +36,12 @@
         *y = *y * limit/norm;
         }
     }
-
+    
+void limit(float *x, float min, float max){
+    *x = fmaxf(fminf(*x, max), min);
+    }
 
-int float_to_uint(float x, float x_min, float x_max, uint8_t bits){
+int float_to_uint(float x, float x_min, float x_max, int bits){
     /// Converts a float to an unsigned int, given range and number of bits ///
     float span = x_max - x_min;
     float offset = x_min;
@@ -45,9 +49,9 @@
     }
     
     
-float uint_to_float(int x_int, float x_min, float x_max, uint8_t bits){
+float uint_to_float(int x_int, float x_min, float x_max, int bits){
     /// converts unsigned int to float, given range and number of bits ///
     float span = x_max - x_min;
     float offset = x_min;
     return ((float)x_int)*span/((float)((1<<bits)-1)) + offset;
-    }
\ No newline at end of file
+    }