PIC32 intermittent MCLR reset - involves electromagnets

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
wave.jaco
Posts: 28
Joined: Sat Aug 01, 2015 2:45 am
Location: South Africa

PIC32 intermittent MCLR reset - involves electromagnets

Post by wave.jaco » Thu Mar 23, 2017 12:37 am

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.
Forum - image 1.jpg
PIC MCLR pin and decoupling capacitors
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:
Forum - image 2.JPG
Electromagnet switching circuit
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.

I strongly suspect that the resets have something to do with the electromagnets being switched and a possible voltage spike propagating through VDD and thus into the PIC's MCLR-pin, causing the reset. But given the precautions I've already taken, 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.

User avatar
DanV
Posts: 333
Joined: Sat Apr 25, 2015 9:29 am

Re: PIC32 intermittent MCLR reset - involves electromagnets

Post by DanV » Thu Mar 23, 2017 7:11 am

Your flyback diode should be strapped right across the electromagnet as close as possible.
I assume it is not shown in your diagram. If it is, then the placement is likely wrong.

wave.jaco
Posts: 28
Joined: Sat Aug 01, 2015 2:45 am
Location: South Africa

Re: PIC32 intermittent MCLR reset - involves electromagnets

Post by wave.jaco » Thu Mar 23, 2017 10:17 am

The problem is that the electromagnets are somewhat difficult to reach and are widely spread across the system they are installed in. Therefore, all signal wires to the electromagnets come together at a central connection block where they are easily connected to the control circuitry. Therefore, the closest location that is practically possible to have the diodes is at the connection block. From there it is easily between 2 to 10 meters length of cable to the respective electromagnets.

Regarding the orientation of the diodes, they are connected exactly as indicated in the circuit diagram.

User avatar
phalanx
Non-SFE Guru
Posts: 1958
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: PIC32 intermittent MCLR reset - involves electromagnets

Post by phalanx » Fri Mar 24, 2017 12:50 pm

Do you have access to a scope so you can watch what's happening to your power supply and MCLR lines? I would not be surprised if you found spikes occurring somewhere in your system.

I agree with DanV that ideally your flyback diode should be as close to the electromagnet as possible to keep the residual circulating currents away from your controller board. Can you better illustrate the physical connection of the leads to your electromagnets and flyback diodes?

In an application like this where you are switching lots of inductive loads, I would have used an isolated DC-DC converter to power the microcontroller side of the system in addition to isolating the low power control signals from the power electronics.

On an unrelated not because I doubt is has anything to do with your problem at hand, is there are reason why you are running the 74HC595 shift registers at 5V instead of 3V like the rest of the system?

-Bill

wave.jaco
Posts: 28
Joined: Sat Aug 01, 2015 2:45 am
Location: South Africa

Re: PIC32 intermittent MCLR reset - involves electromagnets

Post by wave.jaco » Mon Mar 27, 2017 5:50 am

Unfortunately I do not have access to a scope to see what's happening on the power supply and MCLR lines. I could try to make a plan about that, though, although I will not be able to get access to the system for another few weeks due to logistical issues.

I also totally agree that the ideal location for the flyback diodes are as close to the electromagnets as possible. Some details on the connections to the electromagnets and flyback diodes: The electromagnets are at fixed locations and control a series of air channels by opening and closing a series of small valves. The one end of each of the electromagnets is connected to a common negative signal (connected to GND - which is also the same GND signal used by all the electronics throughout the whole system). The other end of each electromagnet (the positive/12 VDC connection) is first terminated in a central connection block (a Krone connection block, to be more specific) where all the connections from the electromagnets come together. The respective control signals from the control circuitry are also terminated in this connection block, where each of these control signals is connected to its respective electromagnet connection. The electromagnets themselves are hard to access and are placed in such a manner that connecting the flyback diodes directly to them would be very tedious and somewhat impractical.

