Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Generating 50% duty cycle square waves greater than 1Mhz using PWM.

Hello,

I am attempting to use my nRF52810 (testing with the nRF52 DK) to generate square waves using PWM. Ideally, these square waves would operate at 8 or 16Mhz. So far I have used the base pwm_library and pwm_driver examples provided in the sdk to test this but have some uncertainty how to do it. I have been able to produce square waves with 50% duty cycles, but it seems that the frequency tops out at 1Mhz. 

When using the pwm_library, it seems as though the lowest period I can set is 1us (1Mhz). However I cannot provide a period less than 1us or the pwm output is blank. I have stepped through the code a bit to understand how it works, but unsure how to achieve a higher frequency output.

I have also done similar high level exploration into the pwm_driver library but have not gotten any further.

My questions are:

1) What is the max frequency output achievable using PWM (is it 16Mhz)?

2) How can I achieve this (or 8Mhz/16Mhz)? An example would be greatly appreciated.

  • 1) What is the max frequency output achievable using PWM (is it 16Mhz)?

    Using the PWM HW peripheral, then lowest allowed .top_value is 3, so the max frequency you can get with the PWM peripheral is 16(base or prescaler)/3(countertop) = 5.3333 MHz.

    2) How can I achieve this (or 8Mhz/16Mhz)? An example would be greatly appreciated.

    Using GPIOTE+TIMER+PPI, it possible to get max 8 MHz with duty ~50%. See e.g. this post:  nRF52 clock in and out 

  • Thanks for the help Sigurd. Very helpful and much appreciated.

    Would just like to confirm that 8Mhz is the highest frequency achievable. There is no way to generate a higher frequency (16Mhz)?

    I used the example you linked above and was able to generate a 8Mhz waveform.

    Is there any way to adjust the waveform shape so that the output is more square? Additionally, can the amplitude of the waveform be adjusted?

  • himothy said:
    Would just like to confirm that 8Mhz is the highest frequency achievable.

    Yes, this is the highest you can get.

    himothy said:
    Is there any way to adjust the waveform shape so that the output is more square?

    Maybe if you set the GPIO pin in high drive mode.

    nrf_gpio_cfg(pin_number, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);

    himothy said:
    Additionally, can the amplitude of the waveform be adjusted?

    No, it should be around ~VDD

  • Thanks for the follow up Sigurd.

    Setting the GPIO pin in high drive mode makes the waveform "more square." But a bit more of a clipped sine wave than a square wave. It also increases the amplitude too.

Related