The improvement of your design should be done in two separate directions:
1. Hardware improvements - to minimize the impact of external noises to the controller:
- better schematic
- better PCB design
- better mechanical design
2. Firmware improvements. Whatever you do you could never guarantee that the controller will never hang or misbehave but you could do many improvements to minimize the impact of such events or even to make them completely invisible:
- watch dog and brown out detection are "must have"
- thread counters placed on many critical places to guarantee the correct sequence of execution. If threard counter is incorrect - start recovering preferably by doing hardware reset.
- make additional copies of the critical variables in your code and do special processing
- special software architecture to recover immediately and to make the misbehaviour minimal in time
In our company we struggled a lot with such noises, it came out that by doing 1 and 2 you could virtually make the design free of hanging. Even if it's affected from the noises this will be invisible for the user.
Kind regards,
Luben