The distance from the control circuitry to the Krone block is between 0.3 to 1 meter. As stated previously, the distance from the Krone block to the actual electromagnets range between 2 to 10 meters. The actual leads from the control circuitry and to the electromagnets are standard 22-24 AWG leads, bundled in groups of 8 and connected with SIP Molex-type connectors onto SIP headers on the control circuitry PCBs. The flyback diodes, switching transistors and SIP headers are all connected on the same PCB as illustrated in the diagram in my initial post and are all within 3-5 cm from one another.

The suggestion for an isolated DC-DC converter to power the microcontroller sounds like a very good idea. Just for clarification - what exactly is meant by "isolated"? Do you mean that the DC-DC converter is there to power only the microcontroller? I haven't looked at DC-DC converter options yet, but I recall that some are available as an IC. Would such an IC be adequate for this purpose, or is a more sophisticated DC-DC converter necessary?

There is just one thing that bothers me a bit. The MCLR pin on the PIC is an active-low signal. With the MCLR pin connected directly to VDD (3.5 V), that would mean that the MCLR event is triggered by a quick drop in VDD. 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 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.

Regarding powering of the 74HC595 shift registers - there is no specific reason that it must be 5 V instead of 3 V. I just thought it well to have it on the same power line as some of the other logic ICs in the system (also on 5 V), and also for the switching done by the transistors in order to ensure that the output voltage of the shift registers is enough to turn on the NMOS transistors used in the switching. I will take a look at this and see if it might be possible/feasible to power all the electronics on 3 V instead of 5 V. Do you foresee a possible issue with running the shift registers at 5 V instead of 3 V?

User avatar
phalanx
Non-SFE Guru
Posts: 1958
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: PIC32 intermittent MCLR reset - involves electromagnets

Post by phalanx » Mon Mar 27, 2017 9:33 am

wave.jaco wrote:The suggestion for an isolated DC-DC converter to power the microcontroller sounds like a very good idea. Just for clarification - what exactly is meant by "isolated"? Do you mean that the DC-DC converter is there to power only the microcontroller? I haven't looked at DC-DC converter options yet, but I recall that some are available as an IC. Would such an IC be adequate for this purpose, or is a more sophisticated DC-DC converter necessary?
In regards to this application, isolation would provide a completely separate power supply for your low voltage/low power devices (separate from your field wiring) that will eliminate ground loops. There's more to it than just using an isolated power supply however. You should also isolate the power electronics from the rest of your low power control circuitry through optocouplers or some form of galvanic isolation.
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.
This is what I'm suspecting is the problem. There are probably spikes being generated by turning off the electromagnets and their flyback diode is connected to the same GND in the same circuit board as the control electronics. If the path to GND isn't very low impedance, there can be ground bounce and other artifacts present which are large enough in magnitude to affect the operation of the microcontroller. This is why it's important to completely isolate your control electronics from the power electronics in applications where you know you will be driving large or numerous inductive loads. I maintain that it's important for you to get access to an oscilloscope otherwise most of this will remain speculation.
Regarding powering of the 74HC595 shift registers - there is no specific reason that it must be 5 V instead of 3 V. I just thought it well to have it on the same power line as some of the other logic ICs in the system (also on 5 V), and also for the switching done by the transistors in order to ensure that the output voltage of the shift registers is enough to turn on the NMOS transistors used in the switching. I will take a look at this and see if it might be possible/feasible to power all the electronics on 3 V instead of 5 V. Do you foresee a possible issue with running the shift registers at 5 V instead of 3 V?
There are plenty of logic level transistors that will operate perfectly fine in your application. You are only switching a max of 1.2mA from the gate of your PMOS which is trivial for an application like this. I would be looking to redesign this in such a manner that your shift registers are driving an optocoupler which then takes the place of your NMOS gate drivers. The isolated side of the optocoupler should have its own low impedance connection to GND separate from the board that contains your MCU and other low power parts.

Ultimately you can make this work with 3V and 5V rails but it's unnecessary and complicates your board.

-Bill

Post Reply