Welcome to the garage.
P0340 is a cam sensor problem. The sensor sits in the right cylinder head (seen from drivers position) at the fwd side. Easy to change. But check the connector first for tight fit and eventual dirty contact pins.
JEEP Grand Cherokee 4.7 Lmtd 2004
HID 8000K in low and fog / Quad Squad member
KYB Gas-a-Just shocks / Pirelli Scorpion ATR 245/65/17 - Transgo reprogramming shiftkit.