PIC18F452 Controlling Circuit Hangs or Displays Garbagge

Thread Starter

umarfarooqleo

Joined Dec 4, 2012
10
hi..... i made a controlling circuit using PIC18F452. the circuit takes 2 temperature sensing through thermocouples.it displays the temperature on 16x2 LCD and operates 3 relays of 6V DC which further operate 3 AC Relays of 220V AC accordingly!
i have attached the PCB Diagram with thread.

my problem is that when my circuit turns the any of the 3 relays, it do either of the following things:
1) it restarts.
or
2) it hangs.
or
3) it continues operating but shows garbage things on LCD .
or
4) sometimes it works perfectly fine for an hour or a day and then hangs!

i m finding the problem for 20 days but failing.
i also used WDT which removed the problem number 2 of hangs but problem 1 and problem 3 are still there.
some electronics friends of mine suggest that its because of the AC part of Circuit which my Microcontroller is Operating.
plz help.
the circuit in image has 2 parts. 1 used to operate relays and the other part is connected with microcontroller to display and take input of interrupts and turn circuit off!
 

Attachments

Sensacell

Joined Jun 19, 2012
3,432
1) it restarts.
or
2) it hangs.
or
3) it continues operating but shows garbage things on LCD .
or
4) sometimes it works perfectly fine for an hour or a day and then hangs!
Sounds like transient voltage spike problems to me- what do those relays drive? I'll bet they drive some inductive loads like motors, solenoids etc.?

Try running it with the AC relay portion disconnected, does it still crash?

Add some MOV's or snubbers on the relay contacts to suppress the nasty mess that occurs when the contacts open under load.
 

debjit625

Joined Apr 17, 2010
790
I am almost sure that you have any loose connection in your circuit if your circuit sometimes works perfectly fine for an hour or a day.Have you made it on a breadboard ? Check the oscillator connection and power connection PIC18F452 have two Vdd and Vss pin for power you need to power them both and also the MCLR pin for the reset connection it should be connected to Vdd using a pull up resistor if it got disconnected by any mean it will reset or hang as its floating.

I dont know about your power source,if you think its the cause use a battery to check.

Good Luck
 

spinnaker

Joined Oct 29, 2009
7,830
You will need to do a lot more troubleshooting on your own. Ideas as of the problem can be provided but they are just guesses.

One way to solve this is to break the project down into smaller pieces for both code and hardware. Build a small test circuit if you must.

But one big issue with LCDs is how fast data is sent to the display. You might want to play with those delays.
 

ErnieM

Joined Apr 24, 2011
8,377
The WDT should only trigger when something catastrophic has happened in your code. If it *seems* to make things better it is only a band aid at best.

It sure sounds like voltage spikes from the relays are causing the trouble. How rock solid is your power supply bypassing? Can you look at it with a scope, especially when the relays are turning on or off? Do you have catch diodes or any snubber on the relays?

Got a schematic? That's also needed besides a layout.

On the layout I see what I thing is a 1,000 uf on the PIC power leads. You would also need a 0.1 uF there as large value caps have a poor high frequency response and can let short glitches pass all day.
 

Thread Starter

umarfarooqleo

Joined Dec 4, 2012
10
Sounds like transient voltage spike problems to me- what do those relays drive? I'll bet they drive some inductive loads like motors, solenoids etc.?

Try running it with the AC relay portion disconnected, does it still crash?

Add some MOV's or snubbers on the relay contacts to suppress the nasty mess that occurs when the contacts open under load.
u r right. relays drive electrical Valves to turn on and off the supply of natural gas to the boiler. n an ignition solenoid too.
dissconnecting the ac portion doesnt crash the circuit!
i have 2 questions from u....
1) what are MOV and snubbers? what type of them should i use???? plz guide!
2) realys are used to isolate circuits. i m using 2 set of relays to completely isolate my DC portion with AC portion. if relays are doing so, then it means they are not isolating the circuit???? but we studied relays isolate and me using 2 set of relays as shown in attachment of PDF with thread!
 

Thread Starter

umarfarooqleo

Joined Dec 4, 2012
10
I am almost sure that you have any loose connection in your circuit if your circuit sometimes works perfectly fine for an hour or a day.Have you made it on a breadboard ? Check the oscillator connection and power connection PIC18F452 have two Vdd and Vss pin for power you need to power them both and also the MCLR pin for the reset connection it should be connected to Vdd using a pull up resistor if it got disconnected by any mean it will reset or hang as its floating.

I dont know about your power source,if you think its the cause use a battery to check.

Good Luck
no lose connections are there. i checked 100 times! even replaced twice n thrice my microcontroller, ULN, crystal oscillator, Relays....
DC supply is made from AC Input to the circuit! using transfomer then bridge then LM2576-5. MCLR 10k res to pull up. Vdd Vss all correct.
plz check the attached PDF in the thread! waiting for ur help
 

Thread Starter

umarfarooqleo

Joined Dec 4, 2012
10
The WDT should only trigger when something catastrophic has happened in your code. If it *seems* to make things better it is only a band aid at best.

