Me too - started out designing switched mode power supplies in the early 80s, now developing 800V 200kW EV drives. That involves switching tens or hundreds of amps and hundreds of volts within fractions of a microsecond within centimetres of "quiet" circuits. Making analogue and digital control circuits work reliably in the middle of a maelstrom of switching noise requires good understanding and design practice. Similarly, getting the emitted / conducted noise levels down to required levels can be very tricky. Optos are one way out but expensive and messy. They are generally only used where safety isolation is required.

Trying to filter noise out using software is a real bodge. Better to stop the noise getting to the micro to start with. Software filters never work the way you might imagine, as noise isn't a sine wave. Tackle it at or near source, rather than deal with the effects where they aren't wanted. Rather like tackling a barking dog, better to muzzle or strangle it than wrap the kennel and your head in blankets