I have learned about the pic microcontroler for a period of time and have a reasonable amount of knowledge about handling digital electronics. I have worked on basic electronic projects and now I need to work on some commercial applications.

My question is about how to design and build reliable and long lasting circuits. I built a automatic light controller circuit which takes the input from a LDR and displays the value of the analogue reading on a seven segment panel. Then it does some calculations and controls a light through a relay. This circuit needs to be switched on permanently(24 hours a day). The first few months the circuit worked perfectly ,but after about 6 months it started malfunctioning. It showed senseless things on the 7 segment display(it showed just parts of numbers), then it lights the bulb on the indicator LED but it's not switching on the relay.This is not the expected behaviour. The thing is it won't always work that way. Sometimes it works perfectly. Then it starts again to malfunction. There is no exact order in which it works.

Now my question is why do these circuits behave this way. I assume this may be because it works all day without any intervals.This kind of application needs to work all the day. I use PIC because I know about pic only. Is atmal more reliable than pic? (I asked because atmal is used in most of automation applications,more frequently than the pic is used) I need some advice from an expert in digital electronics. How is this kind of industrial applications built? Are there any special rules to follow? How to design more reliable circuits? Any advice or guidance from an expert will be highly appreciated. Thank you...


As it's suggested in the answers,I'll edit my answer by providing additional resources to help figure out the bugs in the design.

Below is an image describing how the circuit looks like after it was built. It's a 12V center tapped transformer which supplies power to the circuit.It's rectified using a half wave rectifier, then regulated using a 7805 IC.

enter image description here

Below is the schematic design.

enter image description here

If any additional information is needed I will provide everything needed. If the program is needed I'll add it. The program is somewhat long.It uses interrupts.

  • 6
    \$\begingroup\$ If you use an IC within it's specified ratings (see datasheet) then almost any manufacturer guarantees a 10 year lifetime. And that is at high temperature. You can blame the components but I think the problem is that there's something unexpected going on in your design. Or maybe one of the chips suffered from an ESD discharge and that is surfacing only now. You need to find the faulty component first before usefull advise can be given. \$\endgroup\$ Feb 16 '16 at 20:28
  • 2
    \$\begingroup\$ In addition to what FakeMoustache said, I doubt the PIC is the source of failure. More than likely it's discrete components or related to the circuit design. \$\endgroup\$ Feb 16 '16 at 20:32
  • 1
    \$\begingroup\$ I have PICs working all the time in many rough places. No issues. Only problem I had was corrosion in plugs and a physically forced electric TFT capacitor with a broken pin. \$\endgroup\$
    – Szidor
    Feb 16 '16 at 20:36
  • 1
    \$\begingroup\$ And BTW I guess you mean Atmel instead of "atmal". Also, PIC is a microC from MicroChip (MicroChip makes them). Atmel is also a microC manufacturer, they make the Atmega microControllers. Both are simply digital ICs made in similar manufacturing processes and having similar reliability. If one was more or less reliable than the other, no one would buy them (at a similar price which they are). \$\endgroup\$ Feb 16 '16 at 20:37
  • 3
    \$\begingroup\$ You need to post a schematic, and ideally a picture of the troubled system. I also doubt your problems are "lifetime expectancy", but rather missing something really basic, like power supply cleanliness or EMI. \$\endgroup\$
    – Techydude
    Feb 16 '16 at 22:08

Before you start thinking about switching, make sure you have a good solid design. You need to start thinking about all the ways you could have problems in your design. A good way to do this is to stop thinking about a microprocessor as a "magic box" that you put code into and does what you tell it to and start thinking about how it functions, on a gate level and system level. You need to keep your microprocessor happy.

  1. Power - If the microprocessors power is not clean, it will not function correctly. That means looking at the PCB design and making sure you have a good low inductance pathway from your power supply and making sure you have adequate power caps close to the chip. Monitor and measure the power on a design you know doesn't work with an oscilloscope and voltmeter, is it the power? Do you see the problem happen when there is a spike or dip in the power? Do you see spikes or dips on your Vcc line?
  2. Code\Clock - Is there a fault in the code that is causing it to not function correctly? Have you looked at the code in an intermittent unit? Does it verify (match) the code that you have now? Are you getting flash degradation? What about the clock? Power can actually degrade the clock over time. Is your clock what it needs to be? If you slow the clock down does your code stop functioning?
  3. Environmental protection. Are you operating the microprocessor in the specs that it was designed for? Is the temperature constant in the units that fail? Are they in an area with environmental factors such as dust,EMI,ESD or Temperature that could cause it to fail. Are your inputs protected to the outside world, could people be zapping the unit? Heat will do bad things to electronics over time. Get a thermal camera an see if everything is normal

