Does anyone on here know if the capacitor-resistor combo attached to a pwm output pin of an Arduino gives a decent analog output?
@MLE_online Low pass filtering PWM to get analog voltage always comes with 3 unavoidable problems. Whether you consider the result "decent" depends on how low your expectations are.
@MLE_online Problem 1 is output impedance. The signal is "weak" because of the resistor. If you will drive something very high impedance like an opamp input, maybe it's a non-issue. If you want a strong signal, you'll need to add an opamp or other way to buffer the output.
@MLE_online Problem 2 is noise on the power supply couples to your signal. With a proper DAC you would look for a PSRR (Power Supply Rejection Ratio) spec or graph to give an idea of how much noise can couple from power to signal. You might power the DAC with separate "clean" power. DACs use a reference voltage too, which is very stable. With low pass filtered PWM, any lower frequency noise on your "digital" power supply goes straight into your signal. Pretty much the worst PSRR scenario!
@MLE_online and of course Problem 3 is trade off between slow response versus some of the PWM frequency remaining. Here's documentation for Teensy to give a quick visual idea, but it applies to Arduino or any other PWM output.
@PaulStoffregen @MLE_online Very interesting! And if you chose to do PWM anyhow, maybe even for audio: What would best practices? Output buffer, ...?
@mixal @PaulStoffregen @MLE_online PWM is not terrible and when combined with high/low-side switching with power transistors can be used to very efficiently provide high-power analog signals to inductive or capacitive loads (look up Class D power amplifiers). I would pick a PWM frequency much higher than the signal bandwidth and do some proper filter calculations/filtering however. The resolution of the duty cycle in your microcontroller becomes (an upper bound on) your sample resolution
@mixal @MLE_online Normally the best practice is to use PWM to directly drive your lights or motor or loudspeaker or whatever other physical thing ultimately matters, which can naturally "ignore" the PWM's high carrier frequency. Perhaps use minimal filtering like ferrite beads, only for the sake of limiting radio noise you spew into the world. For audio driving a speaker, usually use a dedicated power supply to minimize the PSRR problem.