After opening an old webcam I found a lens with a magnetic socket, which is used for autofocus. A coil moves the lens in and out to adjust sharpness.
I recently mounted that feature onto the raspberry pi camera module. Now I want to control the magnetic field of the coil digitally with a PWM signal, which is translated to a analog signal by a simple RC low pass filter see here
At the moment I use a 30uF elko, and an adjustable potentiometer between 0 and 1k ohm, to filter the digital PWM signal. The digital signal from the microcontroller is not directly filterd, but first fed into a stepper motor driver to protect the pins of the microcontroller. The digital output of the PWM is then fed to the RC circuit.
Autofocus does work... although its a little slow. And the problem lies in the relatively slow actuator response. To be a little more speficic: using a PWM frequency of 8khz, and changing the duty cycle by 5 percent, the response is 0.4 seconds for the coil to adjust itself.
I know its difficult to get super fast response without a feedback loop, but I would be happy with 0.1 seconds, if this can be done just by changing some components and values.(Another option would be to find the right amout of overshoot) Basically the RC circuit shall just convert the digital PWM waveform to a certain voltage. It will take some time for the signal to settle to a certain voltage. The more flattend the output voltage shall be, the slower the filter response. The output of the signal should be as flat as possible, to keep the lens still. So I have to find a tradeoff. What I also intuitively expect is, that the higher the PWM frequency, the better? Of course if its too high, then the power dissipation will also be high. And if there is no power at the coil, then the lens will not move.
Unfortunately I can not give you the data for the coil right now, the only thing I know is that is has a ohmic resistance of 30 ohms. But there is also the weight of the lens, the magnetic field of the permanent magnet, the actual inductance, the spring constant of the recoil spring etc... These are so many unknowns that it would be to difficult to predict an optimal setting.
Now my question to you is, whether it is possible to use variable resistor and capacitor, and just find the optimal setting by trial and error? And if so, what kind of components would you recommend?
By the way: The coil at the moment is quite noisy (8khz). Not that its tedious. But normally an autofocus doesnt make that noise, at least the one in my smartphone. Actually I would rather prefer a noisy but quick response, than a quiet snail.