PWM via IR nRF5340

Hi,

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?

Thanks!

Brad

Parents Reply Children
  • Hi Einar,

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

    Thanks,

    Brad

  • 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).

    Einar

  • 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.

  • For more context, I'm trying to send the 1st and 2nd sequences as one 64-bit (2, 32-bit messages) transmission infinitely.

  • Hi Brad,

    You write that you want to output on P0.20, but you write 0x20 (which is 32 = P1.00) to PSEL.OUT. So it is expected that you do not see any output on P0.20. I do not see how P0.01, P0.11 and P0.28 are related to this though?

    Also, I would generally recommend using the nrfx driver (as demonstrated in the examples mentioned in my previous post), as that is typically less time consuming and less error-prone than doing the low-level stuff yourself. 

    PS: Please consider adding code via Insert -> Code instead of screenshots, to make it easier to search, copy-paste etc.

    Einar

Related