MCU program not functioning with current draw

My program is working on my PCB but I encounter MCU lost program when the DC motor draw current.
The DC motor drive from L293DD and is only 0.5-0.8 A when turning but it can cause the MCU to lost program but does not damage any hardware. When I re-upload the program, it work back.

My ATMega328 5V is supplied from 7805. Incoming adaptor is DC 9V 1A to 7805. I try with DC power supply with max current 2A, the problem still the same, i think is not because of not enough current to MCU.

May I know at what situation can cause MCU to lost program ?

Do I need to separate into two different PCB, one DC motor drive and another for uP to prevent share or robbing power of motor from mcu ?

But if incoming only have one adaptor, the same robbing power also occur. Can someone share some thought ?

A lot depends on the size of the power supply (unknown) ?
The routing of the power (unknown) ?
The load requirements of the total circuit (unknown) ?

I am currently using DC power supply which I can set the max limiting current to 2A. The total load of the motor max is 1A. So it will not over. The routing of the power is is I supply 9V from DC power supply into the circuit 7805 to convert 5V. The 9V supply also to L293DD (H bridge motor driver) to drive the DC motor. The 5V from 7805 just supply to Atmel328P-CU and two 74HC595 with 18 LEDs. When the motor not working, the MCU working fine with the two 74HC595. When the motor is moving and drawing current, the MCU and LED is flickering like not enough power and after few times, the program inside the MCU not functioning at all. Even I reprogram, it doesnt work. Now, I suspect it also damage the 74HC595.

Thats not a schematic it just a brief description of how you power it.
Not enough to make an informed decision.

Agreed 2A sounds like it should be plenty but if its a wal-wart type supply some of those are not as good as they say. Had a 2A 12 volt power supply here that would drop below 1.5A under load and caused glitches with the total circuit..swapped it for a better 2A supply and all was good.

But the 2A limiting is a lab tool Regulating DC Power Supply which can supply max 3A. It was Kenwood brand, model PA18-3A. Not those adaptor.

OK so it has taken 5 posts just to rule out the power supply itself.

Schematics by any chance ?