I've created an electronic board to control a joystick (Yoke) using a PIC18f4550. The uController communicates with the computer via USB and send/receive all necessary data information to control 2 DC motors (2 axis). It's working fine and the control circuitry is self-powered. I have in the same board a couple of L6203 to control each DC motor. Also I've put a separated supply to the motors (24v) but with all with common ground.
The problem is that whenever I turn ON or OFF the 24v power supply, the PIC resets. It's not always but most of times it does reset. I've already made all sort of tests and modifications but nothing seems to change. With an oscilloscope I did not see anything in the PIC +5v line. It remains constant. WDT, BOR and MCLRE are all OFF.
Here are some pics of the main blocks:
As you can see the uC generates two different PWM signals which goes through 4081 logic ports. There I can choose whether the driver turns the DC motor to the left or to the right. There is also another Driver block but its just the same of this one.
I've already tried to add some filters on the 24v supply and also on the USB line (+5v). I've tried to put some decoupling capacitors (0.1uf) in both VDD-VSS pins of the PIC. I've tried changing the DC 24v power supply from a switched one to a linear one. Even turning the power supply with low voltage (adjusted to 1v) does not seem to make any difference.
Also, sometimes playing the game with it, the joystick stops responding (freezes) without disconnecting. I dont know if has something to do with the first problem.
I've already tried to add extra +5v line to the circuit so it does not depend on USB supply. Does anyone know what could it be?
EDIT: Another funny thing: if a leave VCC jack disconnected (no 24v in the circuit). Then if I just TOUCH the positive pin of the jack with the red probe of my power supply TURNED OFF, the PIC disconnects from USB and reconnect just after. It does not reset but the USB loose connection for a moment (i can hear that USB disconnected sound). Strange that the power supply is off and I just touch one of the terminals (positive) to the board and it does that.