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
extras/replicape: support servos with linux host hardware PWM #1443
Conversation
Thanks. Interesting. Unfortunately, I don't think it's feasible to add a "hardware_pwm" option to the servo/bltouch extras. On the vast majority of boards, the cycle time of hardware pwm can not be set accurately enough to drive a servo. So, I fear adding the option would cause lots of people to enable it and then have confusing failures. The only use for hardware pwm in Klipper today is for emulating a DAC. You've indicated that the root cause of the problem is that the given pins are muxed to the hardware pwm capability of the beaglebone. Do you know what it would take to not mux those pins, so that the pru could control them? -Kevin |
The pins are muxed by the replicape device tree overlay which is applied by the boot loader since a while. I'm not sure if it is still possible (or desirable) to override pin muxes defined in device tree overlays. Also I don't see a reason to not use perfectly capable HW. |
I made the servo pins replicape specific to force the hardware_pwm protocol upon them. |
Thanks! In general, it looks good to me. A couple of minor comments:
-Kevin |
efb23a9
to
48d3eee
Compare
Don't merge for now. My extruder is suddenly skipping steps. Not sure if there's something wrong in the change or if I somehow managed to damage the replicape. I have unfortunately no time to investigate it before next week. |
The problem was a broken stepper motor cable. The change works as expected. |
Thanks. I committed the change to use 16bit integers for the pwmcmds.c code, and I also committed the Linux pwm support. I didn't commit the replicape.py code as I have a few questions.
SERVO_PINS = {
"servo0": ("pwmchip0/pwm0", "gpio0_30", "gpio1_18"), # P9_11, P9_14
"servo1": ("pwmchip0/pwm1", "gpio3_17", "gpio1_19"), # P9_28, P9_16
}
class servo_pwm:
def __init__(self, replicape, pin_params):
pwm_pin, resv1, resv2 = SERVO_PINS[pin_params['pin']]
pin_params = dict(pin_params)
pin_params[pin] = pwm_pin
# Setup actual pwm pin using linux hardware pwm on host
self.mcu_pwm = replicape.host_mcu.setup_pin("pwm", pin_params)
self.get_mcu = self.mcu_pwm.get_mcu
self.setup_max_duration = self.mcu_pwm.setup_max_duration
self.setup_start_value = self.mcu_pwm.setup_start_value
self.set_pwm = self.mcu_pwm.set_pwm
# Reserve pins to warn user of conflicts
pru_mcu = replicape.mcu_pwm_enable.get_mcu()
ppins = printer.lookup_object('pins')
ppins.reserve_pin(pru_mcu.get_name(), resv1, "servo")
ppins.reserve_pin(pru_mcu.get_name(), resv2, "servo")
def setup_cycle_time(self, cycle_time, hardware_pwm=False):
self.mcu_pwm.setup_cycle_time(cycle_time, True); -Kevin |
Thanks.
|
The servo pins (P9_14/P9_16) are muxed to the SOCs hardware PWM unit driven by a 13MHz GP timer. They have to be driven by the linux host mcu. This commits adds hardware PWM support using the linux sysfs user space interface. The servo pins can be specified as "replicape:servo0" and "replicape:servo1". Removes the "servo0_enable", "servo1_enable" configuration parameters. Fixes Klipper3d#1105. Signed-off-by: Janne Grunau <janne-3d@jannau.net>
pin names updated to servo0/1 and implemented the proposed servo pwm init method. |
Thanks. -Kevin |
Thanks for all the work so far Jannau / Kevin. Have an issue allocating the pwm device for the bltouch on a fresh Debian Stretch install, downgraded kernel to 4.4.155-ti-r154. Upgraded bb-overlays. Any help will be greatly appreciated. Host is unable to configure pwm device - MCU 'host' shutdown: Unable to config pwm device Version.sh output - |
Are you sure the PRU is set up correctly? Otherwise I don't see anything wrong there except for the obvious error to configure the pwm in the klippy.log. Config and Kernel are almost identical to mine. Please attach the output of following commands.
|
The Pru error was only temporary. That is working OK. Output of those commands below -
|
@chappo , please try
After that you should have |
Alright - so that has had resolved the issue until a reboot. Using the above export options I then need to use the chmod and permissions mod found in the 81-pwm file before restarting klipper. Can then get klipper running and deploy and retract the touch. The blue light only stays on for a few seconds and the endstop doesn't seem to trigger but they may be a fault of my touch (clone) - still working on that one. |
Yes, it's only a momentarily fix to debug why your systems behaves differently than mine. Your |
Thanks, that has resolved that issue. But still unable to trigger the end stop, and pwm only appears momentary. Blue light/servo goes off after a couple of seconds. Appreciate the work on this so far - was contemplating moving away from the replicape and back to ramps. |
The servo pins (P9_14/P9_16) are muxed to the SOCs hardware PWM unit driven by a 13MHz GP timer. They have to be driven by the linux host mcu. This commits adds hardware PWM support using the linux sysfs user space interface. The servo pins can be specified as "replicape:servo0" and "replicape:servo1". Removes the "servo0_enable", "servo1_enable" configuration parameters. Fixes Klipper3d#1105. Signed-off-by: Janne Grunau <janne-3d@jannau.net> Conflicts: config/generic-replicape.cfg
The servo pins (P9_14/P9_16) are muxed to the SOCs hardware PWM unit driven by a 13MHz GP timer. They have to be driven by the linux host mcu. This commits adds hardware PWM support using the linux sysfs user space interface. The servo pins can be specified as "replicape:servo0" and "replicape:servo1". Removes the "servo0_enable", "servo1_enable" configuration parameters. Fixes Klipper3d#1105. Signed-off-by: Janne Grunau <janne-3d@jannau.net>
The servo pins (P9_14/P9_16) are muxed as hardware pwm and can't be controlled by the PRU. Implement support for hardware pwm in the linux host mcu via sysfs. Verified to to work with a genuine BLTouch smart v3.0.