Atmega328p hang issue

Go To Last Post
133 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looks like there was no account for creepage on this board.With mains voltage you need clearance around the tracks that carry it - especially around the relays. Start with 6mm. This is required for safety.

 

Why the copper fills on both sides of the pcb? You really only need one on the solder side.

 

No bypass caps on the mega328. The pcb layout is less than optimal - I'd suggest (for your safety) you scrap this board and carefully re-lay a new one. I'd be putting the realys at the end of the pcb rather than in the middle.

 

Last Edited: Fri. Aug 16, 2019 - 12:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Kartman,

 

I have used Opto-couplers in My Design, As we know this Opto couler Isolate the Input stage(MCU) and out Put Stage(Relay Section).So that Whatever things happens in the Out put doesn't reflect On the input stage. we can use Either AC related or DC related Application.

 

As usual, for proper grounding, used copper on Both sides,  this is 2 layer PCB but if we go with for 4 layers, copper must be used on both sides. I think copper pouring is not the proper reason for hang the controller while running.

 

Because,

 

same PCB is running well in another Application with Another Code, no hanging issues there, but why this happens here, we don't know.

 

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your opto couplers do nothing in your design - why? The ground is shared, so there is absolutely no advantage. Relays provide the galvanic isolation anyways.

 

 

Whatever things happens in the Out put doesn't reflect On the input stage.

You hope. Unfortunately the real world has capacitance. Because your copper pour goes close to the relay contacts, you've got plenty of coupling for transients to get into your circuit. It is also illegal is most western countries and unsafe if the relays are switching mains power. Accept that your pcb layout is bad - very bad in fact and learn from it. Have a look at the circuit board for a modern washing machine ,dryer or dishwasher and see how they do it. They're cost driven, so they don't do anything they don't have to. There's also product liability, so they'll follow the required standards. So, if they put slots in the pcb or do anything that adds cost - it's for a good reason.

 

The copper pours on both sides are useless without proper stitching between the two layers. For your application, copper pour on one side of the pcb should be more than adequate. 

 

 I think copper pouring is not the proper reason for hang the controller while running

How does the other application differ? How have you proven this? On one hand you're asking for assistance to solve your problem, but on the other you're very sure of what isn't the problem. Rule out the obvious problems and you're left with what isn't obvious.

 

From what we've been told so far, the problem happens when the AC lamp is switched. Here's some suggestions as to what I'd probably do if faced with the same problem:

 

1. Address the obvious problems - no bypass cap close to the mega328. Ensure the BOD is enabled.

2. Have a flashing led so you can easily see when the controller has crashed.

3. switch the AC lamp at a regular interval

4. run the above test. Does the unit crash or misbehave? Repeat the test a number of times to see if you can repeat the problem.

5. if it does fail, then I'd remove the relay that switches the AC (or wire a separate one) from the pcb and run wires. Ensure the AC wiring is protected so you don't electrocute yourself.

6. run test again. Any difference? This would prove/disprove my assertion.

 

For the test, make sure you don't have any other wiring (apart from the mains input) to the board. Any mains borne transients will usually find their way back via external wiring.

 

 

Other things to consider:

 

Any wiring from external sources needs to be protected. There's mention of a loop detector input - how is that protected from ESD,EMI etc? How does your software filter this input? What is considered a valid input? Is it a 1us pulse or maybe a pulse at least 300ms wide? How would your code determine the difference?

 

Layout of the wiring in your system - don't run high current and/or mains wiring close to your signal wiring. Ensure there is adequate separation. 

 

 

 

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

 

Any wiring from external sources needs to be protected. There's mention of a loop detector input - how is that protected from ESD,EMI etc? How does your software filter this input? What is considered a valid input? Is it a 1us pulse or maybe a pulse at least 300ms wide? How would your code determine the difference?

 

Layout of the wiring in your system - don't run high current and/or mains wiring close to your signal wiring. Ensure there is adequate separation. 

 

There is an induction loop which tells us when any metal detected. There is a relay in that induction loop. Relay gets high and output will short when any metal detects. So in the output i have connected my I/O pin and ground. 

 

