RE: CRANKSHAFT POSITION SENSOR (P0335)
Pull your sensor from the engine and check the wiring and connection. I had a camshaft position sensor with a slightly corroded wire that acted like yours is. Check for nicks in the wiring. If you don't see anything check the wiring harness plug for bent, broken, or corroded plugs also.Whether you find an issue or not, use di-electric tune-up grease on the connection when you plug the harness and sensor back together.
Hope it helps.