Atmega328 keeps resetting itself if I start PWM

Just for kicks, how about trying no gate resistor. I drive MOSFETs that way from PICs all the time.

Bob
Yeah, I mentioned that in post #9. I'm thinking that if the reset is caused by what he thinks it is caused by, removing R! should have no effect or will make it worse (quicker reset?). Right?
 
- If I do not connect the glow plug there is no reset or hang up. This finding strongly suggests that this is a power supply issue.
Yeah, seems like that. Can you see for sure that there is no reset in that case - just getting at the very, very, unlikely situation where you have some WDT issue.

Also, if you could replace the glow plug with something requiring about the same amount of current, but not using PWM, just straight GPIO and much slower on-off cycles, would you still get a reset?
 

MrSoftware

Joined Oct 29, 2013
2,188
The best glow plug substitute would be a resistor of similar resistance to the glow plug. The ESR would be different, but that would help by taking inductance out of the equation.
 

Andrei Suditu

Joined Jul 27, 2016
52
I belive the transients from switching might upset his PSU?
I mean mosfets have an internal reverse diode.Also it's a good practice(like nearly a must) to have a resistor from a micro to the mosfet gate to avoid burning the uC.
If you are using an Arduino board is clear that somethig is not right with your circuit drive.Maybe some hight voltage spikes keep resetting the Arduino.Also you may try adding a cap between the mosfets Drain and Source to kinda soft out the spikes?
Also if you need simple mosfet drive you can use an optocoupler....for Arduino is a led and has isolation.you can isolate the arduino part and run it from another small battery separately.If you don't want an optocopler just use a 220ohm resistor for gate-output of micro.At 5v will pump a max of 22mA.Also at what current does the glow plug work?
High current and fast switching aplications are better done with a gate drive ic.Your logic level is hotter due to it's bigger gate charge.It's more slow in switching at the provided drive current.Use a gate driver ic for it.
 

cmartinez

Joined Jan 17, 2007
8,218
Late for the thread, and to be honest, I haven't read the whole of it. But I just fell compelled to intervene because the same exact thing plagued my designs for quite a while until I finally found the culprit.

There were two things that kept resetting my MCU's. The first one was noise caused by applying PWM to an inductive load (i.e. an electric motor) and said noise went back into the same power line that the MCU's power supply was connected to. It was solved by installing an EMI filter between the power line and the PWM circuit. This is the component that I used.

The second one was pretty obvious, but it took me a while to diagnose. The power supply to the MCU was a simple wall wart, and although it was of pretty good quality (and had a current capacity far exceeding what was actually needed), it was not as heavily filtered as it should have been and was quite susceptible to sudden voltage changes that were caused by the PWM being applied to the motor itself. It was solved through the use of a large, fat and robust capacitor (I used a couple of 4,700 uF caps in parallel) between the circuit and the wall wart, preceded by a diode to make sure that the capacitor did not discharge itself back into the power supply when said transients occurred.

Image00001.jpg

Hope this has helped.
 

Thread Starter

sumeryamaner

Joined May 29, 2017
114
Thank you all for your great inputs...

First of all, the glow plug is not an inductive load. It's inductance is not more than the connecting wires and I think this is negligible. It is a fully ohmic load like an old fashioned filament light bulb. So I believe there shouldn't be any "ringing".
The glow plug needs about 3 - 4 Amps to work and at this current it has about 1.0 - 1.2 Volts on it.
The WDT is always disabled.
There is a really fat capacitor in the circuit and it is the LiPo battery. I don't use a power supply or a wall adapter. The battery is capable of more than 60 Amps without any problems.

I didn't try without a gate resistor but I have tried with 75 ohms, 470 ohms, 1k and 2.2k. With 75 and 470 ohms I am getting regular resets or hang ups. With 1k and 2.2k it works but with 2.2 k the MOSFETs get very hot during operation. With 1k gate resistors everything seems OK for now.
 
Last edited:

Alec_t

Joined Sep 17, 2013
14,280
With 75 and 470 ohms I am getting regular resets or hang ups. With 1k and 2.2k it works but with 2.2 k the MOSFETs get very hot during operation. With 1k gate resistors everything seems OK for now.
To me that suggests EMI, not supply voltage droop, is the cause of the resets. Slowing the FET switching rate (albeit at the expense of greater heating), by using higher gate resistor values, is reducing EMI.
Sounds like you've found a practical compromise.
What is the distance between the PWM output and the glow-plug? Is twisted pair/screened wiring used between them?
 

Thread Starter

sumeryamaner

Joined May 29, 2017
114
To me that suggests EMI, not supply voltage droop, is the cause of the resets. Slowing the FET switching rate (albeit at the expense of greater heating), by using higher gate resistor values, is reducing EMI.
Sounds like you've found a practical compromise.
What is the distance between the PWM output and the glow-plug? Is twisted pair/screened wiring used between them?
Distance between the MPU and the switching MOSFET is about 2 cm and the wire (regular, untwisted, 16 AWG) length is about 10 cm (will be 25 cm in the actual application).
 

cmartinez

Joined Jan 17, 2007
8,218
The battery is capable of more than 60 Amps without any problems.
And my circuit was only drawing 0.1 amps, while the power supply had a 2 amp capability without any problems. That's a 20:1 ratio, and yet the problem persisted. Like you, I also added higher value resistors to the FETs gates (in the order of 1.2k) and the problem was significantly mitigated, but not completely solved.

The big cap I'm suggesting does not only act as an extremely fast current source (way faster than a battery, which has a higher internal resistance) but it also acts as a damper. EMI doesn't only travel through space, but also through a circuit's traces.

I forgot to mention, I also added a TVS diode to the circuit like this:

upload_2019-5-25_8-15-33.png

What I'm suggesting can very easily be tested using wire alligator clips and three easily obtainable components. And there would be no need for you to modify your already existing circuit in any way.,
 

BobaMosfet

Joined Jul 1, 2009
2,110
I think, to be fair, that unless the OP can provide some 'scope shots showing what is going on at certain points, then everything else is a guess. I think cmartinez is probably the closest to a solution, because at the end of the day, voltage follows current. Too much current draw, causes voltage sag, which can cause current drop, which can cause voltage further sag, etc....

But without something actually showing us the signaling-- we're all just guessing.
 

BobTPH

Joined Jun 5, 2013
8,804
Glow plug needs 3 to 4 Amps. PWM duty cycle is 15 out of 255.

So the current during the on period is:

3 x 255 / 15 = 51 Amps.

Is your wiring capable of handling that current? Have you calculated the voltage drop?

Edited to fix result of calculation.

Bob
 
Last edited:

BobTPH

Joined Jun 5, 2013
8,804
Since I redid the calculation, I thought of another cause for the reset. The battery protection circuit might be kicking in at 51 A

Bob
 

Thread Starter

sumeryamaner

Joined May 29, 2017
114
I will write a detailed update as soon as possible. This was part of a big (for me :) ) project and I am working on the code. Additionally I am a surgeon and I have to work. :)
 

Thread Starter

sumeryamaner

Joined May 29, 2017
114
This project is about an engine control unit for a DIY RC aricraft turbine engine. This is the second prototype PCB of the ECU now. With the first prototype we were able to control the startup and running of the turbine on the test bench. The power control was being achieved with a rotary encoder. Now with this second prototype we will develop the code for RC control. This is not an easy task for an amateur and I have to work hard to produce a working code. That means I need a working hardware and with the 1 kohm gate resistors the circuit is working without any problems. This led me to forget (temporarily ! :) ) the problems with the unexpected resets and hang ups.

My thoughts are as follows...

MOSFETs are voltage driven components. That means, if you turn them ON or OFF (not PWM) the gate resistor does not have any effect on the Rdson (unless there is a very high gate resistor and a very low resistor to ground). As current flows only as long as the gate capacitor is empty. After the gate capacitor is fully charged there will be no voltage drop across the gate resistor (if there is a high or no resistor to ground). All of this is true for a steady state and not for PWM.
If we use PWM, the switching time of the MOSFET depends on the gate resistor. The larger the gate resistor, the longer it will take for the MOSFET to conduct fully. That means the MOSFET will stay in the linear region longer which leads to power dissipation and heating up. This affects the generated EMI too. If we switch very fast we get a higher EMI.

As we are planning another engine test in a couple of days, I don't want to solder around the PCB until this test is over. So I am planning a test circuit on a breadboard and reconstruct and replay the scenario where the Atmega resets itself. After that, I will place a flyback diode across the glow plug even if it is not an inductive load. Maybe I can try a small capacitor (maybe 100 nF or so) parallel to the flyback diode and the glow plug in a hope to suppress EMI.

I think I can exclude the power supply and cabling as the cause of the problem because as I said earlier, I have completely isolated the power section supply from the power supply to the logic part of the circuit and the Atmega kept resetting at the start of the PWM signal.
 

BobTPH

Joined Jun 5, 2013
8,804
So your battery can supply 51A with no voltage drop, and without the protection circuilt kicking in? Do you understand how I calculated this current? Do you disagree with my calculation?

Actually it is worse than that. The glow plug will have a positive temperature coefficient, meaning the resistance when cold will be lower.

Do you understand that PWM is NOT changing the voltage you are supplying to the glow plug? When the MOSFET is on, the glow plug is seeing the entire 7.4V from the battery (assuming it is not connected to the 5V regulator). If you can measure the cold resistance of the glow plug, you can determine how much current it will draw initially at 7.4V. I think you will be surprised.

My prediction: The solution to this problem will be using a switching regulator to bring down the battery voltage to the 1.5V or so that the glow plug was designed to operate at.

Bob
 
Last edited:

Thread Starter

sumeryamaner

Joined May 29, 2017
114
So your battery can supply 51A with no voltage drop, and without the protection circuilt kicking in? Do you understand how I calculated this current? Do you disagree with my calculation?

Actually it is worse than that. The glow plug will have a positive temperature coefficient, meaning the resistance when cold will be lower.

Do you understand that PWM is NOT changing the voltage you are supplying to the glow plug? When the MOSFET is on, the glow plug is seeing the entire 7.4V from the battery (assuming it is not connected to the 5V regulator). If you can measure the cold resistance of the glow plug, you can determine how much current it will draw initially at 7.4V. I think you will be surprised.

My prediction: The solution to this problem will be using a switching regulator to bring down the battery voltage to the 1.5V or so that the glow plug was designed to operate at.

Bob
I exactly know what PWM is and what it is not. Thank you. And I am completely aware of the PTC nature of the glow plug.

But...
I think I have problems with expressing myself because I am not a native english speaker. Let me repeat:

I have completely separated the power supplies of the glow plug and the MCU.
That means, the MCU has been supplied bythe 5V regulator from the 2S LiPo battery No:1 and (the glow plug is connected between the positive supply voltage and the drain of the MOSFET which is a low side switch) another 2S LiPo battery (No:2) has been connected to the glow plug (of course with a common ground). So, even if you draw 51 or 151 Amps from the battery No:2 this cannot influence the battery No:1. Am I wrong?
 

cmartinez

Joined Jan 17, 2007
8,218
I exactly know what PWM is and what it is not. Thank you. And I am completely aware of the PTC nature of the glow plug.

But...
I think I have problems with expressing myself because I am not a native english speaker. Let me repeat:

I have completely separated the power supplies of the glow plug and the MCU.
That means, the MCU has been supplied bythe 5V regulator from the 2S LiPo battery No:1 and (the glow plug is connected between the positive supply voltage and the drain of the MOSFET which is a low side switch) another 2S LiPo battery (No:2) has been connected to the glow plug (of course with a common ground). So, even if you draw 51 or 151 Amps from the battery No:2 this cannot influence the battery No:1. Am I wrong?
Question, is the mosfet completely isolated from the MCU circuit?
 
Top