How do I explain the code? P0340? Thats the CAM sensor right?cam sensor is used by the engine to get an initial startup timing when cranckshaft position is not yet established.
So I suppose when the engine is running it could be the camschaft sensor has become not in use.
Rough idling can be caused by a bad vacuum hose to the air intake or EGR problem (when it has one).
Being that it runs the same with cam sensor unplugged, I betting it's dead.Slow performance could mean the engine is in limp home mode, a safety feature to prevent the engine from getting severely damaged.
P0340 means: Camshaft position sensor (A) circuit bank 1. So it has an electrical circuit problem, so maybe short circuit, open line, circuit to ground etc.
Depending on your engine type it is positioned somewhere at the cam shaft, at the top half of the engine.
You could look into the Hyundai service site for all the info you need.
You need to register and log in but it is free.
Timing light not be of much value for crank-cam timing,, for this, std visual of crank at TDC and visual of both cam gear to valve cover reference marks be the truth to belt timing.Crank sensor changed, how about the blade part, there are posts about that also causing problems if worn.
2.7 does not use "blade",,, it is a sensor stuck in hole on outside of block with toothed ring bolted to crankshaft
Old school induction timing light using cyclinder one pick up could freeze marks on crank pulley and timing cover., need to find spec for degrees BTC.