PWM freq

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.


Please log in to post comments.