Hello,
I am working on a project on a car and I need to program an arduino that can recognise the end of a signal. the signal can be seen in the screenshot below.
The signal in blue is the crankshaft position signal as a refference, in red you can see the signal the high pressure pump gets to regulate it's pressure and green is the signal the arduino sends out when it thinks it recognises the end of the pump signal.
The length of the signal in green is irrelevant. it just sends out a pulse on the end of signal en stops this puls when the interrupt function is triggert again. You can see that in code below:
const byte End = 2;
const byte Pulse = 7;
//pulsduur
unsigned long delta_HIGH;
unsigned long delta_LOW;
bool eind;
void setup() {
pinMode(End, INPUT);
pinMode(Pulse, OUTPUT);
attachInterrupt(digitalPinToInterrupt(End), eind_herkenning, RISING);
Serial.begin(115200);
}
void loop()
{
if(eind == HIGH){
digitalWrite(Pulse, LOW);
delta_HIGH = pulseIn(End, HIGH, 400);
delta_LOW = pulseIn(End, LOW, 400);
//Serial.println(delta_end);
if(delta_HIGH == 0 && delta_LOW == 0){
digitalWrite(Pulse, HIGH);
delta_HIGH = 1;
delta_LOW = 1;
//Serial.println("eind");
}
eind = LOW;
}
}
void eind_herkenning(){
eind = HIGH;
}
So in short, when a rising edge is triggered, it goes inside a if functie that calculates the pulse-duration of both a logic high and a logic 0. The timeout is because i want both functions to return zero so that it's fast enough to react to the end of the signal. The way that it is programmed now it should return a 0 on delta_HIGH because the signal is LOW and it should return 0 on delta_LOW because it can't measure the pulse-duration in time (400 µs).
this works as it should except for the false positive it returns at the start of the signal. Is there a way to eliminate this false positive?
