I think it's a hardware problem, if I unplug the board and plug it back in again after I've reprogrammed it, then it works fine.
Also if I touch a scope probe on XOut then it works fine too, I'm guessing it's a capacitance problem, but I can't work out why it starts working if I plug it in again?