Are there any output compare examples that directly accesses the registers?

I am trying to use output compare to make a particular pin output high for 0.8 us. However, I am not particularly familiar with the nRF52840. I am wondering if there's any sample code that'd help me get started? 

Parents
  • Hi,

    You can see a similar example here. This is for continously toggling a pin, so for outputting a single pulse hou would do it slightly differently, but this shows the principle. Adjusting this to making a simple pulse could be by triggering the first pin toggle as the timer starts counting, and toggling it once more and stop the timer (using the STOP shortcut).

    For reference, you can also do this with the nrfx drivers, which you can find an example of under modules/hal/nordic/nrfx/samples/src/nrfx_gppi/one_to_one/.

Reply
  • Hi,

    You can see a similar example here. This is for continously toggling a pin, so for outputting a single pulse hou would do it slightly differently, but this shows the principle. Adjusting this to making a simple pulse could be by triggering the first pin toggle as the timer starts counting, and toggling it once more and stop the timer (using the STOP shortcut).

    For reference, you can also do this with the nrfx drivers, which you can find an example of under modules/hal/nordic/nrfx/samples/src/nrfx_gppi/one_to_one/.

Children
  • Thank you! 

    Would it be possible to toggle a pin high and low for different durations? Here’s the scenario I’d like to achieve:

    1. Toggle the pin high for 0.8 microseconds.
    2. Set the pin low for 0.4 microseconds.
    3. Set the pin low again for an additional 0.8 microseconds.
    4. Finally, stop by stopping the timer.


    Initially, I considered configuring two separate events for the same pin. However, I came across a post suggesting that having multiple events configured to the same pin might not be advisable.

    As a newcomer, I would greatly appreciate any recommendations or best practices on how to approach this.

  • Hi,

    There is no problem having several events connected to the same task, but you cannot have one task for setting high and one for setting low. Sou you have to use toggle on GPIOTE. Then, you can do something like this:

    • Configure two TIMER CC registers (for the times you want)
    • Configure PPI to trigger the GPIOTE toggle task from both CC register on comare event
    • Configure the second compare register to clare the timer with a shortcut (if you want this to run continiously) or to stop if you want this a sa single pulse

    Then it wold work liek this:

    1. Timer starts
    2. When timer reaches the first/lowest CC register, the pin is toggled via PPI
    3. When timer reaches the second CC register, the pin is togglled again and the timer resgtarts from 0 (back to 1.) or is stopped, depending on configuration.
Related