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:
- 9:341c831b162b
- Parent:
- 8:fd403cfcaa0a
--- a/Multiplexer_read.cpp Tue Sep 09 10:48:03 2014 +0000
+++ b/Multiplexer_read.cpp Wed Sep 10 06:36:20 2014 +0000
@@ -1,82 +1,44 @@
+//Includes
#include "mbed.h"
-
+//*************************************************************************
//Outputs
-
+//*************************************************************************
DigitalOut timetest_0 (p30);
-
BusOut unused(p18);
-
//Inputs
-
-InterruptIn Drehzahl_lichtschranke(p29);
-
-Timer Umlaufzeit;
+//*************************************************************************
+AnalogIn DMS_sens (p17);
//Communication
+//*************************************************************************
+int DMS_torque = 0;
Serial pc(USBTX, USBRX);
-volatile int Drehzeit_counter = 0;
-#define DREHZEIT_SIZE 3
-volatile int Drehzeit[DREHZEIT_SIZE];
+//DMS-Abfrage
+//*************************************************************************
+void DMS_value()
+{
+DMS_torque = DMS_sens.read_u16();
+}
+//*************************************************************************
-void Motor_drehzahl()
-{
- timetest_0 = 1;
- static bool first_run = true;
- int tmp = Umlaufzeit.read_us();
- if (first_run) {
- Umlaufzeit.start();
- first_run = false;
- return;
- }
- if (tmp < 1000) return;
-
- // Cache last 3 values for averaging
- Drehzeit[Drehzeit_counter % DREHZEIT_SIZE] = tmp;
- ++Drehzeit_counter;
- Umlaufzeit.reset();
-
- timetest_0 = 0;
-}
-
+//Main
+//*************************************************************************
int main(void)
{
-
- Drehzahl_lichtschranke.fall(&Motor_drehzahl);
-
-
// Time counters
- Timer timer_print;
- timer_print.start();
-
-
- float motor_n_cur = 0;
-
-
while(true) {
-
-
- // Calculate motor_n_cur by averaging
- int drehzeit_sum = 0;
- for (int i=0; i != DREHZEIT_SIZE; ++i)
- drehzeit_sum += Drehzeit[i];
-
- motor_n_cur = (drehzeit_sum ? (1.0e6/drehzeit_sum)*DREHZEIT_SIZE : 0.0)*60;
-
-
- // Set motor_n_cur to 0 if the interrupt wasn't called for a specified time
- if (Umlaufzeit.read_ms() > 200)
- motor_n_cur = 0.0;
-
- pc.printf("%f\n\r",motor_n_cur);
+DMS_value();
+
+ pc.printf("%i\n\r",DMS_torque);
wait(0.5);
}
