Cartographer (STM32F042 HW PWM as CLK OUT) - #7091
Conversation
401baf2 to
ddaeb3b
Compare
|
Interesting. Unless I'm missing something though, this change may break other users of hard_pwm. The current hard_pwm interface assumes that "cycle_time" is approximate while pwm duty times are accurate. This seems to change that (cycle_time may be more accurate, but some pwm duty cycles can raise a shutdown). FWIW, have you considered adding a new Cheers, |
|
Interesting, I never thought about it in an accurate/approximate way. Hmm, I somewhat assumed that it is better to avoid adding entities because this would multiply the amount of work required (no entity - magic behavior, feedback 1 entity, general timer interface - many entities). So, I'm cool with that, I will update. Thanks. |
ddaeb3b to
8c87f88
Compare
|
Now it should look better. Also works as expected. (I realized that Thanks. |
|
Thanks. It seems fine to me. The only thing I'm not sure on is the name "gpio_clock_output" - I know I suggested that name, but I'm unsure of my suggestion. Lets give a few days and see if there are other thoughts. -Kevin |
|
In my head, there are only 2 possible users for now: Carto and IDM (old rp2040 carto). So, maybe it could be renamed as: Thanks. |
|
Another possibility might be "pwm_clock" (thus being similar to "pwm_tool" and "pwm_cycle_time"). Cheers, |
|
I guess the current pwm_tool/pwm_cycle_time implies that it is configurable from runtime with -Timofey |
|
Thank you for your contribution to Klipper. Unfortunately, a reviewer has not assigned themselves to this GitHub Pull Request. All Pull Requests are reviewed before merging, and a reviewer will need to volunteer. Further information is available at: https://www.klipper3d.org/CONTRIBUTING.html There are some steps that you can take now:
Unfortunately, if a reviewer does not assign themselves to this GitHub Pull Request then it will be automatically closed. If this happens, then it is a good idea to move further discussion to the Klipper Discourse server. Reviewers can reach out on that forum to let you know if they are interested and when they are available. Best regards, PS: I'm just an automated script, not a human being. |
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
To support the cartographer, it is required to output 24 MHz. With current defaults max output frequency is: 48 MHz/256 = 187.5 KHz Adjusting the PWM scale allows for ramping up the frequency. To not mess up with existing PWM users, define the STM32-specific command. Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
94782d4 to
0603a44
Compare
0603a44 to
48c7183
Compare
|
Thanks. In general it seems fine. Why does -Kevin |
57ec590 to
4f62aff
Compare
|
Thanks, Fixed. Not sure about practical usage of inversion, but let it be. -Timofey |
|
Ah, yeah, I guess 'invert' doesn't make much sense if it's 50/50 duty cycle. Not a big deal either way. Probably best to remove the now unused Otherwise, let me know when you are ready and I will commit. Thanks, |
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
4f62aff to
6a49c06
Compare
|
Oops, Fixed. Tested one last time, it is ready on my side. Thanks, |
|
Thanks. I committed this along with a minor change in 7377da6 on top. -Kevin |
The goal: be able to output a timer/high-frequency clock on the pin.
TLDR, Cartographer uses the PB4 pin as CLK IN on the LDC1612.
I'm not sure if it is possible or if it makes sense to do the same for other boards, or, though, to implement a different (from PWM) command.
For now, the current code for STM32F042 would allow us to set the frequency as high as 48_000_000 / 256 = ~187500.
Or (half of that, I'm still a little bit puzzled with PWM registers).
Any smaller value would be technically NoOp.
Technically, it is possible to adjust the MAX_PWM if the cycle time is too low, which I do in the PR.
That can create confusion if we try to set the PWM value larger than the new MAX_PWM.
As there is no way to actually feed back the value.
(Well, I can add feedback for that, probably:
sendf("config_pwm_out oid=%c max_pwm=%u",...);)But I hope that, for now wrong configuration should be handled by shutting down on a value larger than the actual MAX_PWM.
I tested it with an oscilloscope and the following snippet:
If I try to set a larger value, it will fail as expected, with:
STM32F1/F401 seems to have a lower
FREQ_PERIPHvalue, so I guess they are slightly more susceptible to hitting this code path.Hope that sounds sane.