PWM as analogue output

Hi

I would like to try using the PWM outputs of my arduino nano as analogue outputs. I understand you can use an RC filter to smooth out the digital waveform into a constant signal. Ive had a bit of a google about what values to use but I'm still not confident on how to do it. I believe the nano's PWM outputs operate at 500hz. Could someone tell me how to calculate appropriate RC values and perhaps how to asses the response time of the filter.

Im planning on feeding the signal to the ECU of a car engine. I think this should be accurate enough, I believe the PWM is 8-bit, but im worried there might be other issues with using this method.
Thanks

Tom

Could someone tell me how to calculate appropriate RC values

Filter design is complex, an RC is only a first order filter. That is only one circuit element moves with frequency. It drops off at 3dBs per octave. An octave is a doubling in frequency.
Replace the R with an L and you have a second order filter (6 dBs per octave)
You can also use op amps these make active filters, (the above are passive ones) and cascade them for any order you want.
Filter design is a compromise between, pass band ripple, stop band ripple and steepness of fall in the pass band to the stop band.

how to asses the response time of the filter.

The filter will respond at any rate inside the pass band.

I have arrived at the values of 3.3Kohm and 0.1 uFahrad. Does that sound reasonable?

Yes that sounds like it is in the right ball park. :slight_smile:

Thanks Mike, ill hit Maplins after work for supplies. What would the maximum output voltage of the PWM pin be? Is it fixed to the supply voltage or maybe some reference pin?

The maximum output voltage will can be no higher then the voltage running the processor chip, +5vdc, somewhat lower actually. It also depends on the input impeadance of what you are wiring the output of the filter too. If the circuit requires more current drive then you might have to buffer the output of the filter with a op amp. An after filter op amp could also be used to amplify the maximum output voltage to what ever value you require assuming you have an external voltage source to reach the desired output voltage.

So in some cases using a active filter op amp is much better then a simple RC filter in that you can obtain better filtering and design in the amount of voltage gain you require for the circuit you are driving.

Lefty

Would the aref pin, analogue input reference, be ground or 5v?

Its any voltage between ground and 5v you choose to put on it. That is then used as a reference for the analogue inputs. If you wanted to measure volatages between 0 and 1volt, you put 1 volt on it and the ADC maximum is then 1 volt. You need to set analogReference(EXTERNAL); in your code otherwise it uses the default of 5v and you don't need to connect the AREF pin.