Today I tried to control the position of a voice coil by using PWM on arduino. Using digitalWrite, the setup is very silent, but I want to control the position steplessly so I used PWM. Positioning works great using a joystick input.
The problem that I now need a solution for is that the setup is buzzing when the PWM is not at 0% or 100%, so it is buzzing at PWM values 1 to 254. When I hit the limits the buzzing stops. Anyone knows why it is like this and how to solve it? Here is a video of it (Please excuse the noisy ventilation in the background) Buzzing voice coil video
The voice coil is responding to the pulses in PULSE-width-modulation (as a loudspeaker is designed to do). You could decrease the PWM frequency to below the audible range or increase the PWM frequency to above the audible range.
However, because you are endeavouring to control coil position by a signal that switches from high-to-low the voice coil will modulate between the maximum and minimum positions with every pulse, irrespective of duty cycle (extremes at either end excepted) or frequency (within mechanical response limitations)
As Mike says, you need a DC value if you want to relate coil position to system output and for that you need to convert the PWM signal into a DC value. However the response will not be linear since the coil impedance will load the RC smoothing network so you either need a low impedance output buffer amplifier, or write a piece of software to correct the non-linear response.
No, wrong approach I think - smoothing to DC then means a linear DC amplifier is needed, which
won't be efficient.
A voice coil is an inductor, it smooths current anyway, but you need to
use a higher frequency of PWM when the inductance is low, and to push the noise out of
the audible range. 16kHz or 20kHz is the sort of frequency to consider, which means
re-programming the relevant timer that drives the PWM pin(s) you are using. Also
you need to use switching devices that are fast enough to cope too.
The same issue applies to motors, and the PWM rates are often pushed up to the ultrasonic
range to prevent acoustic noise (big motors work happily with lower PWM frequencies,
but nearby humans don't like the whining).
Tell us more about the hardware please...
Thanks everyone for the great advice, I will look into this on Tuesday and report my findings. After diving into this, the frequency I used should be the default 980 Hz (pin 9 & 10). Firstly I am going to try the lower audible register just out of curiosity of the effect on the noise (however I cant make it lower than audible frequencies since 20Hz will be to slow for my application), then try upping the frequency to ultrasonic, and lastly try a simple low-pass filter. Very excited about trying this. Thanks people!
I also checked my MOSFET:s, and the rise time + rise delay + fall time and fall delay is 830 ns, which is roughly 1.2 Mhz, so pulsing at 20.000 Hz should not be a problem.
You said in your original post that you were trying to control the "position" of a voice coil (I presume you mean the coil in a loud speaker)
Can you please explain further exactly what you are trying to do.
I do not believe applying a PWM signal will control actual position.
It will simply cause continuous movement of the voice coil at the PWM frequency.
My understanding of loudspeakers is that changing the direction of the current back and forth is what mainly causes the membrane to vibrate at high speeds. In this case however, I will only apply a current change when I want to go from for example a +x position to -x position. The only force applied when the current is off is the spring suspension which is not nearly as strong as the electromagnetic force. There is also considerable inertia in the system since the moving parts consists of relatively heavy magnets and a lens instead of a light plastic membrane and voice coil as in a loudspeaker. Also, when no current is flowing, the force of the springs that moves the magnets will in itself move the electrons and create an electromagnetic force which slows it down even more.
Which is why I think you need a DC soloution rather than PWM.
With PWM you are using the inertia of the system as your smoothing. It would seem that this is not enough which is why you get the sound.
So while upping the frequency will take the PWM further away from the natural inertia cutoff point you run the risk of it not working as well.