My project is a gearshift-indicator using 2 Adafruit neopixels LED strips and an Arduino Nano. Everything pretty much works as expected, save for a few issues.
A while ago I made a thread about measuring my engine's RPM from the ignition wire from the ECM Here.
The gist is that with your help I managed to etablish a method of detecting the time between pulses on an Arduino nano, using the pulsein() command. Arduino reads a square-wave signal from an ignition output from the ECM (square wave 0-5v) and converts it into RPM. Neopixels change quantity/color with raising RPM.
For a while, this worked quite well, but it was never perfect. The signal was always erratic, with the RPM number rising and falling seemingly at random. It was steady enough to measure with accuracy sufficient to render the shift light reliable, but not steady enough to be consistent or react fast enough, and required significant smoothing in the code to stop the leds flashing randomly.
I recently discovered that using digitalread() instead of pulsein() to detect each pulse was allegedly a more reliable and accurate way to measure the RPM with the added benefit of having a non-blocking program as pulsein() is no longer used (which blocks the whole program each time it waits for a peak/trough in the wave.)
However, this new sketch led to an even more erratic output, and I have since regressed to the pulsein() sketch. After trying a few different programming ideas, none of which worked, I decided to go back to square 1.
I went to view the ignition wire signal with my oscilloscope, and as it turns out, when the oscilloscope is set to 200ms/div or more, the signal showed the same erratic behaviour as the new sketch. However, when the oscilloscope is set to 100ms/div or lower, the signal is perfect, with clean uninterrupted pulses.
Now this baffles me, because on the new sketch (and the pulsein() one for that matter) i had everything in my void_loop() in an if() statement that would trigger if millis() was 1ms greater than at the end of the if() statement. So the arduino should be looking for pulses every 1ms, giving it more than enough time to detect every pulse, right? But the sketches are seemingly providing the same erratic output as the oscilloscope does when set at 200ms... I believe I have a critical lack of understanding of what's going on here, hence why I am asking for help.
I had previously hypothesized that perhaps the signal was unclean, and i need to modify things electrically but after stumbling upon the perfectly clean signal at 100ms/div and 50ms/div on the oscilloscope, I believe now it should simply be a matter of getting the Arduino to see that clean signal too through programming, right?
tl;dr, my oscilloscope shows (doesn't show?) missing waves in the signal when set to 200ms/div, but misses none when set to 100ms/div or lower - signal is perfect. This incomplete waveform happens to be also seemingly what the arduino sees/outputs despite my coding attempts. I need help trying to figure out how to get the clean waveform regsitered by the Arduino.Processing: 86 revs 1.mp4...
Processing: 86 revs 2.mp4...
edit: latest schematic