I know that the analog outputs of the Arduino is PWM, and not linear voltage output. However, I would like to "smooth out" the PWM output so that it approximates a regular voltage source.
I need to drive a very delicate moving-needle panel meter with the arduino and I'm worried that the 500Hz pwm might cause resonances in the spring mechanism or shake it apart, plus I'm not sure if 50% pwm will actually push the indicator needle to the same reading as 2.5 steady volts would.
Can I smooth the pwm output just by running a cap from the pin to ground? I know the load resistance, so how should I choose the capacitor's value? I'm not sure if the time constant should be greater than, or less than 1/500s, or if this is even a good idea.
Can I smooth the pwm output just by running a cap from the pin to ground? I know the load resistance, so how should I choose the capacitor's value? I'm not sure if the time constant should be greater than, or less than 1/500s, or if this is even a good idea.
What you need is called a low pass R/C filter. You can make such a filter by wiring a resistor to the PWM output, the other end to a cap and the other end of the cap to ground. Your smoothed analog output voltage will be from the junction of the cap and resistor and ground. The impedenance of your meter movement will effect the performance of the filter and you may have to play around with the values of the cap and resistor, try 5k ohms, 10mfd cap and see what you get. If you can't drive the movement full scale, try lowering the value of the resistor.
My meter is full-scale at about 250uA, so before I thought about the possible drawbacks of PWM, I was just going to run from the output pin, through a 25kOhmish resistor, to the meter coil which is 305ohms. Then if the PWM worked like plain analog output, then 255 duty cycle would full scale the meter and 0 would of course be off. This can be calibrated in software if it doesn't work out theoretically; I mostly need to be able to full-scale the meter at a highish duty cycle for resolution.
Is this simply using a resistor too simplistic? I don't have space to incorporate an amp.
If I want to incorporate a filter I suppose that I can just use the 25k resistor as the filter resistor, put the cap to ground after that, and hook up the meter's coil to the junction there. However, how do I go about calculating the appropriate cap? I know that the filter frequency will be 1/ 2piRC, but what R do I use, the 25k or the 300? And what do I want the frequency to be anyway? <<500hz?
Cool. I don't think using too big a cap is going to be a problem because if the time constant is really long, it will just mean the needle will be slow to react and that won't happen until the time constant is like 1/2s or something giant.