Skip to content
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

High Resolution PWM control #140

Open
zxia545 opened this issue Nov 19, 2022 · 5 comments
Open

High Resolution PWM control #140

zxia545 opened this issue Nov 19, 2022 · 5 comments

Comments

@zxia545
Copy link

zxia545 commented Nov 19, 2022

I have a problem with the current protocol to control Arduino to generate high-resolution PWM. Since some Arduino can config some timers from 8-bit to 16-bit such that PWM can be controlled more accurately. However, due to the current protocol design, it can only transfer 14-bit of data for PWM control.

In my project, I have to change Arduino Firmata Express and Python Pymata4 to achieve a maximum transfer of 21-bit to achieve this case of use.

Just wondering if anyone else needs this feature.

@pgrawehr
Copy link
Contributor

I'm not sure I understand your requirement. Do you need a higher resolution of the duty cycle (e.g 16 bits) or a way to set the frequency (for which there's currently no option in the protocol)?

@zxia545
Copy link
Author

zxia545 commented Dec 23, 2022

I'm not sure I understand your requirement. Do you need a higher resolution of the duty cycle (e.g 16 bits) or a way to set the frequency (for which there's currently no option in the protocol)?

Yap, I need a high-resolution duty cycle and the current protocol does not directly support it. (But it is not a problem, can be easily modified to achieve that )

@pgrawehr
Copy link
Contributor

Yap, I need a high-resolution duty cycle and the current protocol does not directly support it.

That's not exactly correct. To use more than 14 bits for the PWM resolution, you can use the EXTENDED_ANALOG message (described here) instead of the fixed-length ANALOG_MESSAGE. To take advantage of this, you need a board that supports the higher resolution, of course.

@zxia545
Copy link
Author

zxia545 commented Dec 23, 2022

Yap, I need a high-resolution duty cycle and the current protocol does not directly support it.

That's not exactly correct. To use more than 14 bits for the PWM resolution, you can use the EXTENDED_ANALOG message (described here) instead of the fixed-length ANALOG_MESSAGE. To take advantage of this, you need a board that supports the higher resolution, of course.

I used an Arduino MEGA2560 and I can change some registers to let it support higher resolution. After that, it becomes a little bit different since I cannot directly call Arduino analogWrite() method.

@pgrawehr
Copy link
Contributor

analogWrite() takes an int (16 bit) as the second argument, so this should actually work. Have you created a test sketch that uses analogWriteResolution and analogWrite to test how this works with 16 bits?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants