I'm using Atmega128L controller. One of the primary tasks is to control a linear actuator. The actuator supply and controller supply are different(initially it was designed to share a common ground). The relays that are used to control the actuator uses the same supply as the controller. All other inputs and outputs are through isolation. The 3.3V line to the controller is not that noisy, even during relay turn on turn off.
The issue I'm facing is related to microcontroller reset. This reset occurs when the actuator hits the inbuilt electrical limit switch(which cuts off motor power). Apparently this is the time when the motor uses maximum power.
The code flow is in such a way that a normal reset wouldn't affect its functionality. It would recover seamlessly. However when the reset occurs, the controller seems to malfunction, skips done part of code, not following proper initialisation procedure, executes functions which are in memory but are not called anywhere in the current code. Because of this the controller shows some illogical error state (as per code), or corrupts the Ic's that it is interfaced with. Most of the time a proper power on reset or external reset makes the controller work properly.
How can I make sure that the controller gets reset properly?
Edit: I don't deny that there is a noise in nanosecond range in 3.3V supply. I'm very much concerned about the controller's response to the noise. I expect a proper brownout reset or watchdog reset when the noise occurs, instead of PC jumping to random location or stack getting corrupted.
My controller works with 8Mhz external clock, Max speed is 8Mhz