This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Outputting a PWM signal and it's inverse thru gpio pins

Hello,

I have two questions:

How do I access the gpio pins of nrf52840 dk? what example program from nrf5 sdk can I use as example?

Is there a simpler example program to output a pwm signal of example like 400kHz and it's inverse in the pins?I'm looking at the PWM driver example of nrf5 sdk and it's a really big leap for someone like me who's use to programming via Arduino IDE

Parents
  • Hello,

    How do I access the gpio pins of nrf52840 dk? what example program from nrf5 sdk can I use as example?

    The description of the application above sounds very similar to the functionality demonstrated in our PWM Library example from the SDK. I highly recommend checking out this example, to see how you may go about setting up two inverted PWM's using the PWM library provided in the SDK.

    pwm signal of example like 400kHz

    Unfortunately, the pwm library instances are limited to 200 kHz. If you need 400 kHz, you will need to make use of the PWM peripheral. You could see how this can be used in the PWM driver example - however, this example might seem a little intense for someone who's most used to Arduino development. The example contains multiple demons, which in turn makes it seem daunting to familiarize with.

    To make things easier, you could instead have a look at the project I have included below, which is made for the nRF52840 DK. This project is the same as the one referenced by my colleague Torbjørn in this ticket. It showcases a much simpler approach to setting up the PWM peripheral, with a much less complex output. Once you get the hang of this example and how it works, you can begin looking at modifying it for your application needs.
    Mind you that this example uses the legacy nrf_drv driver, but in never SDK's this is using the nrfx driver behind the scenes through forwarding macros.
    2627.pwm_driver_simple.zip
    You should have a look at the nrfx_pwm API Reference when you start modifying the example.

    I'm looking at the PWM driver example of nrf5 sdk and it's a really big leap for someone like me who's use to programming via Arduino IDE

    No worries at all - we've all been new to this at some point! :) 
    Please do not hesitate to ask, if you should encounter any issues or questions.

    Best regards,
    Karl

  • You could see how this can be used in the PWM driver example

    Oh so I should use the pwm driver example rather than the pwm library when going to output 400kHz?

    The example contains multiple demons, which in turn makes it seem daunting to familiarize with

    By any chance you can provide me some resource I could read on or guidance so I could learn to handle these demons? I'm really new in this embedded programming stuff

    This project is the same as the one referenced by my colleague Torbjørn in this ticket

    Are you referring to the zip file you attached?

  • refer_pin said:
    Oh so I should use the pwm driver example rather than the pwm library when going to output 400kHz?

    Yes, this part might seem a little bit confusing, but the PWM library actually does not use the PWM peripheral - it uses the GPIOTE + TIMER peripherals to create a low-power PWM. This is better to use if the application only requires a simple, low-frequency, low-power PWM instance.

    In your case, you will rather need to use the PWM peripheral - which gives you much more options to configure the waveform generation. The PWM peripheral comes with a driver already made for it to make things easier- the PWM driver - which you should use, since you need a 400 kHz waveform.

    refer_pin said:
    By any chance you can provide me some resource I could read on or guidance so I could learn to handle these demons? I'm really new in this embedded programming stuff

    Before looking at the PWM driver demos I would recommend that you read through the PWM peripheral documentation to understand what is being done 'behind the scenes' of the PWM driver.
    Then, you could move on to the simple PWM example from the .zip file, to see if you can recognize how the things from the Peripheral documentation is being applied, in order to generate the PWM waveforms.

    The functionality of the different demos are described in the PWM driver example documentation. When you begin to look into these demos I highly recommend looking at only 1 at the time, and understanding how they perform the task as described in the documentation.

    Is there anything else in particular you would like know more about when it comes to embedded programming?
    The source code behind complex embedded example might seem daunting at first glance, when you come directly from Arduino development, but please know that it get better fast.

    In my opinion, one of the best examples to start looking at when you come directly from Arduino is probably the TIMER peripheral example. The reason why I would recommend this one in particular is because it demonstrates core functionality ( config and init of a peripheral, event handler, and LEDs ) and coding practices ( Wait-for-interrupt, error checks ), while also being contained within 108 lines of main.c code.
    When you understand every line of the TIMER peripheral example, you will be well prepared to familiarize with most of the other peripheral examples.

    refer_pin said:
    Are you referring to the zip file you attached?

    Yes. Sorry, I should have been more explicit. The .zip file I attached contains the simple pwm example.
    You will need to use the PCA10056 version for your nRF52840 DK.

    Best regards,
    Karl

  • How do I access the gpio pins of nrf52840 dk?

     I meant was how do I access for example pin P0.06 on the board? I tried looking at the pwm_library example and all I can recognized being programmed are BSP_LED_0 and BSP_LED_1?

