Petrol P0340 code adivce required
I have a question before is go any further on the 147, searched the forum but most threads relate to diesels.
Bought 2008 1.6 with noisy variator and flat battery, drove it 40 miles home and when it got past 2500rpm it purred so was happy it was just variator. Got 4 miles from home and Motor control failure appeared on dash and went to limp mode, prior to this no lights or warning whatsoever.
Stripped it and found battery was dead, unable to hold charge, variator was screwed, timing belt slack as hell due to faulty tensioner and totally shot water pump, also 2 worn cams.
Pulled fault codes from it an found 2 relating to battery voltage and P0340 cam sensor.
Spent this afternoon replacing cams, variator and tappets, new water pump and timing belt, new battery.
Engine is timed perfectly and purrs from start up, mechanically its spot on.
Every time i start it it throws up code P0340, cleared it a dozen times and same again p0340.
Now it should be obvious that i need to replace the cam sensor, but i can't get my head round it driving 35 miles without any fault codes or Motor control warning, i put the p0340 down to the slackness in the timing belt throwing the timing out when i drove it home but now it keeps occurring i don't know what to think?
Advise please before i go any further.