H2M Teststand / Mbed 2 deprecated H2M_Snippets

Dependencies:   mbed

Fork of Low_Cost_PWM by Hans Dampf

Revision:
5:a68e6c550e4b
Child:
6:f97371e6bc3e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motorregler_simple.cpp	Wed Sep 10 12:51:11 2014 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+
+
+PwmOut Motroregler_PWM(p22);
+
+int void()
+{
+
+//***************************************************************************************************
+//Control Motor rpm
+ 
+int rpm_control(float motor_n_cmd, float motor_n_cur)
+{
+ 
+    static int motor_pwm_cmd_last = 900;
+    //static float motor_n_last = 0;
+ 
+    if (motor_n_cmd < 1.0) {
+        Motroregler_PWM.pulsewidth_us(900);
+        motor_pwm_cmd_last = 900;
+//        motor_n_last = 0;
+        return 1;
+    }
+ 
+    float motor_n_dif = motor_n_cmd - motor_n_cur;
+ 
+    int motor_pwm_cmd = (int)(motor_pwm_cmd_last + motor_n_dif * 0.6 + 0.5); // round() ... works only for positive values
+ 
+    pc.printf("cmd: %7.2f, cur: %7.2f, dif: %7.2f, motor_pwm_cmd: %4d, motor_pwm_dif: %4d, DMS: %f\n\r",
+              motor_n_cmd*60, motor_n_cur*60, motor_n_dif*60, motor_pwm_cmd, motor_pwm_cmd-motor_pwm_cmd_last, ((int)DMS_0.read_u16())/65536.0*3.3);
+ 
+    if (motor_pwm_cmd > 1900) motor_pwm_cmd = 1900;
+    else if (motor_pwm_cmd < 1010) motor_pwm_cmd = 1005;
+ 
+    Motroregler_PWM.pulsewidth_us(motor_pwm_cmd);
+    motor_pwm_cmd_last = motor_pwm_cmd;
+ 
+    return 1;
+ }
+ 
+//***************************************************************************************************
+//Control MOSFET pwm
+}
\ No newline at end of file