This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Getting started with PWM on nRF52

I am quite new to embedded firmware development and definitely just two days old into Nordic nRF52 development.

I want to just setup a 25% duty cycle clock output on GPIO pin 5 for nRF52 with 100 KHz frequency. How can I do this with using just the drivers_nrf header files? I believe that I don't need to setup any IRQ handler for this, correct?

I do not plan to use any SoftDevice and right now want something very simple so that that I can experiment and learn. Just just the static inline functions from components\drivers_nrf\hal\ folder if possible.

I see some sample code online that seems to use NRF_TIMER along with PWM_IRQHandler. But I thought that I could use PWM without any CPU interaction. Can't I use the NRF_PWM resources? I was hoping to find sample code that uses nrf_pwm_pins_set() and nrf_pwm_configure() etc. to just get a simple clock.

I was hoping to have code similar to below but all examples I see use the TIMER2 instead. It feels like I am missing something major...

uint32_t out_pins[] = {5, NRF_PWM_PIN_NOT_CONNECTED, NRF_PWM_PIN_NOT_CONNECTED, NRF_PWM_PIN_NOT_CONNECTED};
static uint16_t pwm_seq[2] = {0x8800, 0x0800};
nrf_pwm_sequence_t const seq = 
{
    .values.p_common = pwm_seq,
    .length          = sizeof(pwm_seq)/sizeof(uint16_t),
    .repeats         = 0,
    .end_delay       = 0
};

nrf_gpio_cfg_output(5);
nrf_pwm_pins_set(NRF_PWM0, out_pins);
nrf_pwm_enable(NRF_PWM0);
nrf_pwm_configure(NRF_PWM0, NRF_PWM_CLK_16MHz, NRF_PWM_MODE_UP, 1600);
nrf_pwm_loop_set(NRF_PWM0, 0);
nrf_pwm_decoder_set(NRF_PWM0, NRF_PWM_LOAD_COMMON, NRF_PWM_STEP_AUTO);

nrf_pwm_sequence_set(NRF_PWM0, 0, &seq);

NRF_PWM0->TASKS_SEQSTART[0] = 1;

BTW - this is on my custom board and not on dev-kit but that should really matter much. Any pointers appreciated. Thanks!

Parents
  • Hi,

    You are correct that the nRF52 series has PWM hardware. Have a look at the PWM Driver and the PWM Driver Example (not to be confused with the PWM Library, which uses a timer, ppi and GPIO.)

    Regards, Terje

  • Thanks Terje. I took a look at the PWM Driver and the example. They are very helpful and I get the high-level idea now. However, there is still a lot of code in there - the driver library pulls in lots of header files for typedefs etc. that we don't plan to use for various reasons.

    I am hoping to use a simple HAL-based PWM itself. The PWM driver has support for complex sequences and use of interrupts to handle tasks when sequences playback is completed.

    I understand this is my work and not someone else's but was hoping if you can help identify what is missing in the following code. I don't get any signal output.

    I updated the code in my original post. What am I doing wrong?

Reply
  • Thanks Terje. I took a look at the PWM Driver and the example. They are very helpful and I get the high-level idea now. However, there is still a lot of code in there - the driver library pulls in lots of header files for typedefs etc. that we don't plan to use for various reasons.

    I am hoping to use a simple HAL-based PWM itself. The PWM driver has support for complex sequences and use of interrupts to handle tasks when sequences playback is completed.

    I understand this is my work and not someone else's but was hoping if you can help identify what is missing in the following code. I don't get any signal output.

    I updated the code in my original post. What am I doing wrong?

Children
No Data
Related