setPWM latency #19
Replies: 4 comments 3 replies
-
I suggest you to use the Lines 279 to 280 in 353f9e3 Check these examples to see how you can use and adapt if OK If still not fast enough, you have to use |
Beta Was this translation helpful? Give feedback.
-
I tried it out. It is much faster. It is approximately 2us instead of 32us . Thanks again for the help. |
Beta Was this translation helpful? Give feedback.
-
Hi @jmdodd95682 Just modify the code and I'm able to reduce nearly 50%. Now the new I'll publish the new release ASAP for you to test Releases v1.6.0
|
Beta Was this translation helpful? Give feedback.
-
Hi @jmdodd95682 The new RP2040_PWM v1.6.0 has just been published. Your contribution is noted in Contributions and Thanks Have a look at the new PWM_SpeedTest example Please test and don't hesitate to report bug / issue or request enhancement. Even a simple discussion can lead to new and better library features. Best Regards, |
Beta Was this translation helpful? Give feedback.
-
I noticed that executing the setPWM command has approximately a 32us latency. Which I guess would normally be fine, but if you're trying to use it to generate audio, this is too slow. You need to update the duty cycle of the PMW out faster than that. Or at least I would want it to be faster for my purposes. Is this expected?
I thought, at first, it was somehow related to the PWM frequency, but regardless of duty cycle and frequency the latency is about 32us. It is a very tight loop. The only other things in the loop take about 1us. The output pin in the code below is toggling at about 29KHz. When I comment out the setPWM it toggles at about 490KHz.
void loop()
{
digitalWrite(digPin,dig_output);
dig_output^=0x01;
data=testpattern[testdata_count];
testdata_count=(testdata_count+1)%624;
PWM_Instance->setPWM_Int(pinToUse, frequency, data);
}
Beta Was this translation helpful? Give feedback.
All reactions