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

Just getting started with Tasks and Events: PWM => SAADC

Coming from other embedded systems, I'm impressed with the flexibility and power of the Task/Event framework of the nRF52832. But with great flexibility comes great confusion! :)

I'd like to do something along these lines, written here in pidgin C:

for (int i=0; i<12; i++) {
    gpio_set(PIN_A);
    gpio_clr(PIN_B);
    pause_briefly();
    dma_buf[2*i] = saadc_read();
    gpio_clr(PIN_A);
    gpio_set(PIN_B);
    pause_briefly();
    dma_buf[2*i+1] = saadc_read();
}

My best guess as to translating this into Tasks and Events:

  • Configure PWM to drive PIN_A inverted and PIN_B non-inverted.
  • Set PWM LOOP.CNT to 24
  • Use ??? to trigger an SAADC TASKS_SAMPLE [*]
  • Use DMA to write SAADC samples into RAM
  • Use PWM's EVENTS_LOOPSDONE to trigger interrupt in user code

[*] I think I can use a second PWM channel to toggle its output shortly after setting PIN_A and PIN_B and use that to generate an Event. This event give PIN_A and PIN_B a chance to settle before triggering the SAADC read. As long as I can use any of the channel outputs to generate an event I should be okay.

So the questions:

Is this more or less the right approach? What are some good examples to use as starting points? Any gotchas I should be aware of?

My environment:

  • nRF54 dev board
  • nRF5_SDK_14.2.0
  • SEGGER Embedded Studio Release 3.30
  • macOS High Sierra 10.31.1
Related