Ah, the camshaft position sensor. A real grievance of mine, I had to replace it twice.
My symptoms were strange, my 320Ci with an automatic transmission would stall if I was too quick switching between Drive - Reverse, then Drive again (like when turning around in a drive way), I scanned and saw the code P0304, replaced the sensor, and the car seemed fine for a while. But I still did not get that VANOS power boost at lower RPMs. I was suspecting a worn-out VANOS unit at this point, but did further digging. I did a test drive car with an OBDII-scanner and revealed the sensor output was not what it should have been. The same P-code did not re-appear, but others did, BMW-specific ones such as "41 Signal, inlet-camshaft sensor" where 41 is hexadecimal for 65.
So I ponied up the $200 or whatever it was for a new Genuine BMW sensor, and the problems I had had the last two or so years all vanished.