Main Site Documentation

Can't get over 9MHZ on PWM


Have anyone manage to get PWM running faster then 9MHZ??

I need to get it to 10MHZ.

I use _pwm.SetPulse(100, 50);

Does anyone have tried set the PWM pulse with register access?


You might check this code I wrote for FEZ Cobra:

There you see how the prescaler is calculated:

public void SetPulse(uint period_nanosecond, uint highTime_nanosecond)
        // Adjust for 72 MHz / 4 clock
        period_nanosecond *= 9;
        period_nanosecond /= 500;
        highTime_nanosecond *= 9;
        highTime_nanosecond /= 500;
        lock (syncLock)
            if (pin == null)
                throw new ObjectDisposedException();
            mr0.Write(period_nanosecond);           // Set the clock
            mr.Write(highTime_nanosecond);          // Set duty
            ler.SetBits(1U | (1U << pin.Channel));  // Set latch enable bits for clock and duty

As you can see, the peripheral clock for PWM is derived from 72MHz/4 = 18MHz.So 18MHz will be the fastest clock you can get on PWM. Divided by two, that gives you the 9MHz clock you’re seeing. You cannot divide the peripheral clock by 1.8

I don’t know if you can change the peripheral clock to 36 MHz or 72 MHz, that way, you could get closer to 10Mhz (in all cases, you’ll never get a perfect 10MHz!). You’ll have to check the datasheet for that.


Aha, that explains the 9Mhz,

Thanks a lot for the info!