Another reset culprit is stack overflow. If you have too many nested gosubs, or gosubs without returns, the PIC will reset.