When any metal detects I/O pin and GND will get short that's it. Is it fine right?

 

My controller will get the power through UPS.

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nowhere near enough information. How long is the wiring between the relay and the input? Understand that every bit of wire is an antenna - it can radiate and receive. It is also a point where ESD can enter.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
How long is the wiring between the relay and the input?

 

It is about 60cm. Can i know how to avoid this ESD and EMI?

Last Edited: Tue. Aug 20, 2019 - 06:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ram kumar wrote:
It is about 60cm

60cm...antenna.

 

But anyway, I saw the board, the layout is very bad....just accept it as kartman said, redraw eveything from scratch, and please take a look at the Good PCB design suggestion...there is plenty on the internet. forgetting the decoupling capacitors suggests that this is your first ever PCB ? then at this point you should stay away from AC stuff and just consider playing around with 1.8 - 12V DC sources...other than this I think the guys here gave their best, you cant just keep arguing for a week, asking questions and not accepting any answer or willing to do any suggestion. think again, re-draw the board from the scratch and only then you could get a valid suggestion.

 

other than this, this is just a waste of time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ram kumar wrote:
Can i know how to avoid this ESD and EMI?

 

As I said, its better to go read a little bit about hardware design, good PCB practices...etc.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Moe123 wrote:

ram kumar wrote:
It is about 60cm

60cm...antenna.

 

But anyway, I saw the board, the layout is very bad....just accept it as kartman said, redraw eveything from scratch, and please take a look at the Good PCB design suggestion...there is plenty on the internet. forgetting the decoupling capacitors suggests that this is your first ever PCB ? then at this point you should stay away from AC stuff and just consider playing around with 1.8 - 12V DC sources...other than this I think the guys here gave their best, you cant just keep arguing for a week, asking questions and not accepting any answer or willing to do any suggestion. think again, re-draw the board from the scratch and only then you could get a valid suggestion.

 

other than this, this is just a waste of time.

 

Okay we will come back with new design. Thank you for valuable suggestions. 

 

Moe123 wrote:
As I said, its better to go read a little bit about hardware design, good PCB practices...etc.

 

Yes correct. We will work on it.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Kartman,

 

Modifications done as per your's suggestions.

 

please comment on this.

 

By pass caps added and Copper removed near by Relays.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The opto’s won’t do much will they since you have no galvanic isolation. Yes,it was fun reverse engineering the schematic from the pcb.
What are your clearance distances?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

thanks Kartman,

 

Line to Line ,thru pin, smd pin, thru via ...... 10mils

 

Line to Shape ...... 20 mils

 

and 

 

How can I modify to get Galvanic Isolation.

 

 

           

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Srinivas_nipun wrote:
How can I modify to get Galvanic Isolation.

 

Please take a look here at this presentation:

http://pwrsocevents.com/wp-conte...

 

and this article:

 

https://www.allaboutcircuits.com...

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks  Moe123 ,

 

so that need to separate signal ground(opto coupler input) and  relay ground(opto-coupler out ) to get the Galvonic Isolation.

 

 I am getting 5V from AC supply and converted into 3.3V, this 3.3V used for opto coopler input and Micro controller.5V for Relay with common Ground for Both 5V and 3.3V.

 

    How can I modify to separate Grounds.

 

Also,

 

Can I remove the Opto Coupler and Atmega328P input can Drive the Relay.(both Atmega and Relay at 5V).

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

here is My Schematics Diagram.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

is it just me who thinks that the schematic is inconsistent with the board or am I missing something ?

 

I suppose the ATmega_Power is the going to Vcc, you have 2 caps with 100nF, the datasheet suggests only one cap 100nF Vcc <-->GND and as close as possible to the MCU, I dont see in the Board  C8 and C9. Does Eagle ignore the missing components when doing (what i suppose you did) a forward annotation, 

 

the Atmega_Power global label, where does it go ?? I dont think you have reworked your board as we suggested, you messed it up again.

 

Please confirm that this schematic is related to your board the one that you posted! its very dangerous to change something in the board without changing your schematic.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

to the freaks who used Eagle: does eagle ignore such errors like missing components in the board but they are still in the schematic ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks  Moe123 ,

you can find C8 on the silk screen bottom(ssb), Pin No 7 is the VCC and Pin No:8 is GND, I placed C8 Between 7&8. " Atmega_Power global label "  Modified as VCC

 

My tool is Allegro 16.6.

 

CN9 is used for power option to MCU, either 3.3V or 5V.

 

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you confirm that you made your board according to your schematic....same labels...same everything ?? or you were just deleting here and there and then adding random components ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes, whatever in the Schematics is on the Board.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


- AREF is left floating, decouple it to 100nF.

- the other Vcc should also be decoupled to 100nF... (sorry but its very difficult to read your schematic...incosistency is everywhere).

 

Page 6 via

http://ww1.microchip.com/downloa...

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

is it ok now

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

here  VCC is Either 5V or 3.3V

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The optos on the relays do nothing to improve your circuit, get rid of them. The optos on your inputs share 0V - that is also next to useless. If you want galvanic isolation, then have a separate isolated power supply for it. Something else you need to consider is stray currents across your power supply module - they're going to flow through your circuit and back out via routes you don't expect. You might want to add a capacitor to ensure these are shunted to earth.

 

Get your schematic correct first, then think about your pcb.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks kartman,

 

I will modify as your suggestions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Some suggestions:

 

A good PCB requires a right schematic. Skipping the schematic and going straightforward to make your board is one of the biggest mistakes, this leads to inconsistency all over the project. You cannot just make global labels in the schematic and then ignore them totally in the board. also you can just jump around fixing the board without fixing FIRST the schematic. You have used ATmega328p, but it seems that you havent studied well the datasheet of this chip, you also skipped one of the most important datasheets which adresses the basics for hardware consideration when using this exact chip.

 

Making a PCB that works is something, Making a good PCB with good design is something else. In your case, its even more dangerous since you are dealing with high current, the outcome would be a disaster. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks  Moe123 ,

 

I will update My schematics at the Earlist

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi guys,

 

Schematics Modified as per your's valuable suggestions.

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PD2,3 look like they go out into the real world. How are you protecting them?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

to Interface Relay Module like PC0,PC1,PC2...only.

 

suggest me , if other circuit than Relay circuit, How to  protect.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

also,

 

ADC5 is used for Loop Detector  , which is from out side, if the loop detector, detect the vehicle(metal), it gives low input  otherwise high input, these inputs reads by ADC5.

 

if Atmega operated with 3.3V, Loop detector gives high(+5V), so that we used +3.3v to 5V voltage level converter.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Much better, however, never cross wires like this with a dot.  If the dot become hard to see (say a photocopy or pasted into a document) it will be easy to miss the connection.  Use 3-way connecting intersections & there will be no possible mistake.

Here, it might appear the 3.3V arrow only connects to the capacitor...when it's just signal lines, it would be even easier to miss.

 

 

Also, add a vcc arrow near C8, it becomes a lot easier to see where Vcc is coming from.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Thu. Aug 22, 2019 - 03:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks guys,

 

schematics attached, 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Move the Vcc slightly over, so not to cause possible confusion as to the connection. You might say these wires just happen to be crossing & Vcc only connects to the cap

 

 

This is how you want it---then there is NO possibility of any mix-up

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi 

 

schematics diagram attached, comments please , can I Start PCB.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

You might want to tell us about all the inputs and outputs - what you expect to connect to them, length of wiring, voltage etc. Then we might be able to help.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

You noticed this is the 5th or 6th time you are making the same mistake ?

 

 

Please dont mix:

- the 3V3 is the output of the LDO

- 5 V is the output of the step-down converter

 

Now you are feeding both the 5V and 3V3 to the connector, I suppose the CN9 is a switch or whatever to choose what you are feeding to MCU. why you are complicating it so much like this ? Vcc is a pin name in the MCU. 3V3 or 5V are two different voltage level. if you think its best then just choose another name for the Vcc(label NOT pin).

 

I also think the concept in general is bad. almost all the pins goes out to real world, nothing mounted on the PCB directly but through connectors....more wires, more EMI and noise, I doubt if this concept will ever pass the EMI test ?!.

 

Last Edited: Fri. Aug 23, 2019 - 07:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks  Moe123 ,

 

Label VCC changed as MCU_Power, 

 

Actually I want to Run MCU with 3.3V, In case it is not , then I can use 5V, 5V also using for Relay.In my Previous Design , used 3.3V as MCU power but did not Drive the Relay(same circuit), so that If 3.3V fails then , I can use 5V ,this is My concept. Please suggest on this.

 

Only ADC5(for loop detector), PD2, PD3 (only future use) are going out side, Please suggest , how to protect  from noise.

 

 

 

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Srinivas_nipun wrote:

thanks  Moe123 ,

 

Label VCC changed as MCU_Power, 

 

Actually I want to Run MCU with 3.3V, In case it is not , then I can use 5V, 5V also using for Relay.In my Previous Design , used 3.3V as MCU power but did not Drive the Relay(same circuit), so that If 3.3V fails then , I can use 5V ,this is My concept. Please suggest on this.

 

Only ADC5(for loop detector), PD2, PD3 (only future use) are going out side, Please suggest , how to protect  from noise.

 

 

 

 

 

 

But you are driving almost all the others with the same label "(Vcc)", so not just the MCU ?

  

 

So how does this work ?. Please open the schematic, take a calm look at it...trace the your 3V3...5V...etc and look if it make sense.

 

Srinivas_nipun wrote:

 

Actually I want to Run MCU with 3.3V, In case it is not , then I can use 5V, 5V also using for Relay.In my Previous Design , used 3.3V as MCU power but did not Drive the Relay(same circuit), so that If 3.3V fails then , I can use 5V ,this is My concept. Please suggest on this.

 

 

 

Then you SHOULD, before going further, to test it in real life.... see how can you drive this relay, if its 5V, then its 5V. Have you ever tried to test this concept in a small protytype ? just connect some wires and check!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I will change VCC as MCU power, It is okay , fine.

 

Board Already working fine in the Field, but some times  MCU hang, when the Power supply is off and On it is working , that is the issue, As per the Kartman, PCB Layout is Bad.

 

Also, found no galvanic isolation by opto couplers, then I Removed in my schematics. Now I am Expecting with Existing schematics, with 3.3V as MCU power , MCU input can drive the Relay or Not.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Srinivas_nipun wrote:
MCU input can drive the Relay or Not.

 

 

We cant tell you forsure! you have to check it by yourself. connect some wire, do some testing and read the datasheet of the relay. only then you can be sure.

 

Side note: What is your background in HW design/ Electronics ?? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Srinivas_nipun wrote:
but some times  MCU hang

 

But kartman also and the others traced a lot of problems and bad layout PCB. Kartman also gave you a lot of points why you should not only be bothered by the hang issue but also ommit and fix the obvious problem.

 

Are we going to have this same conversation all over again ?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Side note: What is your background in HW design/ Electronics ?? 

 

Both.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

then start do some HW testing.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bad layout PCB

 

I used copper near by Relays, so that I removed My Lay out

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lets not just move away from the topic. It was not just the bad layout, check your 1st schematic and compare it with your 10th edition schematic. Now if you would like some help here then start to do some testing and re-evaluate your concept + taking the suggestions from the others, not just replying without doing some real work.

 

We dont get pay here, its a helping forum from volunteers!

Last Edited: Fri. Aug 23, 2019 - 09:08 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks Moe123

 

My first Schematics attached, Tested  Proto type Board. It did not drive the Relay with 3.3V as MCU power.

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

also Existing PCB Image Attached. hanging issue found in this PCB

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is Q1 doing? Q2,3 are reversed! I think there is too much guesswork happening here.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks kartman ,

 

if PC0 is high, then Q1 is on, then Relay coil(pin2) get the ground Path, then it is On.

if PC0 is at low, then Q1 is off , then relay is Off.

 

 

Pages