Thank you for the suggestion John. At the time of the problem I tried EVERYTHING - caps, grounding the motor casing, separate battery supplies for PIC circuit and motor, etc. Seemed the the PIC was just too close to the motor itself (I had no control over this). But by repeating the commands constantly (especially the TRIS commands to keep inputs as inputs and outs as outs) and the HIGHs as HIGHs, etc., the problem vanished. I also had another motor problem where the HPWM was set to a specific duty cycle and intermittently become an output HIGH or output LOW. Again, after setting the HPWM, I constantly repeated the command in other parts where the program would go and that fixed it. Of course the program took more memory, but that wasn't an issue.