Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] PIC Malfunction when other devices are switched on/off

Status
Not open for further replies.

leorickings

Junior Member level 1
Junior Member level 1
Joined
Oct 18, 2013
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
197
Hi all, I have come across a really weird phenomena... I am working with a project with PIC16F877A,
which sounds a buzzer, lights up two LEDs (different output ports), lights up a 24V pilot lamp (optocoupled) and energizes a relay (transistor) when it detects a signal.

The power supply is a 24Vdc power supply, sourced from office mains (230Vac), and i built a switching regulator (24Vdc to 5Vdc, 3A) for the system.

It was all working fine until I found out that, whenever someone randomly switches on or off anything in the office (lights, aircond, fans, anything), the system will malfunction. The buzzer will sound, the pilot lamp will turn on, but only one of the LED lights up. Which means, something meddled the microcontroller, not the microcontroller picking up a false signal input.

Anyone has similar experience? Please help!

- - - Updated - - -

btw i had tried powering the circuit with a UPS, not plugged into the office mains. The problem still occurs. So it's not any current backflowing/inrush/spike/sag/ whatever to do with instataneous over current. I suspect it's something to do with magnetic field which disturbs the microcontroller. Please advice...
 

It may be related to the switching regulator, may be it is not stable enough to prevent the PIC from Brownout reset. use proper power line filtering.
 

1. Introduce emi filter (Differential mode pi filter) in between voltage regulator (24V to5V) and line transformer (230V to 24V). Use 1uH inductor series with two 1uF capacitor parallel( both sides of the inductor)
2. Check the output filter capacitor of voltage regulator is enough, Put a 0.1 uF capacitor parallel to the electrolytic capacitor.
3. Introduce 0.1 uF capacitor very close to microcontroller vcc pin
 

Hi,

In an office enviroment Fluorescent lights are a well known cause of problems like that.

However as said its more likely to be weak design on your board in terms of shielding of the whole board or any inputs , used or unused.
Ideally set all unused pins to outputs, used shielded cable on any input lines, how close to the pic is the crystal, have you followed the datasheets pcb example for it.
If you have done all the points mentioned in the previous replies but are still getting problems, then post your full circuit with a pictures of both sides of your board and associate wiring.
 

I have Brown out reset configured to OFF in the config word. How do I achieve proper power line filtering? I don't think it is the problem with the power, since the same problem occurs when i power the system with a UPS, not connected to the mains. Purely run on the UPS backup battery.

- - - Updated - - -

How do I shield the circuit? Is it something to do with EMI?

The circuit is currently a prototype, on a breadboard. The crystal (20MHz) is 20mm away from the circuit on the breadboard.

the PIC16F877A datasheet does not mention about precautions on the PCB layout, and this prototype is now on breadboard where components are placed faraway from each other to ease my work whenever I need to modify it.

I have never experienced this before with any type of microcontroller... not even with the lesser pins PIC nor the atmel 805X series...

- - - Updated - - -

1. Introduce emi filter (Differential mode pi filter) in between voltage regulator (24V to5V) and line transformer (230V to 24V). Use 1uH inductor series with two 1uF capacitor parallel( both sides of the inductor)
2. Check the output filter capacitor of voltage regulator is enough, Put a 0.1 uF capacitor parallel to the electrolytic capacitor.
3. Introduce 0.1 uF capacitor very close to microcontroller vcc pin

I have a power supply module (already built) which converts the 230Vac to 24Vdc, only after the power supply comes my switching regulator (24Vdc to 5Vdc), so I do not have access directly to the line transformer. Where should i connect the emi filter?

I have a 0.1uF capacitor parallel to the Vcc and Vss, right beside the Vcc and Vss pin.

Did i miss out anything?

- - - Updated - - -

Hi,

In an office enviroment Fluorescent lights are a well known cause of problems like that.

However as said its more likely to be weak design on your board in terms of shielding of the whole board or any inputs , used or unused.
Ideally set all unused pins to outputs, used shielded cable on any input lines, how close to the pic is the crystal, have you followed the datasheets pcb example for it.
If you have done all the points mentioned in the previous replies but are still getting problems, then post your full circuit with a pictures of both sides of your board and associate wiring.

What is actually causing the malfunction? if I switch on/off a light from a distant room (yes, distanced) such as the toilet, the problem occurs too.
 

The crystal and its associated 33pf capacitors must be as close as possible to the micro. All put 0.1uF ceramic between the power pins of the micro again as close as possible. 20 MHz on breadboard gives problem. Use 4 MHz for testing. Maybe the transformer (step down) you are using for power supply is not of good quality.
 

Hi,

Think you highlighted the cause of the problem, the Breadboard and the wires / component spacing - they will be acting as antenna , picking up every bit of electrical noise.

Using crystals and their caps on a breadboard also can cause problems due to poor contact with their fine leads - better to solder the three parts together and fit some short thicker leads to plug into the breadboard.

No mention of what Inputs to the pic you are using and how long their leads are.

You really need a pcb, with input leads shielded/filtered as needed.

Again without any more specific details hard to advise.
 

