0
\$\begingroup\$

Can anyone please describe how to use sandeepmistry nrf52 library to create an accurate microsecond timer, without using any standard delay functions.

I'm using the timer on a generic nrf52832 design I made for myself, and I want to use it to control the duty cycle of a 1 kHz square wave. I figured that if I can create a 1000 us on and off and vary the on time in 5us increments, I effectively have a 1 - 50% duty cycle output.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You're trying to do PWM in software, by employing the hardware timer units just to trigger your software.

That makes no sense. Instead, use the hardware timer units directly to create PWM.

On the NRF52xxx, I'm pretty certain you can use the DMA controller to regularly and autonomously update the counter thresholds (i.e., the duty cycle) from a buffer that your software writes to.

That way, your CPU is not tasked with doing things that are more accurate than its interrupt latency, and also not busy with doing things that the hardware timer unit can do by itself.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks Marcus, can you share a code snippet or something i can use to understand the process, as i'm new to this, thanks \$\endgroup\$ Commented May 30, 2023 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.