raschemmel:
That was my first thought when I first saw it so I increased the delay and it didn't affect the duty cycle of that triangle waveform. Commenting out the serial prints didn't affect it either.
None of that stuff would affect the PWM waveform that analogWrite makes, it's generated by the timer hardware.
I eventually started moving the mosfet around and found that if I moved it to a certain position that oscillation went away.
That's odd. There's no way moving the MOSFET would change the characteristics of the filtered analog signal, so it shouldn't have went away if you were still using LPF PWM as the control signal. It's kind of hard to tell with analog scopes, you may have been reading the wrong point or miswired the circuit while rearranging it. That could just be an open circuit reading.
I call that "background processing".
The brain reviews all data collected while you are sleeping and checks it for anomalies or similarities.
I have fixed circuit boards in my sleep this way after a whole day working on them at work. (fortunately I don't have to do component level troubleshooting anymore. I went back to school to get my degree so I could get out of that kind of "grunt work". (chained to a bench)
I was consciously thinking about it while laying down, it was very much a "foreground" process.
The best ones though are those problems you spend like 3-4 hours trying to solve, give up for two days, look at it again and solve it in 15 seconds. Then it's like "what kind of idiot was I two days ago that thought this was hard?"