Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Multiplexer-Test by
Diff: Multiplexer_read.cpp
- Revision:
- 2:d815250d0377
- Parent:
- 1:84c53305b6a5
- Child:
- 3:cb991a9ba6a6
--- a/Multiplexer_read.cpp Mon Sep 08 12:15:43 2014 +0000
+++ b/Multiplexer_read.cpp Mon Sep 08 13:30:52 2014 +0000
@@ -46,7 +46,7 @@
volatile int Drehzeit_counter = 0;
#define DREHZEIT_SIZE 3
volatile int Drehzeit[DREHZEIT_SIZE];
-//***************************************************************************************************
+
//***************************************************************************************************
//read sensors via multiplexer
@@ -112,7 +112,7 @@
}
}
-//***************************************************************************************************
+
//***************************************************************************************************
//Control Motor rpm
@@ -140,14 +140,13 @@
if (motor_pwm_cmd > 1900) motor_pwm_cmd = 1900;
else if (motor_pwm_cmd < 1010) motor_pwm_cmd = 1005;
- // Bremsenstrom_MOSFET.pulsewidth_us(curr_MOSFET_pwm_pulsewidth);
Motroregler_PWM.pulsewidth_us(motor_pwm_cmd);
motor_pwm_cmd_last = motor_pwm_cmd;
return 1;
}
-//***************************************************************************************************
+
//***************************************************************************************************
//Control MOSFET pwm
@@ -158,29 +157,29 @@
if (mosfet_pwm_cmd < 1.0) {
- Motroregler_PWM.pulsewidth_us(00);
- motor_pwm_cmd_last = 900;
-// motor_n_last = 0;
+ Bremsenstrom_MOSFET.pulsewidth_us(00);
+ mosfet_pwm_cmd_last = 0;
+
return 1;
}
- float motor_n_dif = motor_n_cmd - motor_n_cur;
+ float mosfet_pwm_dif = mosfet_pwm_cmd - mosfet_pwm_cur;
- int motor_pwm_cmd = (int)(motor_pwm_cmd_last + motor_n_dif * 0.6 + 0.5); // round() ... works only for positive values
+ // int mosfet_pwm_cmd = (int)(mosfet_pwm_cmd_last + mosfet_pwm_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);
+ pc.printf("cmd: %7.2f, cur: %7.2f, dif: %7.2f, mosfet_pwm_cmd: %4d, mosfet_pwm_dif: %4d",
+ mosfet_pwm_cmd, mosfet_pwm_cur, mosfet_pwm_dif, mosfet_pwm_cmd, mosfet_pwm_cmd-mosfet_pwm_cmd_last);
- if (motor_pwm_cmd > 1900) motor_pwm_cmd = 1900;
- else if (motor_pwm_cmd < 1010) motor_pwm_cmd = 1005;
+ if (mosfet_pwm_cmd > 20000) mosfet_pwm_cmd = 20000;
+ else if (mosfet_pwm_cmd < 0) mosfet_pwm_cmd = 0;
- // Bremsenstrom_MOSFET.pulsewidth_us(curr_MOSFET_pwm_pulsewidth);
- Motroregler_PWM.pulsewidth_us(motor_pwm_cmd);
- motor_pwm_cmd_last = motor_pwm_cmd;
+ Bremsenstrom_MOSFET.pulsewidth_us(MOSFET_pwm_cmd);
+
+ mosfet_pwm_cmd_last = mosfet_pwm_cmd;
return 1;
}
-//***************************************************************************************************
+
//***************************************************************************************************
//Calculate rpm
@@ -197,7 +196,7 @@
++Drehzeit_counter;
Umlaufzeit.reset();
}
-//***************************************************************************************************
+
//***************************************************************************************************
// MAIN:
