Ich verstehe nicht ganz wo ich diesen einsetzen soll?
Ich habe heute kurz getestet, wenn ich immer wieder mit digital write ein High schreibe, dann scheint er beim Wechsel auf Low auszuschalten. Ich weiss jetzt nicht ob ich im Code was falsch habe, aber eigentlich sollte es passen.
Wenn der Code normal durchläuft und die Bedingung if ((WdogTime - WdogTimeLast) >= WdogTimeout)
nicht erfüllt wird gleich zu Beginn, sondern irgendwann nach dieser Sekunde, dann funktioniert es. Wenn aber das Inputsignal am "WdogPin" fehlt, dann setzt er komischerweise den StopPin nicht auf Low wie es eigentlich geschehen sollte.
/*Emergency Stop Board V1.0 Test code
V1.1 Improved code
Added stop function if wire is broken or not connected
Added temporary WatchDog signal for programming
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Pin configuration:
- For the ATtiny 13 or ATtiny 85:
Watch Dog Pin => Pin D0 //Watch Dog signal receiving pin
Emergency Stop Pin => Pin D2 //Emergency Stop output pin
Signal LED Pin => Pin D1 //LED for showing the received Watch Dog signal
Watch Dog Pin for programming => Pin D3 //Temporary Watch Dog signal output pin during programming
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
#define WdogPin 0 //Watchdog connected to pin 0, Input (active high)
#define LedPin 1 //LED for Watchdog connected to pin 1, Output (active low) [Optional]
#define StopPin 2 //StopPin connected to pin 2, Output (active low)
#define TempProgPin 3 //Temporary Watch Dog signal output pin
#define WdogTimeout 350 //Define timeout in milliseconds
unsigned WdogStateLast = 1; //last Watch Dog signal status (High or Low)
unsigned long WdogTimeLast = 0; //last Watch Dog receiving time
unsigned WdogState = 0; //actual Watch Dog signal status (High or Low)
unsigned long WdogTime = 0; //actual Watch Dog receiving time
byte WDsignal = 0; //variable for the temporary Watch Dog signal (High = 1, Low = 0)
void setup() {
pinMode(StopPin, OUTPUT);
pinMode(LedPin, OUTPUT);
pinMode(WdogPin, INPUT_PULLUP);
pinMode(TempProgPin, OUTPUT);
digitalWrite(StopPin, 1); //High for normal process, high on startup for pulling the output pin to low for E-Stop if needed
digitalWrite(LedPin, 1); //Low for receiving WatchDog signal, high on startup
}
void loop() {
WdogState = digitalRead(WdogPin); //read the pin WdogPin and store it to WdogState
WdogTime = millis(); //store the time in ms to WdogTime
if (WdogStateLast == 0) { //if WdogStateLast is low, then make...
if (WdogState == 1) { //if WdogState is high, then make...
WdogStateLast = 1; //set WdogStateLast to high
WdogTimeLast = WdogTime; //store current time to WdogTimeLast
}
}
else { //else if WdodStateLast is high, then make...
if (WdogState == 0) { //if WdogState is low, then make...
WdogStateLast = 0; //set WdogStateLast to low
WdogTimeLast = WdogTime; //store current time to WdogTimeLast
}
}
if(WdogTime >= 1000){ //if WdogTime is greater than 1000ms (for power off if wire is broken or connection lost), then make...
if ((WdogTime - WdogTimeLast) >= WdogTimeout) { //if the difference between WdogTime and WdogTimeLast is greater or equal to WdogTimeout, then make...
digitalWrite(StopPin, 0); //E-Stop activated
digitalWrite(LedPin, 1); //LED turned off for transmitting signal
} else { //else if the WdogTimeout is not achieved, then make...
digitalWrite(StopPin, 1); //E-Stop deactivated
digitalWrite(LedPin, 0); //LED turned on for transmitting signal
}
}
//Temporary Watch Dog signal for programming the system
if(WDsignal == 0){ //if WDsignal is equal to 0, then make...
digitalWrite(TempProgPin, 0); //set pin TempProgPin to Low (High = 1, Low = 0)
WDsignal = 1; //set WDsignal to 1
}
else if(WDsignal == 1){ //if WDsignal is equal to 1, then make...
digitalWrite(TempProgPin, 1); //set pin TempProgPin to High (high = 1, low = 0)
WDsignal = 0; //set WDsignal to 0
}
}