PWM question

xtech007

Senior Member
Good morning all!
Quick question.
if I wanted to use pwm to fade 5v led via 28x2 how would I know the pwm frequency in kHz or Hz that is nesessary to turn on the LED?
Or how do I get that info?
Same for dc motors.

I do know there is a pwmout wizard, but initially it ask for " desired PWM frequency " that is what I would like to know how to obtain!

Thanks !
 

oracacle

Senior Member
I would just experiment until you fond desired results. Its a tried and tested method of finding the information you want.

you could write a piece of code that ramps and send the info back to the serial terminal to save constantly reprogramming the picaxe.
I'm sure there are plenty of threads on PWM ramping which you can use as a base for that.
 

AllyCat

Senior Member
Hi,

For a "simple" system, e.g. a bipolar or FET driving a motor or LED(s), the basic answer is "as low a frequency as is acceptable". For LEDs that may be just high enough to avoid perceptible flicker, perhaps 100 Hz, but keep the switching losses as low as possible. For a (dc commutator) motor it may be even lower (perhaps as low as the PICaxe will go), because an advantage of PWM is that it gives the motor brief "kicks" that can overcome "stiction" (static friction) to give improved low speed "torque".

However, for a "serious" system with an inductive filter, RF suppression components and a proper FET driver, etc., the general aim is to use "as high a frequency as possible" because that allows smaller (and potentially cheaper) components to be used. But you really need to know "exactly what you're doing" (so wouldn't be asking this question) or you may destroy the components (or worse) with excessive power dissipation.

The difficult answer is if the power supply is itself of a Switching Mode (PWM) type. That may have "economised" on the size of its output decoupling/reservoir capacitors, so you may need to use a mid frequency (perhaps 1 - 20 kHz), which will depend on the characteristics or specification of the power supply.

Cheers, Alan.
 

hippy

Technical Support
Staff member
The maximum duty value determines the period and frequency and vice versa; period = maximum duty / 4.

As the frequency increases the period and maximum duty value decrease, so the amount of control you have over dimming or speed by varying the duty, decreases. It is therefore a matter of finding a balance between each.

When dimming a LED, having 0 to 255 ( or 0 to 100 ) brightness control is convenient, which dictates a period value of 63 ( or 25 ).
 

inglewoodpete

Senior Member
If you are just using PWM to control a low-power LED (Eg a 3 or 5mm, ~20mA type), then just about any frequency will do.

I use PICAXEs to drive higher power LEDs Eg 10 to 50 Watts per PWM channel. This requires a MOSFET to drive the higher current of the LED/s (Eg 1+ amps). Due to the gate capacitance of the MOSFET, a lower frequency is required - otherwise the MOSFET takes too long to turn on and off. I use 28X2s to control the MOSFETs via MOSFET drivers at around 950Hz. This gives the MOSFET sufficient time to be in either the PWM 'on' and 'off' states to satisfactorily control the LED/s.
 

erco

Senior Member
From my experience, I use the lowest PWM freq for small DC motors to get past "stiction" and avoid that useless high pitch whine you often hear from RC car controllers. With Picaxe that's often ~62 hz. Per Alan, there are more sophisticated method to determine "optimum" freqs based on inductance and driver impedance, but my goal is usually just getting the most usable torque at low RPMs in practice.

Not sure if PWM freq matters that much on LEDs. Dim's dim at any frequency, you'll need to adjust the PWM to match your expectations & perception of brightness.
 
Last edited:

xtech007

Senior Member
great!

Thank you Guys!
Will experiment and read up a bit more
On PWM . Trying to introduce couple of 10-12yrs kids how to use picaxe blockly!

They just learned how to turn on/off leds. Next fading.

Humm. I do not see a PWM option on blockly, just pulsout.
Is this correct?
" found it under output"
 

hippy

Technical Support
Staff member
Humm. I do not see a PWM option on blockly, just pulsout.
Is this correct?
Under "Output" towards the bottom - "Set pwmout period [X] duty [X] on [pin]".

Edit : Where you found it whilst I was composing :)
 
Top