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
Multiplexer_read.cpp
00001 #include "mbed.h" 00002 00003 //*************************************************************************************************** 00004 //Outputs 00005 00006 DigitalOut Multiplex_select_0 (p25); 00007 DigitalOut Multiplex_select_1 (p26); 00008 DigitalOut Myled (LED1); 00009 00010 //DigitalOut timetest_0 (p30); 00011 //DigitalOut timetest_1 (p29); 00012 00013 //BusOut unused(p18); 00014 00015 //*************************************************************************************************** 00016 //Inputs 00017 00018 00019 AnalogIn Messkanal_0 (p15); 00020 AnalogIn Messkanal_1 (p16); 00021 00022 AnalogIn DMS_Kanal (p17); 00023 00024 //*************************************************************************************************** 00025 //Communication 00026 00027 Serial pc(USBTX, USBRX); 00028 00029 00030 volatile float Motorspannung, Bremsenspannung , Motorstrom, Aux, Bremsenstrom, Temperatur_1, Temperatur_2, Temperatur_3, DMS_Out, DMS_Skalierung; 00031 00032 00033 //*************************************************************************************************** 00034 //read sensors via multiplexer 00035 00036 void interr_read_sensors() 00037 { 00038 00039 int Messwert_0 = 0, Messwert_1 = 0; 00040 00041 Multiplex_select_0 = 0, Multiplex_select_1 = 0; 00042 00043 //Selection of Multiplexer states 00044 00045 for (int i=0; i<=4; i++) { 00046 //while(i<=4) { 00047 00048 Multiplex_select_0 = i&0x01; 00049 Multiplex_select_1 = (i>>1)&0x01; 00050 wait(0.001); 00051 00052 Messwert_0 = Messkanal_0.read_u16(); 00053 Messwert_1 = Messkanal_1.read_u16(); 00054 00055 switch(i) { 00056 case 0: { 00057 Multiplex_select_0 = 0; 00058 Multiplex_select_1 = 0; 00059 wait(0.001); 00060 Temperatur_1 = Messwert_0 ; 00061 Motorspannung = Messwert_1; //* 0.000515 - 0.05 ; Gute Näherung von 2- ~23V. Dannach zu niedrig.Z-Diode 00062 break; 00063 } 00064 00065 case 1: { 00066 Multiplex_select_0 = 1; 00067 Multiplex_select_1 = 0; 00068 wait(0.001); 00069 Temperatur_2 = Messwert_0 ; 00070 Motorstrom = Messwert_1; //* 0.000396 - 4.15; 00071 break; 00072 } 00073 00074 case 2: { 00075 Multiplex_select_0 = 0; 00076 Multiplex_select_1 = 1; 00077 wait(0.001); 00078 Temperatur_3 = Messwert_0; 00079 Bremsenspannung = Messwert_1; //* 0.000515 - 0.05;Gute Näherung von 2- ~23V. Dannach zu niedrig.Z-Diode 00080 break; 00081 } 00082 00083 case 3: { 00084 Multiplex_select_0 = 1; 00085 Multiplex_select_1 = 1; 00086 wait(0.001); 00087 Aux = Messwert_0; // 1629; 00088 Bremsenstrom = Messwert_1; //* 0.00032 - 15.8; 00089 break; 00090 } 00091 00092 00093 } 00094 00095 } 00096 00097 } 00098 00099 00100 //*************************************************************************************************** 00101 // MAIN: 00102 00103 int main(void) 00104 { 00105 00106 DMS_Skalierung = 1; 00107 00108 while(true) { 00109 00110 00111 00112 interr_read_sensors(); 00113 00114 DMS_Out = DMS_Kanal.read_u16()*DMS_Skalierung; 00115 00116 00117 pc.printf(" [Temperatur1, Motorspannung]; 0 %5.2f deg; 1 %5.2f V;", Temperatur_1, Motorspannung); 00118 pc.printf(" [Temperatur2, Motorstrom]; 0 %5.2f deg; 1 %5.2f A;", Temperatur_2, Motorstrom); 00119 pc.printf(" [Temperatur3, Bremsenspannung]; 0 %5.2f deg; 1 %5.2f V;", Temperatur_3, Bremsenspannung); 00120 pc.printf(" [Aux, Bremsenstrom]; 0 %5.2f ; 1 %5.2f ;", Aux, Bremsenstrom); 00121 pc.printf(" [DMS-Kanal]; 0 %5.2f ;", DMS_Out); 00122 pc.printf(" \r\n\r\n"); 00123 00124 wait(1); 00125 00126 } 00127 }
Generated on Wed Jul 13 2022 00:20:07 by
1.7.2
