# Smoothing PWM for electromagnet

Hi fellows,

I’m using an 12 volts and 35 ohms electomagnet.Using Gammon’s circuit below.I’ve set pwm 30Hz to get a precise control(To make big duty cycle control).Because of the PWM’s On/Off cycle electromagnet vibrating so much and its very noisy.I want to smooth PWM to analog so there will be no vibration.But not just for the vibration i think it will be stronger with analogue voltage.

I’ve searched the PWM to analog ways and i saw 3 ways;
1-With a DAC chip.I dont want this because of its low resolutions comparing to other two.
2-Rc filter
3-Lc filter

I want a good control and dont want to make it wrong.I havent an oscilloscope so im afraid to make something that works in the naked eye but actually it’s wrong and will make problems by time.You know electromagnet have an impedance and resistance and they are confusing me.

My questions:

1-Which filter i have to use?Does it much matter?
2-How to determine the values of filter?For a quick reponse like 30hz?I just want to calculations
3-I will apply this filter between +12volts and electromagnet am i right?

My power supply for 12volt is an 1A adapter(like phone charger).And mosfet is FDS9926A Datasheet Electromagnet is 25 kg sucktion 35 ohms, maximum 12volts.

Any reason to use such a low frequency of PWM? The common fix for vibration is to use ultrasonic frequency.

The electromagnet is a giant inductor. So to make an LC circuit, you only need a C (capacitor.)

The Arduino can get "precise" 8-bit control at very high PWM frequencies. (The definition of "very" depends on which Arduino you have. Whoops, you didn't tell us which Arduino you have.) And what do you mean "precise"?

For smoothing 30Hz, you are going to need extremely large capacitors. Like 10,000uF just to get started with.

If the problem is noise from the electromagnet, then the quickest and cheapest solution is to stop the vibration.

What is vibrating? The winding around the magnet core? The wires themselves in the electromagnet? Any of those can be solved by potting the magnet and the iron core in epoxy.

Paul

What was wrong with the default PWM frequency (pin dependent) of the Arduino.
If it squeals, then you pick a higher frequency, not a lower one.

Analogue/voltage is usually not an option, because that heats up the mosfet.
Leo..

Hi,
Are you using the PWM duty cycle to adjust the electromagnet position or strength?

Can you tell us the application please?

Thanks... Tom.....

Kindly please dont stick to my PWM, i didnt mentioned but i want analog voltage to my electromagnet.

I have arduino uno, thus basic pwm precise is 8 bit so one voltage step is 12/256=0,046875 volts.But at lower frequencies it is much better, at 30 hz it is 12/330000=0.36x10^(-3) volts in one step.It is very huge i know and looks unnecessray but its nice for my project.i will increase voltage in future.
@Paul it is vibrating because PWM makes electromagnet on and off very quickly and thus it is sucking and stopping so it is vibrating.

@Morgans I will apply this caps + leg to +12volts and - nleg to ground am i right?Or parallel to electromagnet as diode?

@Wawa Will the heat at lethal degrees for Mosfet?Are you know a way to make this?

Hi,
Can you explain how you came to these calculated results?

I have arduino uno, thus basic pwm precise is 8 bit so one voltage step is 12/256=0,046875 volts.But at lower frequencies it is much better, at 30 hz it is 12/330000=0.36x10^(-3) volts in one step.

The 30Hz calc, how many duty cycle steps do you have?

Tom...

TomGeorge:
Hi,
Can you explain how you came to these calculated results?
The 30Hz calc, how many duty cycle steps do you have?

Tom…

Hi Tom,

Timer1 on arduino is 30 hz intterrupt.So interrupting in every 1/30=0.033^ seconds in other words every 33333 micro seconds i have an interrupt.In interrupt i making pin high and in the loop i making pin low.A PID math adjusting the high time.like
interrupt{
hightime=pid
pin HIGH
time=micros();
}

loop(){

if(time<hightime){
pin LOW
}

Hi,

Tom...

TomGeorge:
Hi,

Tom…

Kindly why do you want to see it the topic not related to my code and sample is at my previous message about your question of voltage step.

MorganS:
The electromagnet is a giant inductor. So to make an LC circuit, you only need a C (capacitor.)

Sorry, this is total rubbish.

You cannot use a capacitor to filter PWM in this application.

In fact, the whole thread is rubbish. The premise appears to be that by using a very slow PWM, you can make the timing increments small in proportion to the whole cycle. Averaged over a second or so, this is quite true, but now you want it to be averaged and controllable over a smaller period which you cannot have. The two are mutually exclusive. Look up "Nyquist".

There is a distinct XY problem here.

Paul__B:
Sorry, this is total rubbish.

You cannot use a capacitor to filter PWM in this application.

In fact, the whole thread is rubbish. The premise appears to be that by using a very slow PWM, you can make the timing increments small in proportion to the whole cycle. Averaged over a second or so, this is quite true, but now you want it to be averaged and controllable over a smaller period which you cannot have. The two are mutually exclusive. Look up "Nyquist".

There is a distinct XY problem here.

Sir thank you very much you hit the bullseye i was expacting an answer like this scentific clearity.
My pwm is at 30 Hz now.My limit for making it faster 250Hz pwm so will be an interrupt in every 4000 microseconds.Is it enough?

This is like using a chainsaw to cut wood but you didn't put fuel in it. Yes it can cut, but extremely badly.

If you need better PWM resolution than 8 bit then you should be using one of the 16-bit timers to produce the PWM. Your don't need to write any code at all in loop() or an interrupt. The hardware does this for you. Just pull the trigger on the chainsaw instead of pushing it backwards and forwards yourself.

Official Arduino Secrets of PWM seems to be an older article but has good background information.

This blog post about a 16-bit PWM library seems to be pretty good too as it discusses the choice of frequencies and then links to another article on the associated filter to create an analog voltage.

If you really, truly want an analog voltage for your electromagnet then you need an analog amplifier. Something like an audio amplifier than has a DC response. This will be big and heavy and much less than 50% efficient, so this option is rarely used in Arduino projects.

Edit: fix broken url tag.

@MorganS Thank you very much, i really appreciated

Again.

Wawa:
What was wrong with the default PWM frequency.

What is so special about this electromagnet that it needs better than 8-bit PWM, and what was wrong with Arduino's default ~500 or ~1000hz PWM frequency.
analogWrite (5, 128); // ~1khz50%PWM on pin5

tlhsglm:
@Wawa Will the heat at lethal degrees for Mosfet?Are you know a way to make this?

You could be looking at 1watt dissipation in the mosfet and a 60C temp rise above ambient if you don't use a heatsink. Analogue/voltage control is usually a poor solution.
As said, PWM is more effficient. You just need to use the right PWM frequency and resolution.
High frequency and high resolution might not go together though.
Leo..

Wawa:
High frequency and high resolution might not go together though.

For a really large electromagnet, the limitation begins to be the inter- and intra-winding capacitance.

@Wawa I want bigger aperture to control electromagnets voltage.If i use analog write my aperture is 256.And if i use 250 hz pwm my aperture for voltage control is 4000.At 30 hz its 33333.But you said it is too slow, my limit is 250 hz, and i will do it.

@Wawa and Morgans
I know when i convert pwm to analogue voltage my torque will be reduced and the other loses will rise but i want to learn this.Do you think is 250Hz nice for converting anologue voltage?

By "aperture" you mean "number of steps between 0% and 100%"?

Specialized electromagnetic applications like these guys' ferrofluid don't need more than 256 steps. Think of every beautiful photo or video you have ever seen on your computer monitor: there are only 256 steps of red, blue and green in that image.

250Hz is awful. Even the default Arduino frequency of 480Hz is pretty bad. You should be in the kilo-hertz range for most PWM work.

Yes, if you can find a big analog amplifier then try it. But it will be a lot of work for negative benefit.

Another thing you might try is find out if your lab has an adjustable power supply of the appropriate current and voltage. Expensive ones can be controlled with an Arduino or PC with the right cable adapter.