Update vom 10.05.15
Dependencies: FreescaleIAP MODSERIAL mbed monitor timer0
Fork of 18_PT1000 by
main.cpp@21:6f524a6caabe, 2015-08-23 (annotated)
- Committer:
- rs27
- Date:
- Sun Aug 23 10:18:54 2015 +0000
- Revision:
- 21:6f524a6caabe
- Parent:
- 20:b85406f52de3
Version 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rs27 | 21:6f524a6caabe | 1 | // Version 1.0 erstellt am 22.08.2015 |
rs27 | 21:6f524a6caabe | 2 | // |
rs27 | 21:6f524a6caabe | 3 | // IN1 auf 0 = OUT5+6 AUS |
rs27 | 21:6f524a6caabe | 4 | // IN1 auf 1 = OUT5+6 EIN plus 5 Sekunden Ausschaltverzögerung |
rs27 | 0:e248310dfcdb | 5 | |
rs27 | 0:e248310dfcdb | 6 | #include "mbed.h" |
rs27 | 19:f3c41bbc809a | 7 | #include "main.h" |
rs27 | 0:e248310dfcdb | 8 | #include "timer0.h" |
rs27 | 0:e248310dfcdb | 9 | #include "monitor.h" |
Sven3010 | 18:939d3df56218 | 10 | #include "MODSERIAL.h" |
rs27 | 0:e248310dfcdb | 11 | |
rs27 | 19:f3c41bbc809a | 12 | #define NEED_CONSOLE_OUTPUT 1 // Set this if you need debug messages on the console |
rs27 | 19:f3c41bbc809a | 13 | // mit Debug wird die Programmgröße von 32,8k um ca. 300 Byte vergrößert |
rs27 | 19:f3c41bbc809a | 14 | // dies ist nicht bedeutend, aber auch die Ausführungszeit der Ausgabebefehle |
rs27 | 19:f3c41bbc809a | 15 | // benötigt CPU Zeit |
rs27 | 19:f3c41bbc809a | 16 | #if NEED_CONSOLE_OUTPUT |
rs27 | 19:f3c41bbc809a | 17 | #define DEBUG(...) { pc.printf(__VA_ARGS__); } |
rs27 | 19:f3c41bbc809a | 18 | #else |
rs27 | 19:f3c41bbc809a | 19 | #define DEBUG(...) // nothing |
rs27 | 19:f3c41bbc809a | 20 | #endif // #if NEED_CONSOLE_OUTPUT |
Sven3010 | 18:939d3df56218 | 21 | |
rs27 | 6:f53dd76c8806 | 22 | //------------------------------------------------------------------------------ |
rs27 | 6:f53dd76c8806 | 23 | // Anlegen von Klassen |
Sven3010 | 4:46365f765d30 | 24 | |
rs27 | 2:f48d2eb0cc55 | 25 | timer0 down_timer; // Zeitsteuerung |
rs27 | 19:f3c41bbc809a | 26 | MODSERIAL pc(USBTX, USBRX); // tx, rx |
rs27 | 6:f53dd76c8806 | 27 | |
rs27 | 19:f3c41bbc809a | 28 | monitor mon; |
rs27 | 19:f3c41bbc809a | 29 | |
rs27 | 10:84387eed15b5 | 30 | Timer t; // Zeitmessung für Entprellen |
rs27 | 0:e248310dfcdb | 31 | |
rs27 | 6:f53dd76c8806 | 32 | //------------------------------------------------------------------------------ |
rs27 | 6:f53dd76c8806 | 33 | // Zuordnung von Eingängen und Ausgängen |
rs27 | 6:f53dd76c8806 | 34 | |
rs27 | 19:f3c41bbc809a | 35 | DigitalOut LED(PTE30); |
rs27 | 0:e248310dfcdb | 36 | |
rs27 | 19:f3c41bbc809a | 37 | DigitalOut OUT1(PTC6); // nicht belegt |
rs27 | 21:6f524a6caabe | 38 | DigitalOut OUT2(PTC5); // nicht belegt |
rs27 | 21:6f524a6caabe | 39 | DigitalOut OUT3(PTC4); // nicht belegt |
rs27 | 21:6f524a6caabe | 40 | DigitalOut OUT4(PTC3); // Türöffner schaltet gegen GND max. 500mA |
rs27 | 21:6f524a6caabe | 41 | DigitalOut OUT5(PTC2); // nicht belegt (Summer) |
rs27 | 21:6f524a6caabe | 42 | DigitalOut OUT6(PTC1); // Relais: Tür / Torsteuerung Relais Kontakt als Ausgang |
rs27 | 0:e248310dfcdb | 43 | |
rs27 | 21:6f524a6caabe | 44 | DigitalIn IN1(PTC7); // Taster Türöffnersignal 24V oder 1 ist der Ruhezustand |
rs27 | 21:6f524a6caabe | 45 | DigitalIn IN2(PTD4); // nicht belegt |
rs27 | 21:6f524a6caabe | 46 | DigitalIn IN3(PTD5); // nicht belegt |
rs27 | 19:f3c41bbc809a | 47 | DigitalIn IN4(PTD6); // nicht belegt |
rs27 | 19:f3c41bbc809a | 48 | DigitalIn IN5(PTD7); // nicht belegt |
rs27 | 0:e248310dfcdb | 49 | |
rs27 | 19:f3c41bbc809a | 50 | DigitalInOut rst(PTA4); //Connect this to the reset pin |
rs27 | 6:f53dd76c8806 | 51 | |
rs27 | 6:f53dd76c8806 | 52 | //------------------------------------------------------------------------------ |
rs27 | 6:f53dd76c8806 | 53 | // Globale Variablen |
rs27 | 6:f53dd76c8806 | 54 | |
rs27 | 19:f3c41bbc809a | 55 | bool in; |
rs27 | 2:f48d2eb0cc55 | 56 | |
rs27 | 19:f3c41bbc809a | 57 | struct di_struct in1; // Eingang 1 |
rs27 | 21:6f524a6caabe | 58 | |
rs27 | 0:e248310dfcdb | 59 | |
rs27 | 2:f48d2eb0cc55 | 60 | //------------------------------------------------------------------------------ |
rs27 | 2:f48d2eb0cc55 | 61 | // |
rs27 | 0:e248310dfcdb | 62 | |
rs27 | 19:f3c41bbc809a | 63 | int main() |
rs27 | 0:e248310dfcdb | 64 | { |
rs27 | 19:f3c41bbc809a | 65 | rst.input(); // SW watchdog ist derzeit nicht erforderlich |
Sven3010 | 3:72a65324d50d | 66 | |
rs27 | 2:f48d2eb0cc55 | 67 | //------------------------------------------------------------------------------ |
rs27 | 2:f48d2eb0cc55 | 68 | // RS232 Schnittstellt welche auf den CMSIS-DAP (USB Port) weitergeleitet wird |
rs27 | 2:f48d2eb0cc55 | 69 | // |
rs27 | 19:f3c41bbc809a | 70 | pc.baud(115200); |
rs27 | 19:f3c41bbc809a | 71 | pc.printf("\n N1380 V1.0 was compiled on %s %s \n", __DATE__,__TIME__); |
rs27 | 0:e248310dfcdb | 72 | |
rs27 | 19:f3c41bbc809a | 73 | |
rs27 | 19:f3c41bbc809a | 74 | //-------------------------------------------------------------------- |
rs27 | 19:f3c41bbc809a | 75 | // Anfangswerte setzen |
rs27 | 6:f53dd76c8806 | 76 | |
rs27 | 21:6f524a6caabe | 77 | in1.old = 1; // 1 im Ruhezustand |
rs27 | 21:6f524a6caabe | 78 | OUT4 = 0; |
rs27 | 21:6f524a6caabe | 79 | OUT6 = 0; |
rs27 | 21:6f524a6caabe | 80 | |
rs27 | 2:f48d2eb0cc55 | 81 | //-------------------------------------------------------------------- |
rs27 | 19:f3c41bbc809a | 82 | // Softwaretimer für die Zeitsteuerung anlegen |
rs27 | 6:f53dd76c8806 | 83 | |
rs27 | 21:6f524a6caabe | 84 | down_timer.SetCountdownTimer(0,1,500); // 1 ms Timer * 500 => ergibt 500 ms für die LED |
rs27 | 21:6f524a6caabe | 85 | down_timer.SetCountdownTimer(1,1,10); // 1 ms Timer * 10 => ergibt 10 ms für die Tasterabfrage |
rs27 | 2:f48d2eb0cc55 | 86 | |
rs27 | 0:e248310dfcdb | 87 | //-------------------------------------------------------------------- |
rs27 | 0:e248310dfcdb | 88 | // Schleife fuer die Datenerfassung |
rs27 | 19:f3c41bbc809a | 89 | |
rs27 | 0:e248310dfcdb | 90 | while(1) |
rs27 | 0:e248310dfcdb | 91 | { |
rs27 | 19:f3c41bbc809a | 92 | //------------------------------------------- |
rs27 | 19:f3c41bbc809a | 93 | // Prüfen ob Zeichen eingegeben wurden |
rs27 | 19:f3c41bbc809a | 94 | // wird in der aktiven Version ausgeblendet, ist nur zum Testen |
rs27 | 19:f3c41bbc809a | 95 | |
rs27 | 19:f3c41bbc809a | 96 | mon.get_line(); |
rs27 | 19:f3c41bbc809a | 97 | |
rs27 | 19:f3c41bbc809a | 98 | //------------------------------------------- |
rs27 | 19:f3c41bbc809a | 99 | // timer 0 steuert die LED auf dem Board mit der Takrate 0,5 Sekunden |
rs27 | 19:f3c41bbc809a | 100 | |
rs27 | 21:6f524a6caabe | 101 | if (down_timer.GetTimerStatus(0) == 0) |
rs27 | 21:6f524a6caabe | 102 | { |
rs27 | 19:f3c41bbc809a | 103 | down_timer.SetCountdownTimer(0,1,500); |
rs27 | 19:f3c41bbc809a | 104 | LED = !LED; |
rs27 | 19:f3c41bbc809a | 105 | |
rs27 | 19:f3c41bbc809a | 106 | } |
rs27 | 19:f3c41bbc809a | 107 | |
rs27 | 19:f3c41bbc809a | 108 | //------------------------------------------- |
rs27 | 19:f3c41bbc809a | 109 | // Eingänge abfragen und Aktionen ableiten |
rs27 | 19:f3c41bbc809a | 110 | // down |
rs27 | 19:f3c41bbc809a | 111 | |
rs27 | 19:f3c41bbc809a | 112 | if (down_timer.GetTimerStatus(1) == 0) |
rs27 | 19:f3c41bbc809a | 113 | { |
rs27 | 19:f3c41bbc809a | 114 | //down_timer 1 mit 10 ms gesetzt |
rs27 | 19:f3c41bbc809a | 115 | down_timer.SetCountdownTimer(1,1,10); |
Sven3010 | 18:939d3df56218 | 116 | |
rs27 | 19:f3c41bbc809a | 117 | //------------------------------------------------ |
rs27 | 19:f3c41bbc809a | 118 | // IN1 Nottaster auswerten, null im Ruhezustand |
rs27 | 19:f3c41bbc809a | 119 | // wird mit der negativen Flanke aktiviert |
rs27 | 19:f3c41bbc809a | 120 | // das Signal muss mindestens 10ms anliegen, damit es akzeptiert wird |
rs27 | 6:f53dd76c8806 | 121 | |
rs27 | 19:f3c41bbc809a | 122 | in = IN1; |
rs27 | 6:f53dd76c8806 | 123 | |
rs27 | 19:f3c41bbc809a | 124 | if(!in && in1.old) // Öffner im Ruhezustand 24 V >> durch Drücken wird eine neg. Flanke erzeugt |
rs27 | 21:6f524a6caabe | 125 | { |
rs27 | 19:f3c41bbc809a | 126 | in1.old = 0; |
rs27 | 19:f3c41bbc809a | 127 | DEBUG("\n negative Flanke IN1 \n"); |
rs27 | 19:f3c41bbc809a | 128 | } |
rs27 | 19:f3c41bbc809a | 129 | |
rs27 | 21:6f524a6caabe | 130 | if (in && !in1.old) // Öffner im Ruhenzustand 24 V >> durch Rückstellen enteht eine pos. Flanke |
rs27 | 16:3a4350104b68 | 131 | { |
rs27 | 21:6f524a6caabe | 132 | in1.old = 1; |
rs27 | 21:6f524a6caabe | 133 | down_timer.SetCountdownTimer(3,1,5000); // Zeit für Abschaltverzögerung auf 5 Sekunden setzen |
rs27 | 21:6f524a6caabe | 134 | DEBUG("\n positve Flanke IN1 \n"); |
Sven3010 | 18:939d3df56218 | 135 | } |
rs27 | 19:f3c41bbc809a | 136 | |
rs27 | 19:f3c41bbc809a | 137 | //--------------------------------------------------------------------------------------------------------------------------------------- |
rs27 | 21:6f524a6caabe | 138 | // Die Eingänge sind nun gelesen, jetzt kommt das Steuern der Ausgänge |
rs27 | 19:f3c41bbc809a | 139 | // |
Sven3010 | 18:939d3df56218 | 140 | |
rs27 | 19:f3c41bbc809a | 141 | //------------------------------------------------ |
rs27 | 21:6f524a6caabe | 142 | // IN1 auf 0 = OUT4+6 AUS |
rs27 | 21:6f524a6caabe | 143 | // Nach Ablauf der Ausschaltverzögerung wird der Ausgang wieder auf 0 geschaltet |
rs27 | 19:f3c41bbc809a | 144 | |
rs27 | 21:6f524a6caabe | 145 | if (!in1.old && (down_timer.GetTimerStatus(3) == 0)) |
rs27 | 21:6f524a6caabe | 146 | { |
rs27 | 21:6f524a6caabe | 147 | OUT4 = 0; |
rs27 | 21:6f524a6caabe | 148 | OUT6 = 0; |
rs27 | 19:f3c41bbc809a | 149 | } |
rs27 | 19:f3c41bbc809a | 150 | |
rs27 | 19:f3c41bbc809a | 151 | //------------------------------------------------ |
rs27 | 21:6f524a6caabe | 152 | // IN1 auf 1 = OUT4+6 EIN plus 5 Sekunden Ausschaltverzögerung |
rs27 | 21:6f524a6caabe | 153 | // Die Ausschaltverögerung wirkt auf das Ausschalten nicht auf das Einschalten |
rs27 | 21:6f524a6caabe | 154 | |
rs27 | 21:6f524a6caabe | 155 | if (in1.old) |
rs27 | 21:6f524a6caabe | 156 | { |
rs27 | 21:6f524a6caabe | 157 | OUT4 = 1; |
rs27 | 21:6f524a6caabe | 158 | OUT6 = 1; |
rs27 | 21:6f524a6caabe | 159 | } |
rs27 | 19:f3c41bbc809a | 160 | |
rs27 | 19:f3c41bbc809a | 161 | } // end if (downtimer ... |
rs27 | 19:f3c41bbc809a | 162 | |
rs27 | 0:e248310dfcdb | 163 | } // end while |
rs27 | 0:e248310dfcdb | 164 | |
rs27 | 19:f3c41bbc809a | 165 | } // end main |
rs27 | 19:f3c41bbc809a | 166 |