-
Notifications
You must be signed in to change notification settings - Fork 957
Set PWM frequency #855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't think this is as simple as it seems. Usually chips can control multiple PWM channels (where one channel is usually mapped to one pin) with a single PWM peripheral that runs on a given clock. This means that you can only change the frequency for multiple channels/pins at once. Ideally we would need to look at a few chips from a few different vendors to see how the hardware usually works, to make sure such an API would map cleanly to the underlying hardware on as many chips as possible. If you have ideas of what a good API would look like that would be great. |
Piezos/buzzers and servos (and LEDs and motors) likely need different combos of duty cycle and frequency (which will affect the resolution of the output). e.g. an LED / piezo / buzzer can probably do a duty cycle of 0%-100% at whatever frequency you want, e.g. 1000Hz frequency, 10% duty cycle => 100ms on, 900ms off, and the resolution is probably fine in 1% increments (10ms) a consumer servo has very specific needs: 40-50Hz pulse rate (20-25ms), resolution ~180 degrees ( 0-255 is probably fine for most applications) which has to span a range between about 1-2ms => the clock cycles need to be 1ms/256 = ~4us => ~250kHz But as @aykevl says, running servos and LEDs at the same time on the same timer hardware is not trivial. I'm planning on implementing some attempts at it on the |
Hi, I also need to set the frequency on a atsamd21 to be above 20khz. I have some code for C++ but I have no idea how to translate that to Golang. I even do not understand whats going on in C++, but it works the last time I played around with that. Code can be found here somewhere in this thread: forum.arduino.cc It would be perfect if I could set the frequency globally with |
This is now implemented in the latest release, see #1121. |
Uh oh!
There was an error while loading. Please reload this page.
Can you add a method for setting PWM's frequency in the near future? It would be useful for controlling passive piezo buzzers and servos. (I'm having trouble using the buzzer driver in repo tinygo-org/drivers on my Arduino Uno.)
Thanks.
The text was updated successfully, but these errors were encountered: