What sorts of thing can cause an Atmega 328 to reset? (model railway problem)

Apart from interference with the 5v power supply, what other things should I be checking as possibly causing the Atmega 328s to reset. I can see that they are resetting via the start-up LED flash sequence.

I have built 2 Atmega 328s on pieces of strip board as part of a model railway control system. Each board controls about 5 servos and 5 relay modules on the basis of control signals sent by Serial from a Mega. Everything was working fine until we tried running a train on the tracks.

Running the train causes both Atmega 328s to reset occasionally - and not both at the same instant. Presumably the reset is caused by voltage spikes from the train power system as the problem only happens when the train is moving.

AFAIK there is no direct electrical connection between the 12v track power system and the 5v power for the Arduinos, servos and relays. The relays are used to switch the track power to different section of track. The 5v power comes from some mains powered switch-mode power units which (I think) came from China.

This is a traditional 12v DC power system (not DCC) so the under-board wiring and the control panel wiring is (to be kind) complex. There are many situations where the track power wires run parallel to the 5v DC power wires.

None of the I/O pins on the Atemga 328s are used to take inputs apart from the HardwareSerial connection that talks to the Mega. The reset problem has happened even with the serial wires disconnected.

My assumption is that there is induced interference between the 12v wiring and the 5v wiring - although my amateurish attempt to monitor the 5v supply with my oscilloscope did not show anything. However I hardly ever use the 'scope and I may not have been using it to best effect.

My present plan for the next test is to provide a completely separate 5v supply (ideally from a battery) for the 2 Atmega 328s and their servos and relays.

If anyone can suggest other things that are known to cause a reset I would very much appreciate it.

Thanks.

...R

What's powering the servos & relay coils? Is that power shared with the Arduino? Motors & relay coils are usually the source of the problem.

It might be possible to get a "spike" on an I/O pin that causes a reset.

There are many situations where the track power wires run parallel to the 5v DC power wires.

That shouldn't be a problem. You can get indictive or capacitive coupling in to a high-impedance input but power supplies are lower impedance so it's a lot harder to transfer enough energy to cause a problem.

I would carefully check the grounding to ensure that the '328s and tracks etc have their own connections back to the power supply. You want to ensure that there are no "alternate" paths through microcontroller circuits for motor or relay currents to get back to the supply.

You specify Atmega328; are these custom PCBs with that microcontroller or are they Uno R3 Arduino boards? If custom, do you have schematics?

One thing that come to mind as a possibilty if the supplies are completely isolated from each other, and at least one is switch mode in particular, and particularly from China; switch mode supplies and particularly those from china seem to induce, or couple from the mains input (I suspect some minimal galvanic isolation and maybe leakage or a coupling mechanism) highish voltages at high impedance to the dc output jack.

It can be high enough to cause a nasty tingle if grasping the jack and touching ground or another power supply, and can draw a small spark if touched to ground. With a high impednace multimeter I've often measured 50V+ ac from smps jacks to ground. I've also zapped a few IC's and micros and had resets too when using/connecting separate supplies without the commons connected.

It's very easy to couple an unwanted voltage to a highish impedance input, even from a highish impedance source, when it's voltage is "high"

The cure is to tie the various dc 0v supply connections together at a convenient point so that the relative difference between supplies and their circuits is minimal, not floating at a variable high voltage from which it is easy to couple switching spikes, or touch voltages from handling etc.

I've certainly struck similar problems in ship-board installations involving sensitive eqipment, and audio equipment, where a "single point ground" was required, and it may (hopefully!) help in this case.

Can you possibly put a scope on the power going into the AtMega?

Thanks for the Replies so far.

There are a few comments about grounding. I'm not sure if that is general advice or if it is specific to my situation where the ONLY time there is a problem is when a train is running.

The Atmega 328s share the power supply with the relays and servos - and, as above, there is ONLY a problem when a train is running.

One problem I forgot to mention is that there is less interference from a train after it has been in use for a minute or so - which greatly reduces the opportunity to investigate the problem - very frustrating.

As mentioned earlier I have put my 'scope on the 5v supply but not at the power pins of a specific Atmega 328. And, as also mentioned earlier, I and very inexperienced with using a 'scope. This is a model railway club layout and there is very limited time for testing on a club night.

I'm really looking for ideas about how activity on one electrical circuit could transfer to a different electrical circuit sufficient to cause my Atmega 328's to reset.

One overnight thought is whether a voltage spike in the track on top of the board might induce a voltage in the parallel vero-board strips that are under the board and about 15mm below the track?

...R

Have you tried disabling the brownout detection on the ATmega328P ?

srnet:
Have you tried disabling the brownout detection on the ATmega328P ?

That's a brilliant idea, one really worth trying for a process of elimination for supply spikes.

My comments were general, and specific, in terms of if the track spply is isolated from the 5v supply, possibly it could radiate rfi or spikes more strongly, than if it's 0v connection at the supply was single point refernenced to the 5V supply 0v.

Which leads on to my other thought, if the train motors are brushed and don't have a suppression cap and possibly ferrite beads (don't know if this is standard or a standar mod for trains), then they could be radiating "hash" onto the tracks which could then couple onto nearby strip board tracks which act as aerials.

It can be tricky using a scope for certain faultfinding, often they are grounded through the mains supply, and either eliminate a problem, or cause other issues such as grounding things you don't want to, or injecting interference, and also can be tricky to set up triggering to capture related but intermittent events.

But if a general increase in noise level, spikes, or hash can be seen on the 5v supply as the trains move around, or move in certain areas, or perhaps the track noise can be looked at too, an idea of the source noise, or the susceptability of the boards receiving noise could be gained.

It's also possible, but perhaps unlikely that unused i/o pins could be acting as antennas to couple noise into the die. It was certainly std practice on projects I worked on in a previous career that unused pins were pulled low with resistors around 1K, and to use say a 10k pullup or pulldown on active inputs if for any reason they could be disconnected from signal, or signal source could be tri-stated/go high impedance. Perhaps it's also possble to set unused i/o pins as outputs and set low.

Tricky to solve problems like these, trickier from a distance! :slight_smile:

srnet:
Have you tried disabling the brownout detection on the ATmega328P ?

I will certainly examine that.

...R

One of the reasons for suggesting it, as a troubleshooting step, is that it seems unlikly that random electrical noise, from wherever, would always result in a reset.

You would expect, if there was electrical noise was interfering with the processor itself, that there would most often be a lockup, but it appears to be always a reset.

Apart from the brownout detection is not the only other internal source of a reset, the Watchdog ?

From playing with model trains ages ago I remember they like to make sparks when the contact is less than perfect between the train and the rails, and far more so if you actually use overhead power to the trains. That sounds like a possible source of voltage spikes, even on your supply lines. I remember hearing those sparks on at least the AM radio.

Normal decoupling should take care of those spikes, but maybe a pi filter close to your ATmega328 PCB is needed.

I don't have access to the Atmega 328s to check them right now but AFAIK brown-out detection is disabled by default.

Another thought is that the tracks might be inducing a signal in the veroboard strip that is connected to the Atmega 328 reset pin. The reset is pulled high with a 5k6 or 4k7 resistor and is linked to the header for the USB-TTL cable with 0.1µF capacitor.

I think if this is the cause then moving the veroboard further away, or orienting it at right-angles to the tracks might solve the problem. Or maybe a grounded layer of aluminium foil on the underside of the baseboard between the tracks and the Atmega328 board.

Maybe a lower value pullup resistor would help, but I don't know what is the lowest value that would still allow the process of uploading code to trigger a reset.

I will read about Pi Filters

...R

Hi,
I've fought these kind of things for over 50 years :slight_smile:

See this page for more ideas: Arduino-Project-Planning-Electrical - ArduinoInfo

The most basic question is "Where Is Ground"???

If I was working on this, the first thing I would do would be to run a heavy ground wire under the layout from your main control point and around past most of the devices you control. At the control point I would bring all the grounds from all the Arduinos and all the peripherals and the negative terminal of all power supplies together at one point. And I would make sure that was connected to your building electrical ground. You can do that by using a regular power plug with a single wire connected to the round (in USA) 'Green Ground' pin.

RobinWhoKnowsStuff:

Or maybe a grounded layer of aluminium foil on the underside of the baseboard between the tracks and the Atmega328 board.

Or a blank PC board with a copper side insulated from the veroboard.

terryking228:
See this page for more ideas: Arduino-Project-Planning-Electrical - ArduinoInfo

Thanks for the link - it brings things into focus.

At first thought a single GND point does not seem to be feasible because the controlling Mega is on one wooden module and the track layout is divided into 4 modules. At the moment we are testing with two Atmega 328 boards on one of the track modules. The mains to 5v power supply is in another module that will sit on the floor.

I think the best that can be done is to have a single GND point on each module with a decent sized GND cable connecting them. However that may be tidier than the present arrangement.

What's frustrating is not knowing whether all the work that would be involved in re-wiring would solve the problem.

...R

Robin2:
I don’t have access to the Atmega 328s to check them right now but AFAIK brown-out detection is disabled by default.

All official ATmega328P Arduino boards, including the “breadboard” package, have their extended fuse definition for 2.7 V BOD:
http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega328p&LOW=FF&HIGH=DE&EXTENDED=FD&LOCKBIT=0F

Of course, you may have used a custom or 3rd party board definition that uses a different extended fuse value.

Robin2:
I don't have access to the Atmega 328s to check them right now but AFAIK brown-out detection is disabled by default.

Its normally enabled, unless you have disabled it specifically. Minicore does have an option to turn it off when burning a bootloader.

And if its not the BOD, what other internal process can trigger the Atmega 328 to reset ?

srnet:
And if its not the BOD, what other internal process can trigger the Atmega 328 to reset ?

If, by that, you mean that there is no other process then that is welcome news.

...R

Another thought is that the tracks might be inducing a signal in the veroboard strip that is connected to the Atmega 328 reset pin. The reset is pulled high with a 5k6 or 4k7 resistor and is linked to the header for the USB-TTL cable with 0.1µF capacitor.

Did you also include the diode on the reset line?

Robin2:
I'm really looking for ideas about how activity on one electrical circuit could transfer to a different electrical circuit sufficient to cause my Atmega 328's to reset.

Try powering the Arduino from a battery. (Keep the grounds connected). If the problem goes away, you know that the problem is something injected through the power supply. If the problem persists, then the interference is being radiated through the air.

justone:
Did you also include the diode on the reset line?

No. What is the diode for?

SteveMann:
Try powering the Arduino from a battery. (Keep the grounds connected). If the problem goes away, you know that the problem is something injected through the power supply. If the problem persists, then the interference is being radiated through the air.

That's on my to-do list for exactly that reason. Next problem is to find a suitable battery - I don't fancy dragging a 12v lead-acid battery on the bus :slight_smile:

...R