changing PWM freq

19 Jan 2013

I declare a pin as PwmOut MotorL_Pin(P2_5);

and in Main I have; MotorL_Pin.pulsewidth_us(10); MotorL_Pin=.5;

the pwm is at 50%, but the freq is 50hz. what did I miss to change the freq? How do I set it to say 10khz? Thanks Ringo

19 Jan 2013

You set the pulsewidth with the first method and then you set the dutycycle with the = operator. What you need to do is set the period. The period defines the repetitionfrequency of the pwm signal. The pulsewidth defines how long the generated pulse lasts. You can also express that pulselength as a percentage of the repetition period, that is also known as dutycycle.

So first set the period and then set the pulsewidth either as an absolute time or as a dutycycle percentage.

MotorL_Pin.period_us(100);  // 10 khz
MotorL_Pin=.5; //  50%

Note that all mbed pwm pins will have the same repetition frequency. You can only vary the pulsewidth independently.

21 Jan 2013

I'm intrigued with this one as my own aim is to build a terrain following rover using sensory feedback and position feedback to control speed etc. Why would you use such a high frequency on a motor output? Isn't motor speed dependent on the % of full scale output voltage from the motor driver board. In other words a high frequency output is just switching the H-Bridge output drivers faster. 10kHz equating to a pulse of 0.1mS?

21 Jan 2013

Derek Calland wrote:

I'm intrigued with this one as my own aim is to build a terrain following rover using sensory feedback and position feedback to control speed etc. Why would you use such a high frequency on a motor output? Isn't motor speed dependent on the % of full scale output voltage from the motor driver board. In other words a high frequency output is just switching the H-Bridge output drivers faster. 10kHz equating to a pulse of 0.1mS?

Agree that in general such a high freq is not needed for PWM motorcontrol. Maybe Ringo is hoping to simplify filtering out electric noise by using a high frequency. The other explanation why such a high frequency may be used is when you try to control a three-phase motor. You can create 3-phase voltages by using three PWM outputs running at high freq and varying the PWM duty cycles for each phase to effectively generate a lower, possibly variable, frequency (eg 50Hz).

22 Jan 2013

2 reasons for the freq. 1) it is above the audible range. If you PWM at 1Khz there is a good chance you will here it. Annoying. 2) The voltage at the H-bridge turns on and off, but you want the current to continue to flow through the motor. The inductance of the motor allows this. Unless the motor you have has a HUGE inductance you need a high freq so that you are turning it back on before it decays completely. That is what allows the variable digital PWM to turn into a variable analog current.

Ringo

22 Jan 2013

Hmmm 2 further thoughts on this one. 1. The current still flows because of Ldi/dt as the current cannot change instantaneously across an inductor, so the motor winding inductance prevents this but current is also required for the motor magnetisation current that develops torque. 2. High frequency voltage switching across a simple dc motor would not do the brushes much good or the winding insulation over time me-thinks. May have to try and experiment with this when I go back to my Magnevation board.