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

[Feature request]: Dither PWM #108

Open
3 of 7 tasks
Peter-van-Tol opened this issue Aug 19, 2024 · 0 comments
Open
3 of 7 tasks

[Feature request]: Dither PWM #108

Peter-van-Tol opened this issue Aug 19, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@Peter-van-Tol
Copy link
Owner

Initial Checks

  • I have searched Google & GitHub for similar requests and couldn't find anything
  • I have read the documentation and couldn't find anything

Description

Currently the resolution of PWM is limited to the number of cycles within a PWM period. For example, when the FPGA runs on 40 MHz and a PWM frequency of 1 kHZ is requested, the resolution of the PWM is 40,000. This effect is worse on higher PWM frequencies.

One solution is to switch to PDM, which is already supported. However this mode does not have a fixed frequency and might not be supported by PWM to voltage converters.

The other solution is to implement dithering, allowing for full 32-bit resolution, regardless of the frequency. Proposed communication to PWM:

  • byte 0: pick-off (position of the decimal point);
  • byte 1-3: frequency in cycles;
  • byte 4-7: duty-cycle.

The counter for the duty cycle will be enlarged to 64-bit, fixed point (32 bit - 32 bit). At every start of a PWM cycle, this counter is increased with the value of duty-cycle (bytes 4-7), rigth-shifted with the pick-off (byte 0).

Every clock-cycle the counter of the duty-cycle will be reduced with 1.0 (0x0000000100000000). When the value of the counter is below 1.0, the output pin will be switched off until the end of the PWM cycle.

This method ensures that changing the frequency does not influence the duty-cycle counter.

Affected Components

  • CLI.
  • Supported boards (i.e. 5A-75B, 5A-75E, HUB75HAT, etc.)
  • Supported connections (i.e. SPI, Ethernet, etc.)
  • Modules (i.e. GPIO, PWM, stepgen, encoders, etc.)
  • Documentation
@Peter-van-Tol Peter-van-Tol added the enhancement New feature or request label Aug 19, 2024
@Peter-van-Tol Peter-van-Tol self-assigned this Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant