I am working on a project that involves a lot of switching of electromagnets.
The switching is controlled by a PIC32MX6xx-series microcontroller, which determines the required states of 80x 12 VDC electromagnets (each drawing about 15-200 mA) and outputs this data to a series of interconnected 74HC595 shift registers. These shift registers' outputs each switches a MOSFET on/off, which in turn switches its respective electromagnet.
The problem that I am experiencing is that, when the electromagnets are switched, the PIC resets intermittently. There is no particular switching sequence/load that causes this reset - it happens completely at random. At times it takes about 30 seconds of switching to reset it, and at some other times almost 15 minutes.
What I do know is that it is the MCLR-reset that takes place - I determined this by monitoring the RCON register, where the EXTR-flag bit (MCLR reset event) is set on each such reset. This is the initial circuit of the PIC, with specific focus on the MCLR-pin and the decoupling capacitors as recommended by the PIC's datasheet.
It can be seen from the diagram, that there is a 1k resistor between GND and the switch, as well as a 10k pull-up resistor on the MCLR-pin. After noting the recommendation of a capacitor at the MCLR-pin to prevent unintentional resets, I added a 100 nF ceramic capacitor between the MCLR-pin and GND. Yet still, the resets still occur intermittently, although it seems as if the interval between resets were longer than without the capacitor.
In the hope to eliminate the reset occurrence, I replaced the 1k resistor between the switch and GND, as well as the 10k resistor between the MCLR-pin and VDD with 0-ohm resistors (short circuits). This would ensure that the MCLR-pin is always connected to VDD. The 100 nF capacitor was also still present. Thus, essentially the only component connected to the MCLR-pin is the 100 nF capacitor between the MCLR-pin and GND. Yet still, the intermittent resets continue to occur.
The system is powered by an industrial transformer with a 380 VAC, 3-phase input and 12 VDC output. This 12 VDC output is then the input to two LM1085 voltage regulators - one with a 5 V output (powering all logic ICs) and the other a 3.3 V output (powering the PIC). A surge suppressing circuit consisting of a MOV and snubber diode is also in place right before the voltage regulator inputs (12 VDC inputs).
The MOSFET switch circuit for each electromagnet is as follows:
As can be seen, the switching circuit is a high-side switching circuit (common negative) topology, using both an NMOS and PMOS transistor for the switching. Note that there is a snubber/flyback diode in place as well. The LED is purely there to indicate the state of the electromagnet. This is the circuit used for every electromagnet in the system.
Since the MCLR pin is an active-low signal, the only event that I can foresee that would trigger the reset event is if there is a momentary drop in VDD (since the MCLR pin is directly connected to VDD). However, since VDD is provided by an LM1085 voltage regulator, my guess would be that a sudden "positive" voltage spike on the 12 VDC supply wouldn't cause such a drop in the voltage regulator's output. Therefore, the only explanation that I can come up with is that the supply voltage is probably momentarily dropping to such a level that causes a low enough voltage on the VDD line that triggers the MCLR reset event, although I cannot quite figure out how that would happen. The only other possibility in my view could be that a voltage spike propagates on the GND signal, causing the voltage differential between VDD and GND to become small enough to be within the range considered as a LOW signal on the MCLR line, since the microcontroller's "ground" is momentarily above 0 V during the occurrence of the voltage spike.
Some answers to possible anticipated questions:
- Connecting the flyback diodes directly to the electromagnets is not practical due to the location of the electromagnets. The flyback diodes are therefore placed together with the MOSFET switching circuit on the control circuitry PCB.
- The outputs from the control circuitry are all terminated into a Krone block, where the electromagnets' positive signal lines are also terminated. The distance from the Krone block to the actual electromagnets is anything between 2 to 10 meters.
- I currently do not have access to an oscilloscope in order to see what actually happens on the VDD and MCLR lines.
Given the precautions I've already taken against voltage spikes/surges, what am I still missing? It is absolutely crucial that the PIC doesn't reset intermittently as it currently does.
Inputs, advice and comments will be greatly appreciated.
Thank you in advance.