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

How to generate two complimentary 300KHz signals with specific timing

How can I generate two complimentary signals using PWM with a period of 3.33us (300khz) with ability to control number of pulses to generate.

1: With current api PWM takes period is integer values of microseconds so I can set either 3us or 4us, but I need to set 3.33us

2: How do I control exact number of pulses generated by PWM

3: For my second signal is it possible to set delay so that first signal and the second signal does not overlap

Parents
  • Hi,

    it would be too complex configuration for PWM, though maybe it's possible...  I would recommend you to use TIMER and GPIOTE for this task. Note that you cannot achieve an exact 300khz signal, either with TIMER or PWM, the closest value is 16000000/53=301.8kHz (if it matters to you). A number of pulses can be counted by an interrupt handler triggered with COMPARE[3] event.

    Here is a code that uses TIMER1:

  • How do I register an interrupt handler on compare event

  • You can look at this example (it should compile also for nRF52)

  • Thank you, that helped

Reply Children
No Data