![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Kalibriersoftware Stromwerte
Pruefprogramm_Motorteststand.cpp@0:5e35c180ed4a, 2015-11-23 (annotated)
- Committer:
- Racer01014
- Date:
- Mon Nov 23 16:09:54 2015 +0000
- Revision:
- 0:5e35c180ed4a
- Child:
- 1:ea5f520dcdc1
-
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Racer01014 | 0:5e35c180ed4a | 1 | #include "mbed.h" |
Racer01014 | 0:5e35c180ed4a | 2 | #include "Matrix.h" |
Racer01014 | 0:5e35c180ed4a | 3 | #include "USBSerial.h" |
Racer01014 | 0:5e35c180ed4a | 4 | |
Racer01014 | 0:5e35c180ed4a | 5 | //*************************************************************************************************** |
Racer01014 | 0:5e35c180ed4a | 6 | //Outputs |
Racer01014 | 0:5e35c180ed4a | 7 | |
Racer01014 | 0:5e35c180ed4a | 8 | DigitalOut Multiplex_select_A (p26); |
Racer01014 | 0:5e35c180ed4a | 9 | DigitalOut Multiplex_select_B (p25); |
Racer01014 | 0:5e35c180ed4a | 10 | DigitalOut Myled (LED1); |
Racer01014 | 0:5e35c180ed4a | 11 | |
Racer01014 | 0:5e35c180ed4a | 12 | |
Racer01014 | 0:5e35c180ed4a | 13 | //*************************************************************************************************** |
Racer01014 | 0:5e35c180ed4a | 14 | //Inputs |
Racer01014 | 0:5e35c180ed4a | 15 | |
Racer01014 | 0:5e35c180ed4a | 16 | AnalogIn Messkanal_X (p15); |
Racer01014 | 0:5e35c180ed4a | 17 | AnalogIn Messkanal_Y (p16); |
Racer01014 | 0:5e35c180ed4a | 18 | AnalogIn DMS_Kanal (p17); |
Racer01014 | 0:5e35c180ed4a | 19 | |
Racer01014 | 0:5e35c180ed4a | 20 | //DigitalIn Start(p22); |
Racer01014 | 0:5e35c180ed4a | 21 | |
Racer01014 | 0:5e35c180ed4a | 22 | //*************************************************************************************************** |
Racer01014 | 0:5e35c180ed4a | 23 | //PWM |
Racer01014 | 0:5e35c180ed4a | 24 | |
Racer01014 | 0:5e35c180ed4a | 25 | PwmOut Motor(p23); |
Racer01014 | 0:5e35c180ed4a | 26 | PwmOut Bremse(p21); |
Racer01014 | 0:5e35c180ed4a | 27 | |
Racer01014 | 0:5e35c180ed4a | 28 | |
Racer01014 | 0:5e35c180ed4a | 29 | |
Racer01014 | 0:5e35c180ed4a | 30 | //*************************************************************************************************** |
Racer01014 | 0:5e35c180ed4a | 31 | //Communication |
Racer01014 | 0:5e35c180ed4a | 32 | |
Racer01014 | 0:5e35c180ed4a | 33 | Serial pc(USBTX, USBRX); |
Racer01014 | 0:5e35c180ed4a | 34 | |
Racer01014 | 0:5e35c180ed4a | 35 | //USBSerial terminal; |
Racer01014 | 0:5e35c180ed4a | 36 | |
Racer01014 | 0:5e35c180ed4a | 37 | |
Racer01014 | 0:5e35c180ed4a | 38 | volatile float Motorspannung, Bremsenspannung , Motorstrom, An_In_0, Bremsenstrom, Temperatur_0, Temperatur_1, Temperatur_2, DMS_Out, DMS_Skalierung; |
Racer01014 | 0:5e35c180ed4a | 39 | |
Racer01014 | 0:5e35c180ed4a | 40 | |
Racer01014 | 0:5e35c180ed4a | 41 | //*************************************************************************************************** |
Racer01014 | 0:5e35c180ed4a | 42 | //read sensors via multiplexer |
Racer01014 | 0:5e35c180ed4a | 43 | |
Racer01014 | 0:5e35c180ed4a | 44 | void read_sensors() |
Racer01014 | 0:5e35c180ed4a | 45 | { |
Racer01014 | 0:5e35c180ed4a | 46 | |
Racer01014 | 0:5e35c180ed4a | 47 | Multiplex_select_A = 0; |
Racer01014 | 0:5e35c180ed4a | 48 | Multiplex_select_B = 0; |
Racer01014 | 0:5e35c180ed4a | 49 | wait_ms(1); |
Racer01014 | 0:5e35c180ed4a | 50 | An_In_0 = Messkanal_X.read_u16(); |
Racer01014 | 0:5e35c180ed4a | 51 | Motorspannung = Messkanal_Y.read_u16(); //* 0.000515 - 0.05 ; Gute Näherung von 2- ~23V. Dannach zu niedrig.Z-Diode |
Racer01014 | 0:5e35c180ed4a | 52 | |
Racer01014 | 0:5e35c180ed4a | 53 | Multiplex_select_A = 1; |
Racer01014 | 0:5e35c180ed4a | 54 | wait_ms(1); |
Racer01014 | 0:5e35c180ed4a | 55 | Temperatur_0 = Messkanal_X.read_u16(); |
Racer01014 | 0:5e35c180ed4a | 56 | Motorstrom = Messkanal_Y.read_u16(); //* 0.000396 - 4.15; |
Racer01014 | 0:5e35c180ed4a | 57 | |
Racer01014 | 0:5e35c180ed4a | 58 | Multiplex_select_A = 0; |
Racer01014 | 0:5e35c180ed4a | 59 | Multiplex_select_B = 1; |
Racer01014 | 0:5e35c180ed4a | 60 | wait_ms(1); |
Racer01014 | 0:5e35c180ed4a | 61 | Temperatur_1 = Messkanal_X.read_u16(); |
Racer01014 | 0:5e35c180ed4a | 62 | Bremsenspannung = Messkanal_Y.read_u16(); //* 0.000515 - 0.05;Gute Näherung von 2- ~23V. Dannach zu niedrig.Z-Diode |
Racer01014 | 0:5e35c180ed4a | 63 | |
Racer01014 | 0:5e35c180ed4a | 64 | Multiplex_select_A = 1; |
Racer01014 | 0:5e35c180ed4a | 65 | wait_ms(1); |
Racer01014 | 0:5e35c180ed4a | 66 | Temperatur_2 = Messkanal_X.read_u16(); // 1629; |
Racer01014 | 0:5e35c180ed4a | 67 | Bremsenstrom = Messkanal_Y.read_u16(); //* 0.00032 - 15.8; |
Racer01014 | 0:5e35c180ed4a | 68 | |
Racer01014 | 0:5e35c180ed4a | 69 | } |
Racer01014 | 0:5e35c180ed4a | 70 | |
Racer01014 | 0:5e35c180ed4a | 71 | //*************************************************************************************************** |
Racer01014 | 0:5e35c180ed4a | 72 | //Safety Circuit |
Racer01014 | 0:5e35c180ed4a | 73 | |
Racer01014 | 0:5e35c180ed4a | 74 | int safety() |
Racer01014 | 0:5e35c180ed4a | 75 | { |
Racer01014 | 0:5e35c180ed4a | 76 | int Temp_max; |
Racer01014 | 0:5e35c180ed4a | 77 | read_sensors(); |
Racer01014 | 0:5e35c180ed4a | 78 | |
Racer01014 | 0:5e35c180ed4a | 79 | if( (Temperatur_0 < Temp_max) && (Temperatur_1 < Temp_max) && (Temperatur_2 < Temp_max)) |
Racer01014 | 0:5e35c180ed4a | 80 | return(0); |
Racer01014 | 0:5e35c180ed4a | 81 | else |
Racer01014 | 0:5e35c180ed4a | 82 | return(1); |
Racer01014 | 0:5e35c180ed4a | 83 | |
Racer01014 | 0:5e35c180ed4a | 84 | } |
Racer01014 | 0:5e35c180ed4a | 85 | |
Racer01014 | 0:5e35c180ed4a | 86 | //*************************************************************************************************** |
Racer01014 | 0:5e35c180ed4a | 87 | //Checkup @ Start |
Racer01014 | 0:5e35c180ed4a | 88 | |
Racer01014 | 0:5e35c180ed4a | 89 | int checkup() |
Racer01014 | 0:5e35c180ed4a | 90 | { |
Racer01014 | 0:5e35c180ed4a | 91 | return(1); |
Racer01014 | 0:5e35c180ed4a | 92 | } |
Racer01014 | 0:5e35c180ed4a | 93 | |
Racer01014 | 0:5e35c180ed4a | 94 | |
Racer01014 | 0:5e35c180ed4a | 95 | //*************************************************************************************************** |
Racer01014 | 0:5e35c180ed4a | 96 | //send values |
Racer01014 | 0:5e35c180ed4a | 97 | |
Racer01014 | 0:5e35c180ed4a | 98 | void send_data(void) |
Racer01014 | 0:5e35c180ed4a | 99 | { |
Racer01014 | 0:5e35c180ed4a | 100 | // pc.printf(" [Temperatur1, Motorspannung]; 0 %5.2f deg; 1 %5.2f V;", Temperatur_0, Motorspannung); |
Racer01014 | 0:5e35c180ed4a | 101 | // pc.printf(" [Temperatur2, Motorstrom]; 0 %5.2f deg; 1 %5.2f A;", Temperatur_1, Motorstrom); |
Racer01014 | 0:5e35c180ed4a | 102 | // pc.printf(" [Temperatur3, Bremsenspannung]; 0 %5.2f deg; 1 %5.2f V;", Temperatur_2, Bremsenspannung); |
Racer01014 | 0:5e35c180ed4a | 103 | // pc.printf(" [Aux, Bremsenstrom]; 0 %5.2f ; 1 %5.2f ;", An_In_0, Bremsenstrom); |
Racer01014 | 0:5e35c180ed4a | 104 | // pc.printf(" [DMS-Kanal]; 0 %5.2f ;", DMS_Out); |
Racer01014 | 0:5e35c180ed4a | 105 | pc.printf(" [Motorstrom, Bremsenstrom]; 0 %5.2f ; 1 %5.2f ;", Motorstrom, Bremsenstrom); |
Racer01014 | 0:5e35c180ed4a | 106 | pc.printf(" \r\n\r\n"); |
Racer01014 | 0:5e35c180ed4a | 107 | wait_ms(50); |
Racer01014 | 0:5e35c180ed4a | 108 | } |
Racer01014 | 0:5e35c180ed4a | 109 | |
Racer01014 | 0:5e35c180ed4a | 110 | |
Racer01014 | 0:5e35c180ed4a | 111 | //*************************************************************************************************** |
Racer01014 | 0:5e35c180ed4a | 112 | // MAIN: |
Racer01014 | 0:5e35c180ed4a | 113 | |
Racer01014 | 0:5e35c180ed4a | 114 | |
Racer01014 | 0:5e35c180ed4a | 115 | |
Racer01014 | 0:5e35c180ed4a | 116 | |
Racer01014 | 0:5e35c180ed4a | 117 | int main(void) |
Racer01014 | 0:5e35c180ed4a | 118 | { |
Racer01014 | 0:5e35c180ed4a | 119 | //********************* VARIABLEN ***************************** |
Racer01014 | 0:5e35c180ed4a | 120 | |
Racer01014 | 0:5e35c180ed4a | 121 | DMS_Skalierung = 1; |
Racer01014 | 0:5e35c180ed4a | 122 | Motor.period_us(200); |
Racer01014 | 0:5e35c180ed4a | 123 | Bremse.period_us(200); |
Racer01014 | 0:5e35c180ed4a | 124 | |
Racer01014 | 0:5e35c180ed4a | 125 | |
Racer01014 | 0:5e35c180ed4a | 126 | |
Racer01014 | 0:5e35c180ed4a | 127 | |
Racer01014 | 0:5e35c180ed4a | 128 | // Matrix Values(1,4); |
Racer01014 | 0:5e35c180ed4a | 129 | |
Racer01014 | 0:5e35c180ed4a | 130 | |
Racer01014 | 0:5e35c180ed4a | 131 | //************************ MAIN ******************************** |
Racer01014 | 0:5e35c180ed4a | 132 | |
Racer01014 | 0:5e35c180ed4a | 133 | |
Racer01014 | 0:5e35c180ed4a | 134 | while(true) |
Racer01014 | 0:5e35c180ed4a | 135 | { |
Racer01014 | 0:5e35c180ed4a | 136 | Motor.pulsewidth_us(0); |
Racer01014 | 0:5e35c180ed4a | 137 | Bremse.pulsewidth_us(0); |
Racer01014 | 0:5e35c180ed4a | 138 | read_sensors(); |
Racer01014 | 0:5e35c180ed4a | 139 | send_data(); |
Racer01014 | 0:5e35c180ed4a | 140 | |
Racer01014 | 0:5e35c180ed4a | 141 | DMS_Out = DMS_Kanal.read_u16()*DMS_Skalierung; |
Racer01014 | 0:5e35c180ed4a | 142 | |
Racer01014 | 0:5e35c180ed4a | 143 | //safety(); |
Racer01014 | 0:5e35c180ed4a | 144 | |
Racer01014 | 0:5e35c180ed4a | 145 | |
Racer01014 | 0:5e35c180ed4a | 146 | Myled=!Myled; |
Racer01014 | 0:5e35c180ed4a | 147 | wait_ms(500); |
Racer01014 | 0:5e35c180ed4a | 148 | |
Racer01014 | 0:5e35c180ed4a | 149 | |
Racer01014 | 0:5e35c180ed4a | 150 | //********************* Messprozedur **************************** |
Racer01014 | 0:5e35c180ed4a | 151 | //********************* |
Racer01014 | 0:5e35c180ed4a | 152 | |
Racer01014 | 0:5e35c180ed4a | 153 | |
Racer01014 | 0:5e35c180ed4a | 154 | |
Racer01014 | 0:5e35c180ed4a | 155 | |
Racer01014 | 0:5e35c180ed4a | 156 | } |
Racer01014 | 0:5e35c180ed4a | 157 | |
Racer01014 | 0:5e35c180ed4a | 158 | } |