PWM Question with an 8M and FET

RexLan

Senior Member
Got it working to my satisfaction now.

==============

I'm using a 8M code works fine.

PWMout SPIMotorPin,249,750
 
Last edited:

BCJKiwi

Senior Member
I'm not the expert on this topic but have asked the same question before and never received a definitive answer.

Why? Well it seems the issue is (as is often the case) that there are conflicting requirements.

The faster the FET is switched on and off by the PWM, the smoother the output seen at the motor will be.
The faster the FET is switched on and off by the PWM, the more time the FET will be in the transition between off and on where it is effectively a resistor and heating up.
There are also issues about the Ron and other effects to do with the properties of the gate of the actual FET selected.

So, in summary, turn it on and off as slow as is practical.
If the FET is turned on solid with the normal load on the motor, the full load heating (due to Ron) can be established. Then start controlling with the FET at a slow PWM, increasing the PWM frequency until the Motor behaves smoothly. This is the minimum rate for PWM and should produce the least heating effect in the FET. Faster PWM will produce a steadier output but increase heating effects in the FET.
 
Last edited:

BeanieBots

Moderator
Don't understand what you mean by "float a little":confused:
As for what would be a good setting, that depends on the motor and what it has to do. Impossible to say!

The PWM bit is quite simple.
The last two numbers are "period" and "Duty".
"Period" can be 1 to 255 and determines the frequency that the PWM runs at.
"Duty" determines the ratio of on/off but it is linked to "Period".
"Duty" must never be more than 4 times bigger than "Period".
When "Duty" is twice "Period", the output will be 50%.

So, for example,
PWMout SPIMotorPin,249,498 would give 50%.
PWMout SPIMotorPin,249,747 would give 75%
PWMout SPIMotorPin,249,996 would give 100%
You MUST NOT use a value greater than 996 if your period is 249.

As you probably know, the FET gate has capacitance. This must be charged/discharged quickly to avoid running in linear mode and producing heat. I've not looked up the spec, but you could just increase frequency until it starts to get warm. The motor inductance will also play a part in what is the best frequency to run at. Experiment.
 

BeanieBots

Moderator
Indeed, a reply would have been better than removing the original long post/questions:(
I'd still like to know what "floating a little" meant and what fix stopped it.
 
Last edited:

boriz

Senior Member
I'd like to know what the problem was and what the solution was. I learn from my mistakes, but I also learn from other peoples mistakes!
 

LizzieB

Senior Member
I'm not the expert on this topic but have asked the same question before and never received a definitive answer.

Why? Well it seems the issue is (as is often the case) that there are conflicting requirements.

The faster the FET is switched on and off, the smoother the output seen at the motor will be.
The faster the FET is switched on and off, the more time it will be in the transition between off and on where is is effectively a resistor and heating up.
There are also issues about the Ron and other effects to do with the properties of the gate of the actual FET selected.

So, in summary, turn it on and off as slow as practical.
For posterity and anyone else viewing this decapitated topic, I was very confused reading the above until I realized that by "switched on and off" and "turn it on and off" you mean the PWM frequency, and not the switch/turn on and off times of the FET - which can be affected by how it is driven and will have pretty much the opposite effect.
 

Michael 2727

Senior Member
A PWM frequency of 4KHz to 20KHz seems to be the standard for many DC Motors.
It will depend on the individual motor, some produce a lot of noise at different
frequencies, in most cases it's not that bad - Experiment.
4KHz has worked for me on various motors.
 

RexLan

Senior Member
Sorry for editing the post. When I did there were no replies so I did not thing it was appropriate to just leave the post there. However I can't really tell if I have some delay on my end or not.

The problem I saw was that the motor would turn on but not stay on solid (float). I selected a FET (IRFZ44V) with a high RDS(on) = 16.5mΩ so it would run cool.

What I wanted to know was how to find the optimum switching speed to provide enough starting torque and keep the motor locked on hard but to also keep the current low and allow the FET to run cool.

I ended up with 199, 520 and it seems OK. But that is just a guess and done unscientifically ...lol. Hacked at it until it seemed to work OK.

I started with 299,400 which works but it was "soft"

This little motor controls the second set of ports on the intake manifold of my race car. I need to open and close them at specified RPM.

The motor and the Picaxe controller are in the pictures on teh site:
http://www.srf-engine.rexlantz.com/
 
Last edited:

BeanieBots

Moderator
I selected a FET (IRFZ44V) with a high RDS(on) = 16.5mΩ so it would run cool.
Not sure if that was just a typo, but you want the LOWEST RDS(on) to run cool.

The way you got to a good working frequency/duty is probably about the only way of doing it without a comprehensive datasheet for the motor and a lot of maths. Even then, it's usual to have to 'fiddle' with the numbers anyway.
 

boriz

Senior Member
It takes time (and current) to charge/discharge the gate capacitance. Usually the higher the current handling capacity of a MOSFET, the higher the gate capacitance. A straight Picaxe output will provide about 25mA maximum. This is the turn-on / turn-off time ‘slope’ you are working with. During this time the FET is neither fully on, not fully off. It’s in it’s linear mode and this is where the heating occurs.

At higher frequencies the turn-on/off slope becomes more significant as it represents a greater proportion of the FET on time, especially at low duty cycles. So in that respect, the lower the operating frequency, the better. But that has to be balanced against the properties of your motor/solenoid.

The lowest PWM frequency possible with a default Picaxe is about 4Khz. That means using a PWM period of 255. (I dunno where you get 299 from). Using this frequency should be ok, but lower frequencies are possible by poking a special pre-scaler register in the Picaxe. See this post.

Frequencies as low as 250Hz might work just fine. Like I say, it depends on your load. You’ll have to experiment. Good luck.
 

BeanieBots

Moderator
It would be nice if the editor actually threw out 299,400 as those are invalid numbers to use anyway.
I've not tried it on the hardware but I would suspect it would be equivalent to using 43,400 which again is invalid and "might" be equivalent to 43,56 assuming an excessive duty is reduced by the modulus. (must try that).

Please can we have the editor report an error if period > 255 and/or duty > 4*period?
 
Top