Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Change the PWM frequency #2

Closed
americodias opened this issue Oct 4, 2021 · 5 comments
Closed

Change the PWM frequency #2

americodias opened this issue Oct 4, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@americodias
Copy link

americodias commented Oct 4, 2021

Hi Khoi,

Describe the bug

I'm not sure if this is a bug or a "feature", but I wanted to dynamically change the PWM frequency and I'm not able to do so using the setPWM function.

Steps to Reproduce

Example code: https://pastebin.com/raw/bAJ09Jn9

Expected behavior

I was expecting to have 2s of 1000Hz and then 2s of 2000Hz repeatedly.

Actual behavior

Frequency stays constant at 1000Hz.

Thanks,
Américo

@americodias
Copy link
Author

americodias commented Oct 4, 2021

Hi again,

I forgot to mention that if I instantiate new objects each time it works:

void loop()
{
  delay(200);
  frequency = 1000;
  PWM_Instance = new RP2040_PWM(pin0, frequency, 50);
  PWM_Instance->setPWM();

  delay(200);
  frequency = 2000;
  PWM_Instance = new RP2040_PWM(pin0, frequency, 50);
  PWM_Instance->setPWM();

}

But this is not optimal I guess.

EDIT: As I expected this will end up crashing as you are instantiating new objects without deleting the previous ones.

Kind regards,
Américo

@khoih-prog
Copy link
Owner

Hi @americodias

Thanks for reporting an interesting bug due to my fault. I'm releasing by today the new release v1.0.2 to fix the issue.

I'd really appreciate your contribution. Happy bug finding.

Best Regards,

KH

khoih-prog added a commit that referenced this issue Oct 4, 2021
### Releases v1.0.2

1. Fix bug not changing frequency dynamically. See [Change the PWM frequency #2](#2)
khoih-prog added a commit that referenced this issue Oct 4, 2021
### Releases v1.0.2

1. Fix bug not changing frequency dynamically. See [Change the PWM frequency #2](#2)
@khoih-prog
Copy link
Owner

khoih-prog commented Oct 4, 2021

Hi @americodias

The new RP2040_PW releases v1.0.2 has just been published

Your contribution again has been noted in Contributions and Thanks

Check the new PWM_DynamicFreq example and verify if it's OK now.

The library is definitely better and more useful now. Looking forward to receiving more bug reports from you.

Best Regards,

KH


Releases v1.0.2

  1. Fix bug not changing frequency dynamically. See Change the PWM frequency #2

@khoih-prog khoih-prog added the bug Something isn't working label Oct 4, 2021
@americodias
Copy link
Author

Hi @khoih-prog,

Thanks for the quick fix. I will test it asap.

Kind regards,
Américo

@khoih-prog
Copy link
Owner

Hi,

Be sure to test using the new and better RP2040_PWM releases v1.0.3

Thanks,


Releases v1.0.3

  1. Not reprogram if same PWM frequency.
  2. Add PIO strict lib_compat_mode

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants