Electronic – optimal low pass by trial and error

coilfilterlow passstep responsestepper motor

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.

Best Answer

I would direct drive the mechanism coil with a PWM of a frequency that is well above the audio range and at least 20X the mechanical response time. The PWM driver chip that you have now may just be able to do that and if not find one that can do it. The coil will do a wonderful job of reducing the PWM to its equivalent analog value just the same as any PWM direct motor drive works.

You will want to have a clean PWM waveform driven by counter/timer hardware or by a dedicated PWM generater chip. (There are actually simple I2C generator chips available that you could interface to the Pi). A software generated PWM will likely have too many glitches and interrupt update latencies to produce a clean waveform.

A really nice thing about this approach is that you can change the PWM to any setting you want and get corresponding action. Then you can consider an algorithm in software that sets the PWM farther that its target value to get the mechanism moving and then taper off to the target value to settle to final position. With a little fiddling you should be able to tune the performance of the overdrive without any real feedback as long as the drive voltage and mechanical load stay the same.