grblHAL / LPC176x

grblHAL driver for LPC1968 and LPC1769
Other
18 stars 22 forks source link

Question/clarification - PWMs #38

Closed paukstelis closed 1 year ago

paukstelis commented 1 year ago

Sorry if this is a bit of a rudimentary question, but I haven't been able to sort it out just yet.

Background: for lack of anything better to do, I have been working on integrating a BLTouch probe on SKR 1.4 Turbo. I have it sitting around so I thought I would give it a try. It needs a PWM, which are typically defined by servo angles for it to deploy/retract.

I have it defined for PWM1_CH1 and secondary_pin. I have an init statement in driver.c, but it is unclear to me how the period and width parameters are used. It looks like the spindle period pwm defaults to 5000Hz. Is the width value simply the duty cycle for this period (0-100), or is it defined by the pwm resolution value (32bit?)?

terjeio commented 1 year ago

It is defined by the pwm resolution value. Relevant functions are are spindle_precompute_pwm_values() and spindle_compute_pwm_value(), the first precomputes some values based on settings, the second returns a PWM value (width) from RPM input. These could be adapted to use constants instead of settings data in order to generate a servo signal. See footnote 13 in the drivers overview for how it can be set for the spindle.