What you really need to do is find the failure mechanism, you need to know why it is failing. Once you know why its failing you can address the problem. If you cant find that then you will have to make your design invincible to stop any problems from occurring. If you don't you could switch microprocessors and still have the same problems. If you do want to switch, ST makes some great microprocessors that are more suited for industrial applications.

  • 2
    \$\begingroup\$ Add radiation to the list of environmental factors. Ionizing radiation of most kinds (atomic, photonic, etc) can cause electronics to experience SEU or single-event upsets which result in garbled output. \$\endgroup\$
    – rdtsc
    Feb 17 '16 at 5:29
  • \$\begingroup\$ As u suggested I updated my answer adding the additional resources. the schematic design and a image if the circuit. please can u figure out any bugs in the design. \$\endgroup\$ Feb 17 '16 at 7:41
  • \$\begingroup\$ Thanks a lot. I got a idea and more knowledge about dessing more reliable circuits. I have to learn more before starting building commercial applicatuons. Thanks a lot. Accepted as the answer. \$\endgroup\$ Feb 17 '16 at 11:32
  • \$\begingroup\$ I kind of assume that radiation is not a factor, but if your running these things next to a nuclear plant or other source of radiation (or in space, it becomes a serious issue with a commercial MCU having a few SEU's a week, even Rad hard processors will have SEU's). A regular MCU could have an SEU but I would think it would be on the order of years for the probability of that in a normal environment. \$\endgroup\$
    – Voltage Spike
    Feb 17 '16 at 19:07
  • \$\begingroup\$ @danial weaber a 7805 is not going to stop a power dropout with the caps you have. Lets say the power draw from the 5V reg is 100mA max (you can run these calcs if you measure your actual max current), that would be like a 50Ohm load. Your cap is 10uf so tau=RC -> tau = 50*10uf = 0.5msec. That is approxamately the time it would take for you to have an issue. You may want to buy a cheap chinese "wall wart" for a few bucks that can tolerate some droppout from the AC mains. Or you could use a DC to DC converter that might be more tolerant. What does your grounding look like on the PCB? \$\endgroup\$
    – Voltage Spike
    Feb 17 '16 at 19:24

Since you don't say, I question how the troubled circuit is physically constructed - since this sounds like EXACTLY the type of problem that is typically seen when someone who does not solder constructs a circuit on a temporary "push to connect" breadboard and leaves it for a few months.

If this resembles your case, there's your problem; if not, I'd still suspect poor connections, but it becomes a "skill at soldering" issue more than a "failure to solder anything" issue.

  • 3
    \$\begingroup\$ To add to this improper soldering technique can produce joints with poor mechanical strength and other issues that cause the joint to fail after a much shortened period of time. \$\endgroup\$
    – crasic
    Feb 17 '16 at 1:06
  • \$\begingroup\$ Thanks a lot. I updated my answer and if u can figure out any bug in the design that would be very thankful. \$\endgroup\$ Feb 17 '16 at 7:43
  • \$\begingroup\$ The solderings look good, no effects to be seen in the soldering. Can it be a problm related to the program. But then how does it work good at a time \$\endgroup\$ Feb 17 '16 at 8:34
  • \$\begingroup\$ ...provide a picture of the solder side? As for programming issues that sometimes work, sometimes don't, various options were already mentioned in comments on the question. And there's the socket the IC is in as a solderless potential failure point (between the socket and the IC pins.) Sockets are sometimes a good idea, but can cause problems. If the problems get better for a while if you remove and replace the IC, that might be part of the problem. ...also, your power supply filter capacitors look a bit on the small side - all of 33 pF between the bridge and the regulator input? Really? \$\endgroup\$
    – Ecnerwal
    Feb 17 '16 at 11:58

