Why did you not list the engine size or mileage, especially when you have an engine-related problem? With intermittent problems with this circuit, it typically IS caused by the sensor, but it is customary to test the wiring harness first to eliminate all other possibilities before spending money on parts. In this case the wiring was likely being checked while the problem wasn't occurring, so everything is going to check okay.
What needs to be done now is to connect a scanner to view live data, then watch what happens to the camshaft position sensor's signal when the stalling and / or Check Engine light act up. Some older scanners will just list the signal as "present" or "no", but many of the newer ones have graphing capabilities that show the signal and when there's "dropouts", meaning a momentary loss of that signal. Some engines will still run with one missing signal but will not restart after being stopped. Some engines stall right away when the signal from the camshaft position sensor OR the crankshaft position sensor go missing.
On most engines the two sensors share a common ground and a common five or eight volt feed circuit. When either sensor shorts, it kills the signals from both sensors, but often a fault code is only set for one of them. That will show up on a graphing scanner.
An additional clue you might watch for is if the five volt feed circuit has an intermittent short to ground, the Engine Computer will shut that power supply down to protect it. The only way to reset it is to turn the ignition switch off, then restart the engine. If there is any intermittent stalling but suddenly it clears up and the engine continues running, that pretty much indicates the cause is not the feed wire shorting to ground. It could have an intermittent "open circuit", meaning a break in the wire. That is not the same thing as a short circuit.
Thursday, July 16th, 2015 AT 11:03 PM