can you post your code to see what can be the cause of lockup.

you can clear watch dog timer... not sure it will resolve the problem here. CLEARWDT or NOP can do what you need.