-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
expand pwm max value to 16 bit for avrs #3612
expand pwm max value to 16 bit for avrs #3612
Conversation
Signed-off-by: Pascal Pieper <[email protected]>
Unless I'm missing something, all of the cycle_time calculations in -Kevin |
I will check this soon, thanks for the fast comments |
As I understand, the AVR-Code currently picks the closest PWM frequency to the requested cycle_time. My suggestion is to have a different behavior for 8bit and 16bit PWM:
Unless choosing very fast PWM-Frequencies, the resolution decrease would max out at half (so 15 bit). What are your thoughts about this, @KevinOConnor? "Implicit" behaviour of resolution changes may confuse the power-user, but would not break currently running systems (as long as they did not use a 16bit hard-pwm pin with a cycle time near zero) |
Signed-off-by: Pascal Pieper <[email protected]>
I'm not sure I understand. Are you proposing that we be able to hit higher frequency cycle times by using less bits in the "on duration" setting? And similarly, obtain lower frequency cycle times by going up to 16 bits? If so, I suppose it could be done, but I'm not sure what the use case is. Currently, Klipper's hard pwm feature is mostly used as a "poor man's DAC". That is, it's mostly used to approximate an analog voltage level (via resistor/capacitance circuit) for applications that need that. In particular, stepper motor driver reference voltage lines. I've also seen it used to try and provide a lower voltage level to some fans. For these applications I haven't seen a need for more precision or faster switching rates. How do you intend to use the hardware pwm feature and what precision / switching rate do you need to obtain? -Kevin |
Correct. The timers can be resetted when hitting a specific value, effectively increasing the frequency at the expense of resolution, so using a 16-bit timer will not reduce the maximum PWM frequency but even increase it.
I want to use a higher resolution with the laser-extension (laser_fork, #133). |
Okay, I understand.
FYI, a 1ms cycle_time is well within the range of the software pwm implementation. And the software pwm code will provide excellent precision. The software pwm code can have some scheduling jitter, but I'd guess it would be less than 20us for at least 99.9% of updates on AVR (and likely <5us for ARM chips). I don't know if that kind of jitter is acceptable for your application though. If you do feel it's necessary to use hard pwm, my suggestion would be to not attempt to increase the frequency. (Thus always having at least 8bits of precision, and not make notable changes to the 8-bit timers.) For the 16bit timers, though, I don't see any harm in bit shifting to obtain similar cycle times with higher precision. -Kevin |
I'd also mention that bit shifting an arbitrary amount (eg, -Kevin |
I did not expect it to be, but that would be great. Then I would not need the 16-bit HW-PWM resolution.
I will test that. 20µs at 1ms cycle time is 2%, thats probably unnoticable. |
I tested the soft-pwm with good results. |
This enables AVR-Chips to use the full PWM resolution if available on the pin