Hey scotty, I've got a 1998 BMW 328i, and the code P0340 pops up. I replaced the sensor with a non OEM replacement and the code still pops up. The car tends to have a rough idle going up and down to 500 and 700 rpms.
See below: you should only use OEM for sensors
https://www.obd-codes.com/p0340
https://www.carparts.com/blog/code-p0340-camshaft-position-sensor-a-circuit-malfunction/amp/
Yeah I was thinking of that. When I purchased the car which was like 2 weeks ago, the guy told me it came with anew sensor, and I just now found out the sensor Is $30 brand new. Not good. Thanks for the help!
Actually, it turns out that I'm only getting 2.5 volts when I'm supposed to get 5 volts to the sensor. Don't know what the problem is now, maybe bad wiring on problem with the ecu.