1997 nissan altima acts like its going to stall intermittently on highway and town

i get two codes both p0325

Code P0325 indicates a problem with the knock sensor circuit. But that shouldn’t effect the engine at speed.

Sometimes a crankshaft position sensor in the early stages of failure will cause the engine to stall at speed and then the engine runs fine. And a failing crankshaft sensor won’t always set a code.

Tester

Also, fuel pump could be getting weak.

I have owned the car for about three years. it does it about once a year. I have just been cleaning the MAF and it runs fine for about a year. I really dont know where to start. Thanks for your suggestions

Are you using a oiled performance filter? If so, that could be why the maf is getting dirty.