Automotive digital tachometer signal - 0-5v square wave - rising edge at each cylinder TDC on ignition stroke. 6 cylinder engine will produce 3 rising edges per crankshaft rotation (each 4-cycle cylinder only fires every 720 degrees).
8000RPM Max, 400Hz tach signal peak.
(Yes, I am level shifting this signal down to a 0-2v signal)
On the scope the signal going into the T4 on pin A5 is clean. The tach signal idles at 0V with ~37mV of noise. This noise does NOT trigger the ISR. The pulsewidth is ~3ms @ 2V.
In my ISR, the only ISR being used in this setup: (I have simplified the code below) RPMPulse1, RPMPulse2, and RPM are all declared as volatile float.
In my main loop I am performing other tasks such as reading A/D inputs for two other sensors, controlling a PWM output to a solenoid, and driving an ILI9341 TFT with XPT2046 touchscreen to display data, etc. This process loop cycles ~43Hz.
Here is a short stream result of the data I am getting from this:
inf
1775.57
1775.57
inf
1816.86
1775.57
inf
1775.57
1775.57
inf
inf
Obviously divide by zero is occuring which I have confirmed that the RPMPulse1 is sometimes returning a value of 0. I suspect this is because the ISR is getting triggered nearly back to back by noise or??
I could write in a small bit of patch code to prevent this /0 from happening but I'd rather figure out what is really going on here.
After looking more closely at the signal while it is high, there is a bit of noise in it with occasional small ~40mv peaks at the end just before dropping low. The occurrence of these little peaks seems to be similar to how often I get this /0...
However, the micros() timebase should still report a difference in time, albeit somewhere in the 1-2ms range, but it is not, so I am not inclined to think that this small ripple has anything to do with it.
What is the criteria for the signal to be registered as a rising edge?
8000RPM Max, 400Hz tach signal peak.
(Yes, I am level shifting this signal down to a 0-2v signal)
On the scope the signal going into the T4 on pin A5 is clean. The tach signal idles at 0V with ~37mV of noise. This noise does NOT trigger the ISR. The pulsewidth is ~3ms @ 2V.
In my ISR, the only ISR being used in this setup: (I have simplified the code below) RPMPulse1, RPMPulse2, and RPM are all declared as volatile float.
Code:
SETUP:
attachInterrupt(digitalPinToInterrupt(AuxIn), REFRISE, RISING);
void REFRISE() {
RPMPulse1 = micros() - RPMPulse2;
RPMPulse2 = micros();
RPM = 20000000 / RPMPulse1;
}
In my main loop I am performing other tasks such as reading A/D inputs for two other sensors, controlling a PWM output to a solenoid, and driving an ILI9341 TFT with XPT2046 touchscreen to display data, etc. This process loop cycles ~43Hz.
Here is a short stream result of the data I am getting from this:
inf
1775.57
1775.57
inf
1816.86
1775.57
inf
1775.57
1775.57
inf
inf
Obviously divide by zero is occuring which I have confirmed that the RPMPulse1 is sometimes returning a value of 0. I suspect this is because the ISR is getting triggered nearly back to back by noise or??
I could write in a small bit of patch code to prevent this /0 from happening but I'd rather figure out what is really going on here.
After looking more closely at the signal while it is high, there is a bit of noise in it with occasional small ~40mv peaks at the end just before dropping low. The occurrence of these little peaks seems to be similar to how often I get this /0...
However, the micros() timebase should still report a difference in time, albeit somewhere in the 1-2ms range, but it is not, so I am not inclined to think that this small ripple has anything to do with it.
What is the criteria for the signal to be registered as a rising edge?
Last edited by a moderator: