Atmega328 keeps resetting itself if I start PWM

miomir1981

Joined Nov 30, 2010
2
I apologize if someone has mentioned this earlier in the thread.

Power MOSFET transistors have large gate and thus gate represents a large capacitance. Driving a power MOSFET as a switch will require only a small resistor in order to make circuit work. I always use 3K3 resistors for this. This will limit the current output of an I/O pin of the MCU. If you want, you can use larger resistor connected to the ground, let's say 47K or so.

Situation changes dramatically when one tries to drive a power MOSFET with higher speed. PWM is such a case. To make this story shorter, try using dedicated gate driver as this circuit will provide high gate currents needed to drive the MOSFETs properly in high frequency switching applications. The thing that resets your MCU is probably some overcurrent protection inside the MCU or something even worse than that. You probably burned several I/O pins in attempts of driving MOSFET with PWM signal in this way. Maybe there are MCUs that can drive MOSFET with PWM signals directly but Atmega328p is not one of them.
 
Nobody has mentioned interrupts at all. Blame it on hardware nobody here has seen but the PWM module generates interrupts so the setup should be checked.
 
There are so many things wrong with the layout that I don't know where to begin.
  1. High current and low current parts of the board need to moved apart. Not necessarily isolated, just separated.
  2. The glow plug and mosfet need to be very close to the battery terminal with heavier traces.
  3. The ground and power for the microprocessor must not share traces with high currents.
  4. The battery connector and wires are too small.
  5. The filtering for the micro appears to be inadequate.
  6. The gate drive to the mosfet is inadequate.
  7. If I had more time I could probably add a few more.
The main reason you had problems is the length and location of the traces to the glow plug. Any incandescent device has very low resistance when cold. On PWM start up there is a heavy current draw until the glow plug warms up. Due to the traces being too small, too long and shared with the micro you get a very sharp spike in the ground causing the micro to reset. When you reduced the gate drive by enlarging the gate resistor you reduced the di/dt and therefore reduced the spike. This helped your spike problem but is bad for the mosfet. Adding large capacitors also helped but is a bandaid instead of a fix. You will need a lot of changes to correct the circuit.

Redesign the board, placing the glow plug, mosfet and traces close to the battery plug and make the traces as large as possible. Place other high current devices in the same area as the glow plug/mosget. Maybe along the lower edge. Place the low current parts together on the opposite side from the high current. Get a better driver for the mosfet. Place a diode between the positive supply and the regulator and place one large capacitor between the diode and regulator to ground. Scatter a few ceramic capacitors between the positive regulated voltage and ground. Make sure the ground and voltage traces for the micro comes directly from the battery connector and are not shared with any high current paths.
 

ScottWang

Joined Aug 23, 2012
7,501
I haven't read all the thread yet, if you still didn't solve the problem then please check and be sure that the current of power is enough for the motor, the first image that come up in my mind is the power +5V and Gnd had short time shorted, it could be the power can't provides enough current for Motor or the motor generates the noise to causes that, you don't have the O'scope, otherwise you can check that is it only appear in +Vcc or the Ground also has the noise, please check the first circuit below, the second circuit is for +5V and Ground all have noise interfering.




* PS: You can use a multi-meter and turn to the AC range can be measured <=10Vac, the probe in series with an 0.1 uf capacitor and use the other pin of the capacitor and Gnd to test the +5V and Ground, if it shows any voltages then it had noise it.

Use the Toroidal Coil and capacitor LC Filter for the surge and interference of uC 5V and GND.
 
Top