You don't have a decoupling capacitor on the PIC supply, but on a small board like this you'll probably get away with it. You might also want to add brown-out protection so that the PIC is reset if the voltage drops below a threshold.

But I'd be looking at your code.

For starters, you should have the watchdog enabled on the micro. If the code stops working properly, the watchdog will restart it.

Most likely though, you've just got a bug somewhere. As an embedded software engineer by profession, I'd guess it's related to the interrupts, because that's where beginners most often make mistakes. As a beginner though, there's a massive set of mistakes you can make in code, so that's just the first place I'd look. (Don't be offended - I made a lot of those mistakes myself, including when I really should have known better. ;-)

  • \$\begingroup\$ +1 thanks a lot. Now I understand that i have done some mistakes. I need to learn a lot more before starting to build commercial applications. \$\endgroup\$ Feb 19 '16 at 20:43

I agree with the comments that you need a nice fat capacitor either side of the 7805. Especially with a relay there. I expect this is the root issue. I'd add a decoupling capacitor across the PIC's power supply lines too.

I would also be looking for dry joints.

I would also be thoroughly checking my program, and using whatever watchdog facility is there.

But here's a couple of interesting bits from your question:

It showed senseless things on the 7 segment display (it showed just parts of numbers)

I'd be trying to work out what has happened. Has the PIC crashed for instance?

Now, if I read your schematic correctly, then in order for each of the 7 segment displays to be showing something, and something different and constant on at least two of them, then each of Q1, Q2 and Q3 must have still be being turned on in sequence, and the outputs to the segments must have been correct. This would tell me your PIC is still running at least some of its code, but somehow the digit output has been scrambled. For instance perhaps it's not been given a digit 0-9 to display, but a digit 17 or similar (for which it gets the digit layout from a random memory location).

You say:

it lights the bulb on the indicator LED but it's not switching on the relay

Looking at the schematic, then unless the PIC output is pulsating or something (not impossible as that's also a timer output port), this would have to be either an electrical failure (e.g. dry joint), a PSU issue (see above re capacitors), or the Q4 transistor is (perhaps) not fully saturated. I haven't read the PIC data sheet, but a BC547 has a maximum IC of 100mA (hopefully that's enough to drive your relay and the LED), and hFE of 120 at that sort of level, so you'll need about 1mA in. 10k might therefore be a little much. I might try 3k3.

Further, you have no useful means of debugging. As your display is on all the time, perhaps you could make the final decimal point dot flash once per second (or similar) to indicate all is well.

If I had to take a wild stab in the dark, I would guess that particularly when the relay is on, the circuit is drawing significant current. Because of the lack of a large capacitor on the input side of the 7805, when the AC voltage crosses zero, the 7805 will not be providing any output current (and may indeed be draining the capacitor itself) - from the 7805 data sheet 'The input voltage must remain typically 2.0 V above the output voltage even during the low point on the input ripple voltage'. The voltage on the PIC will therefore be reduced, perhaps enough to crash it. Put a scope of the 5V line next to the PIC and if you don't see anything other than a nice solid 5V line, you know you have an issue.

  • \$\begingroup\$ +1 thanks a lot. This answer gave me a good idea about how to design the circuit and some mistakes i have done. Ill check addind the capasitors and tell the results. \$\endgroup\$ Feb 19 '16 at 20:26

Any time you have erratic behavior in a microprocessor, there are two main sources for the problem. 1) missing or insufficient "bypass" capacitors, 2) "floating" microprocessor pins.
Every "chip" needs to have a bypass cap, right at the chip pin connected to Vcc (+5v).
Any pin not used, must be tied high or low, but never left "floating."

I agree that you are not driving "hard enough" Q4, I recommend 1K for R12.

  • \$\begingroup\$ +1 thanks in the answer. Ill try adding the bipass capasitors. Is it nessesery to assign values for pins that im not using in the design. \$\endgroup\$ Feb 20 '16 at 7:56
  • \$\begingroup\$ The correct word is "decoupling" capacitor, not "bypass". Also agreed that floating pins can do funny stuff. I'd add a third main source - brown-outs or similar dodgy reset conditions. But even then, in this case when you've got a beginner doing complex stuff with interrupts, my money is always on the software. \$\endgroup\$
    – Graham
    Feb 22 '16 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.