It sure sounds like voltage spikes from the relays are causing the trouble. How rock solid is your power supply bypassing? Can you look at it with a scope, especially when the relays are turning on or off? Do you have catch diodes or any snubber on the relays?

Got a schematic? That's also needed besides a layout.

On the layout I see what I thing is a 1,000 uf on the PIC power leads. You would also need a 0.1 uF there as large value caps have a poor high frequency response and can let short glitches pass all day.
i will check with oscilloscope the spikes.
i have catch diodes with my relays.
and i will test this 0.1uF thing too coz I think this could help!
schematic attached
 

Attachments

ErnieM

Joined Apr 24, 2011
8,377
Sorry I can't read your schematic file, can you make a pdf or such?

I see what you did with the relays. I wonder if you can remove the 220V power to the 2nd set of relays to see if the problem goes away (though I strongly believe those relays are not the issue it is always good to rule things out).

I would look at the 5V relays as the source of the problem. A relay can hurt you two ways:when you turn it on the surge of current makes the 5 volt power glitch down,tripping the brownout of the PIC, or just resetting it, or worse, making it hang. When you turn it off it makes a big voltage glitch unless you have something to contain the energy,and I see diodes in the proper position.

You should NOT see the 5V power change when the relay goes on, and the drive at the UNL2003 should rise just a diode above 5V at turn off.

The only *possible* issue I see in your layout is the power goes first to the PIC and then to the relays, I would have led each of these portions separately back to the 1000uF cap so the relay had less chance to affect the PIC. However, the layout as is should work anyway.

You may also want to write a simple program that is affected by this problem, say after a second delay you turn on relay 1, delay, relay 2 on, then 3, then 1 off, then 2 off, then 3 off, repeat. Something you can write in 5 minutes that causes the glitch.
 

Thread Starter

umarfarooqleo

Joined Dec 4, 2012
10
Sorry I can't read your schematic file, can you make a pdf or such?

I see what you did with the relays. I wonder if you can remove the 220V power to the 2nd set of relays to see if the problem goes away (though I strongly believe those relays are not the issue it is always good to rule things out).

I would look at the 5V relays as the source of the problem. A relay can hurt you two ways:when you turn it on the surge of current makes the 5 volt power glitch down,tripping the brownout of the PIC, or just resetting it, or worse, making it hang. When you turn it off it makes a big voltage glitch unless you have something to contain the energy,and I see diodes in the proper position.

You should NOT see the 5V power change when the relay goes on, and the drive at the UNL2003 should rise just a diode above 5V at turn off.

The only *possible* issue I see in your layout is the power goes first to the PIC and then to the relays, I would have led each of these portions separately back to the 1000uF cap so the relay had less chance to affect the PIC. However, the layout as is should work anyway.

You may also want to write a simple program that is affected by this problem, say after a second delay you turn on relay 1, delay, relay 2 on, then 3, then 1 off, then 2 off, then 3 off, repeat. Something you can write in 5 minutes that causes the glitch.
sir ur suggestion of 0.1 uf solved many problems of mine.... temperature sensing become accurate coz i inserted a 0.1uf at termocouple connection. also inserted a 0.1uf capacitor at PIC Vss & Vdd. it DECREASED the problem of random hangs very much!
now the Problems that still exists are:
1) random restarts (not restarts from line 1 of code but starts from the while loop or somewhere else)
2) garbage values on LCD Screen sometimes.....

ill also check ur these suggestions in a day or 2!
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,377
I still need to see the schematic in a form I can read such as PDF before any other comments are possible.

Have you done anything to eliminate this being a software problem by giving it a very simple foolproof program to run where you can be very sure you are not doing anything like a stack overflow or a corrupt interrupt service (because you don't use any).
 

mdvrajkot

Joined Jun 13, 2013
8
Hello,

I am facing the same problem in PIC18f4520.

I have interfaced the electro-mechanical relay with the controller and also used the optoisolator. The diode is also connected across the relay. When I run the circuit with out any load, the circuit works perfectly. But when I connect the AC load ( Solenoid Valve - 230 V, 2A), I found some problems. The problems are

1. LCD displays some garbage value
2. Program restarts ( It restarts from while loop !!!! )

I have tried the decoupling capacitors on power supply section. Please suggest me to solve this problem
 

tshuck

Joined Oct 18, 2012
3,534
Hello,

I am facing the same problem in PIC18f4520.

I have interfaced the electro-mechanical relay with the controller and also used the optoisolator. The diode is also connected across the relay. When I run the circuit with out any load, the circuit works perfectly. But when I connect the AC load ( Solenoid Valve - 230 V, 2A), I found some problems. The problems are

1. LCD displays some garbage value
2. Program restarts ( It restarts from while loop !!!! )

I have tried the decoupling capacitors on power supply section. Please suggest me to solve this problem
Please, do not attempt to resurrect a thread just so you can hijack it.

Start a new thread. Also, provide a schematic and, possibly, a picture of the circuit. What are you powering your microcontroller and relays with?

Again, don't respond here, start a new thread, or ask a moderator to move this one for you...
 
Top