The crystal and its associated 33pf capacitors must be as close as possible to the micro. All put 0.1uF ceramic between the power pins of the micro again as close as possible. 20 MHz on breadboard gives problem. Use 4 MHz for testing. Maybe the transformer (step down) you are using for power supply is not of good quality.

What does it mean 20MHz gives problem? I've always used 20MHz for PIC16F877A but never encountered this...
So do I get another 4MHz oscillator to replace the 20MHz crystasl?

- - - Updated - - -

Hi,

Think you highlighted the cause of the problem, the Breadboard and the wires / component spacing - they will be acting as antenna , picking up every bit of electrical noise.

Using crystals and their caps on a breadboard also can cause problems due to poor contact with their fine leads - better to solder the three parts together and fit some short thicker leads to plug into the breadboard.

No mention of what Inputs to the pic you are using and how long their leads are.

You really need a pcb, with input leads shielded/filtered as needed.

Again without any more specific details hard to advise.


Hi,

Thanks for pointing the antenna issue, I never knew that...
So if making them on PCB solves the problem, will the same case occur again?

What does it mean to have poor contact for the crystal? I checked their connections and they are fine connected.
By 'lead', do you mean their "legs"? The components are all just plugged onto the breadboard as is, I never trim their "legs", at most I bent the "legs" to fit across the slots on the breadboard. Does that contribute to the problem?

I have 5 inputs, 3 from push buttons, normally open, one side connected to the +5Vcc of the PIC, another side connected to the ports and parallel to a resistor to ground.

one input from a common ground 24Vdc signal, which I conditioned the signal with voltage divider with a capacitor across the portion I take input (the voltage divider 5V part).
one last input from a 230Vac signal, which I conditioned using transformerless power supply method, then optocoupled. So no common ground.
I had tried removing the 24Vdc input and 230Vac circuits from the system but the problem persists.

Sometimes when I turn on the system, thePIC initializes. The LEDs for the initialization code lights up like normal, but nothing works after that. No input triggers anything, it looks just frozen. I push the reset button, everything from the PIC goes off, when I release it, it initializes, and freezes again.

What is input leads shielded? Do I apply materials to the "legs"?
 

Is it possible to test all I/O on Scope/CRO during switching condition which gives u all answer. If no Scope then just try simple LED blinking code & test it, then start for ur code in which adding one by one routine.This exercise give u condition where problem occur
 

Is it possible to test all I/O on Scope/CRO during switching condition which gives u all answer. If no Scope then just try simple LED blinking code & test it, then start for ur code in which adding one by one routine.This exercise give u condition where problem occur

Thanks, I found the problem with the program freezing using the watchdog timer... Turns out the oscillator was faulty.

Now back to the malfuction... Even with the oscillator replaced, the PIC still goes haywire when someone turns on or off anything randomly..
 

Hi,

Thanks for pointing the antenna issue, I never knew that...
So if making them on PCB solves the problem, will the same case occur again?

What does it mean to have poor contact for the crystal? I checked their connections and they are fine connected.
By 'lead', do you mean their "legs"? The components are all just plugged onto the breadboard as is, I never trim their "legs", at most I bent the "legs" to fit across the slots on the breadboard. Does that contribute to the problem?

I have 5 inputs, 3 from push buttons, normally open, one side connected to the +5Vcc of the PIC, another side connected to the ports and parallel to a resistor to ground.
Many other advanced ways avaliable -
https://www.digikey.com/us/en/techzone/microcontroller/resources/articles/protecting-inputs-in-digital-electronics.html

one input from a common ground 24Vdc signal, which I conditioned the signal with voltage divider with a capacitor across the portion I take input (the voltage divider 5V part).
one last input from a 230Vac signal, which I conditioned using transformerless power supply method, then optocoupled. So no common ground.
I had tried removing the 24Vdc input and 230Vac circuits from the system but the problem persists.

Sometimes when I turn on the system, thePIC initializes. The LEDs for the initialization code lights up like normal, but nothing works after that. No input triggers anything, it looks just frozen. I push the reset button, everything from the PIC goes off, when I release it, it initializes, and freezes again.

What is input leads shielded? Do I apply materials to the "legs"?

Hi.

Making a pcb will Reduce such issues, however pcb design is an art in itself and good ones are multi layered with ground planes etc etc , so diy single sided ones are just a beginning, though still a dramatic improvement on a breadboard with loads of load loose wires.

You could try placing the whole circuit in a large tin or steel box that is connected to earth and see if that kind of shielding improves things.


All input leads should be made with shielded cable with the shield connected to true ground /earth not 0v.
https://www.newark.com/pdfs/techarticles/alphaWire/USC.pdf

Also try a simple input filter right up to the pics pin on all input leads, say 220r in series and 100nf to ground.

The point about the crystal is that its leads /legs/pins are very thin, much thinner than a standard breadboard wire, so they can easily loose contact with the breadboard.
With thier signal being so small and a such a high frequency even the slightest movement can cause the contact to loose its signal, even momentary is enough to knock out the pic.
 

leo
To speed things up I'd recommend you post your full circuit. I suspect it may help.
 

Thanks guys, I will be making the PCB for the system, if the problem persists I will post the circuit here.

Is there any precaution on placement of components in designing the PCB?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top