pic PIC16f877A resets due to external noise

Not rated 31,447

Circuit Image

Connect a relay with a PIC microcontroller, and whenever a load is applied to the relay contacts, the PIC16F877A resets. This issue has been partially resolved by triggering another relay from the basic relay attached to the PIC, but this is not a complete solution. An explanation is sought regarding why the PIC is affected by the relay's electrical noise and what occurs that causes the PIC to reset. It has been noted that this problem does not occur with the Atmel 89C51 microcontroller using the same relay interfacing circuit. The circuit works fine without any load connected to the relay, and no resets occur. A schematic would help visualize the implementation better than a series of textual descriptions. It is suggested to replace the 1N4148 diode with a Schottky barrier diode like the 1N5819 and to add a capacitor (around 10 µF) across the diode. Previous experiences indicate that the problem may stem from power supply collapse, so adding a 10 µF capacitor on the Vdd power rail could resolve the issue. To prevent latch-up, an RCR network is recommended, as noted in the microcontroller's datasheet. Suggestions have also included increasing the capacitor to 100 µF and ensuring proper grounding. It is important to consider that every cable or trace has some resistance, which can lead to a voltage drop, causing the ground to be at a higher potential than 0 volts. The use of a Schottky diode is suggested to alleviate flyback pulses from the relay coil since typical flyback energy can require significant pulse current capability, which the 1N4148 may not handle effectively. Proper design practices are critical, including good grounding, decoupling, power supply filtering, and layout. The grounding should not just be a simple connection; it needs to account for current flow and impedance, as this can lead to offset voltages. It is crucial to consider the relay's switching characteristics, the current it handles, and whether the relay switch side is isolated from the coil. If they share a common ground, substantial currents during switching could cause ground bounce, impacting the microcontroller and other components. Bypass capacitors should be placed across the PIC power and ground pins to prevent power glitches and ground transients. The use of 100 nF capacitors is minimal, and larger capacitors (e.g., 10 µF) should be considered for better stability, especially at the input of the voltage regulator.

To address the issue of the PIC16F877A resetting when a load is placed on the relay contacts, it is essential to implement a robust circuit design that mitigates the effects of electrical noise and voltage fluctuations caused by the relay operation. A schematic diagram would illustrate the connections and components effectively, enhancing understanding of the circuit's layout.

1. **Relay and Diode Configuration**: Utilize a relay rated for the load being switched, ensuring that it can handle the inrush current without causing excessive voltage spikes. Replace the standard 1N4148 diode with a Schottky diode such as the 1N5819 to provide faster response times and lower forward voltage drop, which is crucial for handling flyback voltage generated during relay coil deactivation.

2. **Capacitance for Stability**: Place a capacitor across the diode, starting with a value of 10 µF, to absorb transient voltage spikes. Additionally, consider using a larger capacitor (100 µF) on the Vdd power rail to stabilize the voltage supplied to the PIC, especially during the relay's switching.

3. **Grounding and Layout Considerations**: Ensure that all grounds are properly connected, avoiding ground loops that could introduce noise. Use a star grounding configuration to minimize impedance and voltage drops. Pay attention to the layout of traces; keep high-current paths away from sensitive components like the PIC.

4. **Decoupling Capacitors**: Install decoupling capacitors (100 nF and larger) directly across the power and ground pins of the PIC. This will help filter out high-frequency noise and provide a stable voltage during rapid switching events within the microcontroller.

5. **RCR Network Implementation**: To prevent latch-up, implement an RCR network as suggested by Microchip in the PIC datasheet. This network will help manage the transient responses of the circuit, ensuring the microcontroller remains stable during operation.

By systematically addressing these points, the issues associated with the PIC16F877A resetting can be effectively mitigated, leading to a more reliable operation of the relay control circuit.Connect Relay with pic microcontroller and whenever I put Load on Relay`s Contacts PIC16f877a resets. I some time solve this problem by triggering another relay from basic relay attached to PIC. But this is not a solution. Can any one describes Why pic is affected with this relay spark. And what is really happening which causes pic to reset. Following things I have kept in mind while building circuit I never faces such problem in Atmel 89c51 microcontroller with same relay interfacing circuit. It is PIC who goes reset every time. But if do not connect any load to relay the circuit works fine. No reset occurs. Can any-one describes what is the issue with PIC 1. A schematic helps visualize what has been implemented, far better than a series of textual bullet points. 2. Replace the 1n4148 with a Schottky barrier diode like the 1n5819. 3. Try putting a capacitor (try 10 uF) across the diode. Anindo Ghosh Mar 12 `13 at 11:08 I have had this problem before. It was because of the collapsing on the power supply. Put a 10 uF capacitor on the Vdd power rail, and most probably your problem will be solved. Also, to avoid SR latch-up, as @Kaz noted, Microchip suggest an RCR network. Look for this information in the datasheet of your microcontroller. abdullah kahraman Mar 12 `13 at 11:23 @AbdulRehman Try increasing the capacitor to 100uF. For the replacement on 1N4148, search for "Flyback diode". About grounding. Every cable/trace has a resistance, but very small. However, with sufficient current, there can be a voltage drop. This means the ground will be at a higher potential than 0 volts. abdullah kahraman Mar 12 `13 at 12:41 @AbdulRehman While several excellent inputs have been provided already, hence my prior comment may be irrelevant, my suggestion for a Schottky comes from trying to alleviate flyback pulses from the relay coil at the source.

Typical flyback energy can require 1 to several amps of pulse current capability in the diode, 4148 doesn`t manage that. Also, the lower the diode voltage, the earlier in the pulse the bypass begins. Finally, between the Schottky and the capacitor, the impulse absorption would be more robust. A flyback diode as others suggested is really what you need there. Anindo Ghosh Mar 12 `13 at 16:37 This kind of symptom is to be expected from a number of bad design practises, including bad grounding, bad decoupling, bad power supply filtering, and bad layout.

You didn`t say much about this, which means you didn`t think much about grounding and it is therefore a possible problem. Just connecting everything to a ground net would be fine if nothing has any ground current. Of course various parts do. This current times the impedance back to the one point you get to call ground causes a offset voltage.

Don`t just think of ground in terms of DC. DC is the easy part. Consider the series inductance of any connection and then the high frequency ground return currents that run accross that connection. What is the relay switching Where does the current it is switching run Is the relay switch side completely isolated from the coil, or do they share a common ground If the latter, the substantial currents when the relay switches on its load could be causing ground bounce at the micro or other parts of the system.

This is clearly a problem in your case. You put 100 nF caps on both sides of the regulator, but you completely forgot to put bypass caps accross the PIC power and ground pins. This can cause power glitches local to the PIC when it switches internally, and can cause local ground glitches when those current transients travel along the ground net back to somewhere they can finally loop back to the supply.

You at least seem to have thought about this, but then only implemented it partially. 100 nF if pretty skimpy, particularly for the input of the regulator. I like to put 10 µF at the input of a regulator, 🔗 External reference