(Solved) ATMEGA protection from voltage spikes

Good morning.
I was looking in the forum for answers but I couldn't find anything. First of all I am pretty new to electronics and Arduino, I am learning by myself so my electronic knowledge is quite limited, please be patient.

Now to the problem. I am designing a project where a standalone ATMEGA328P-AU drives a P-ch MOSFET to enable a DC motor. The DC motor is not driven directly by the MOSFET but it has it's own mechanical switch and everything needs to be powered by a 2-3S LiPo battery (so be able to deal with 8-12v input roughly).
The problem I'm dealing with is how to prevent the flywheel current from the motor to damage the ATMEGA when the mechanical switch is turned off.
I added a very basic schematic. Everything right of the dashed line is out of my reach so I can't modify it.
My the solution I thought of (not tested yet due to lack of components) is to put a flyback diode on the output and a TVS diode on the 5V line after the voltage regulator as can be seen in the schematic. My question is if this arrangement is sufficient to protect the ATMEGA and if not what can I change?
Note1: the voltage regulator is an AMS1117-5.0
Note2: the circuit is simplified, there are some capacitors on the voltage regulator and a transistor driving the MOSFET, I just kept it simple.
Thanks in advance.

Luca

A diode in parallel with the motor brushes is all you need to control the flyback impulse, and a low side switch is far easier to implement. No need for the TVS diode, which is in the wrong place in your diagram.

In the diagram below, put the switch between "Vsupply" and the motor. Be sure to use a logic-level N-MOSFET.
'

3 Likes

Hi jremington, thanks a lot for your response.
While I agree that a flyback diode would be the ideal solution unfortunately in my project it would be too inconvenient to modify the switch and motor circuit (the part I drew right of the dashed line), it's simply out of my reach, that's why I'm looking for a workaround. The problem is that when the circuit is working the mosfet is ON most of the times and the switch is controlling the motor, so when the switch goes OFF there's no way for the current to flow back to the motor. I did some measurements with the oscilloscope and on the 8-12V line there are peaks (in the range of microseconds) that ranges from -10V to +30V and the ATMEGA shuts down and resets.
Any idea on how I can solve the issue without touching the switch-motor circuit?
Thanks

Luca

Use a relay instead of the P-MOSFET, so there is complete electrical isolation of the two circuits.

1 Like

Actually there wouldn't be a complete isolation since the ATMEGA is powered (through a voltage regulator) from the same battery that powers the motor, and I'm afraid the spikes are coming from that direction.
On your first reply you told me that the TVS was in the wrong place... Would it be useful somewhere else in my schematic or am I going down the wrong path?
Thanks

Luca

Is this the actual circuit, or a trimmed down version?

It is impossible to tell. Opening the switch can lead to inductive spikes of thousands of volts, and you can have an arc right across the switch contacts.

In any case, the TVS diode goes across the battery, not the voltage regulator output. Study this tutorial: Transient Voltage Suppression in Automotive Applications

2 Likes

We're all dug deep into taking care of a problem that we yet don't know exist.

Have OP checked out the datasheet for the motor and switch ciruit, if a flyback diode already is incorporated?

While it's good practice to take precaution, one also have to be pragmatic not to see a problem where there isn't.

Good point.

This thread boils down to the OP being unwilling to dismantle the motor installation, diagnose the actual problem, and fix it in situ.

The various poorly advised bandaids all seem to have failed, as might be expected.

1 Like

Well we have no information on the battery (ie a link).

You can protect the arduino by powering it from a rechargeable 6V battery that is trickle charged from the main battery - but what charges that?

Then you can protect the control part - by using a relay instead of a mosfet.

Hi everyone.
It's my fault for not being specific on what I want to do, so I'll explain better:
the project is for an Airsoft Arena where people can rent our airsoft guns (ASG) and play. We have a good number of ASGs and what I want to achieve is a device that is mounted on each one of them which receives a signal from basecamp through an HC-12 module, turning the ASGs on at the beginning of the game and off at the end of it to avoid people from firing the ASGs when they're not supposed to.
The ASGs themselves are pretty simple, a LiPo battery (usually 7.4v or 11.1v, 2000mAh, 20-30C), a trigger that is basically a switch and an electric motor that runs the mechanism (no flyback diodes installed). The problem is that the trigger and motor cables are out of reach without disassembling the ASG completely and due to the number of ASGs and the fact that we replace them often it would be absolutely impractical to modify all of them, let alone the lack of space for additional components and the fact that we sell the used ones (that would require to modify them back to their original state).
For the same reasons a dedicated battery for the ATMEGA would be impractical as well due to the number of batteries required.
My solution was to put the device we're talking about on the connector between the battery and the ASG so when they are commanded off it will simply cut the power. I thought about a MOSFET also due to the space it takes (the smaller the device, the better) and because it's often used in the ASG world.
All the wireless and MOSFET part of my device works well, the power is there when they're commanded on and vice versa as intended. I only encounter problems when the ASG is firing due to the voltage spikes created by the motor so I wanted to address that problem.

As far as I understand a TVS in my schematic would be better placed in parallel with the flyback diode, correct?
Would a N-Ch MOSFET in low side switching be any better? I have also considered relays but the space available in the battery compartment of the ASG is very limited unfortunately, with a MOSFET I was able to get a PCB that is 60x25mm and being pretty flat helps a lot.
I know they might look like stupid questions but I'm not super familiar with all these components being a newbie.
Thanks for any help

Luca

This is a simplified version, there's a NPN transistor driving the MOSFET and some capacitors 10nF and 100nF both at the input and output of the voltage regulator. There's also the HC-12 module (see my post #11) connected via serial interface to the ATMEGA.

I'm sceptical to this:

How do you know it exists and is a real problem? Have you equipped an airgun and tested it out?

Don't try to solve a problem that isn't there.

Yes I did. After two or three rounds fired the ATMEGA resets. I connected an oscilloscope on the motor V+ and GND and measured short peaks (microseconds) ranging from -10v to +35v. On the voltage regulator output the spikes goes from 0v to 10v (where it should be 5v to power the ATMEGA).

Note: the motor is charging a spring through a gearbox. This spring is loaded and released for every round fired by the ASG so the motor load is not constant through the firing cycle. It's putting more effort towards the end of the spring, while almost no effort when the spring is released because the gearbox effectively spins without load.
I noticed that while the spring is loading the voltage decreases (voltage sag I believe) from the normal 8v down to around 6.5-7v and then goes back to 8v when the spring is releases. The voltage line on the oscilloscope is not clean and there's a lot of noise.
The highest peaks I was talking about before however are seen when the trigger is released.

Thanks for clarifying. Would you be kind and add those decoupling caps

to the schematics and upload here?

Right now, is the space in the airgun crammed?


I uploaded the schematic from EasyEda, probably more useful. My mistake on the caps, they're 10uF and 100uF, not "nF".
Please let me know if something is not clear.. I'm not an expert so I understand my schematic is probably not the best. It makes sense to me but it's not the ideal layout.

The space is pretty crammed, yes. The motor is in the grip and there's barely any space for it's own cables. The trigger is closed in the gearbox and there isn't much space there either. On top of that opening the gearbox on one ASG is a pain, let alone doing it on 20 or so of them :sweat_smile:

Thanks for any help

Luca

For me this is better than a diagram.

I would deal with these spikes this way: If space allows: change C1 (cap closest to Vin) to a electrolyte 220uF 50 V, or higher F. Also let C1 and C7 switch place. Absorbing a spike is one way.

2 x Zeners connected back to back in parallel with the motor circuitry (instead of the single diode). Value of these depends sole on highest voltage in primary. You stated 8-12 V, but if charging takes place it will be even higher than 12 V. An example is 1N5349BG, 12 + 1.2 = 13.2 but with 5% tolerance that combo can begin to conduct already at 12.5 V, and you don't want the charge current go through the zeners.

Thanks a lot!!
So I uploaded the new schematic according to your suggestions (hopefully I got them right). I put the zener diodes you talked about just to see if the schematic is correct, however I'll probably have to change them because, while the battery will be removed during charge, a fully charged 3S LiPo should be 12.6v so sligtly above the Zener value. I'll look for something with a bit more margin.

On a separate note, I highlighted in yellow this voltage divider/low pass filter I created to monitor the battery voltage (the idea is to turn the MOSFET and thus the ASG off if the voltage is too low to avoid damaging the battery). Could this be another way for the spikes to make their way to the ATMEGA? I put the low pass filter for that reason but I'm not sure it's enough.

How about the highlighted one (power dissipation 3W)?

Thanks

Luca

Yeah Vf =1.5 should work fine. These are SMD components, are you comfortable with SMD?

Not if I need to solder myself, however my plan was to find a PTH diode with the same characteristics like the 1N5927BRLG, do the tests and then have the final PCBs printed and assembled online with the SMD components, if that makes any sense.

1 Like