Reply Children
  • Thank you for your patience.

    refer_pin said:
    I meant was how do I access for example pin P0.06 on the board?

    You may access P0.06 with the NRF_GPIO_PIN_MAP(0,6) function call.
    Please also know that P0.06 is usually used for the UART TX PIN in all the SDK examples.

    To see how this is all done in the nRF52840 DK file, you oculd take a look at the pca10056.h file located in SDK\components\boards\pca10056.h

    Best regards,
    Karl

  • Please also know that P0.06 is usually used for the UART TX PIN in all the SDK examples.

    Hello, 

    So what pins should I use for PWM output? I'm actually planning to push my code to an Adafruit nRF52840 Feather Board. I dont know if my process of coding the nRF52840 dk first then transferring the code to a Adafruit nRF52840 Feather Board is correct but that's my intial plan. Basing from the feather board schematics, my other pin options in the nRF52840 dk that's used in the feather board are 0.07, 0.08, 0.26, 0.27,1.08 and 1.09. From my pin options, what pins are suitable for producing a PWM of 400kHz? 

  • Hello,

    refer_pin said:
    So what pins should I use for PWM output?

    Please choose pints according to the Pin Assignment section of the nRF52840 Product Specification.
    The important part here is to check that you are not sending a high frequency signal on pins that are located close to the radio peripheral.

    Furthermore, you should also always check the Connector Interface diagram of the nRF52840 DK specification, since this will tell you which pins the DK is already using for different functionality.
    If you should need any of these pins you will have to follow the Solder Bridge documentation in order to make them available ( and thus disconnect the current functionality ).

    refer_pin said:
    I'm actually planning to push my code to an Adafruit nRF52840 Feather Board.

    I have never worked with this Adafruit module myself, but the nRF52840 SoC will still be the same - so you will just need to make sure that your program matches the pinout indicated on their board schematics. I.e if they expect UART TX to be on pin 0.06 then you should make sure this is the case in your program as well, etc.

    refer_pin said:
    what pins are suitable for producing a PWM of 400kHz? 

    Please see the Pin assignment referenced above to determine this.
    Please do not hesitate to let me know if anything should be unclear.

    Best regards,
    Karl

  • Please see the Pin assignment referenced above to determine this.

    So I looked into the Pin Assignment and Connector Interface link you sent me which is a good addition of documents to look into going forward, thanks for this. The pin that I believe would be possible to output the 400kHz PWM are P0.26 and P0.27, can you tell me if my analysis is correct or otherwise?

  • refer_pin said:
    So I looked into the Pin Assignment and Connector Interface link you sent me which is a good addition of documents to look into going forward, thanks for this.

    I am happy to hear that you found these documents useful!
    Whenever you need more pins in the future, this is exactly how you should go about choosing them.

    refer_pin said:
    The pin that I believe would be possible to output the 400kHz PWM are P0.26 and P0.27, can you tell me if my analysis is correct or otherwise?

    Yes, your analysis here is correct - you may very well use P0.26 & P0.27 for your 400 kHz outputs, no problem.
    Keep in mind that I have not checked whether P0.26 and P0.27 are already used for anything on the Feather Board you intend to use later. You should also check this, to see if these pins will be available to you when you change module as well.

    Best regards,
    Karl

Related