PWM via IR nRF5340


I'm attempting to transmit IR signals over one of the PWM channels on the nRF5340. I noticed that the PRESCALER register only has 0 - 7 values in the OPS reference manual even though it's a 32-bit register. Is it possible to configure the 16MHz clock to be 38kHz for IR?



  • Hello,
    I am sorry, but we are short staffed this week due to Public Holidays in Norway. We will be back on Monday 22nd and hope to be able to answer all incoming requests within a couple of days, depending on the backlog. I am sorry for the inconvenience.

    Best regards,

  • Hi,

    Other values are not supported. (Only the lower 3 bits of the register are in use).

  • Hi Einar,

    Would the nRF5340 be able to do IR transmission through one of the other peripherals instead?



  • Hi Brad,

    There are several ways to generate PWM signals from the nRF, but I would prefer the PWM peripheral in this case. This has some nice features, particularily that it can play out a sequence via DMA, so very little CPU intervention is needed. Note that the frequency does not only depend on the PRESCALER, and can be much lower than the lowest frequency out of the prescaler, where there may have been a misunderstanding. I suggest you take a look at the PWM chapter in the PS while playing with the PWM examples under modules/hal/nordic/nrfx/samples/src/nrfx_pwm/. If you hook the output to a logic analyzer and play with it a bit, you can more easily get an understanding of how this PWM peripheral works (it is unfortunately a bit complicated, but also quite flexible).

    If you for some reason don't want to use the PWM peripheral, an alternative is to connect a timer to GPIOTE via PPI to get a pin toggling at a specific frequency, but then you would need SW every time you need to change the duty cycle or do other changes. (This can be done by using "sw_pwm" with Zephyr, where a SW library using the mentioned approach generates the PWM signal).


  • Hi Einar,

    So I've set the PWM0 Peripheral like so:

    But I'm only getting transitions on P0.01, P0.11, and P0.28? I figured the above code would set the P0.20 pin as the PWM0 output. Here is what I'm seeing on P0.01:

    This is P0.11:

    And this is P0.28:

    I'm not sure if my code is setting up the channel incorrectly.