- Configuring LinuxCNC
- Basic Configuration
- Solving Reversed Spindle Speed: HAL Inversion for PWM-to-Analog (Pi5, hal_gpio)
Solving Reversed Spindle Speed: HAL Inversion for PWM-to-Analog (Pi5, hal_gpio)
- LucDav
- Offline
- New Member
-
Less
More
- Posts: 1
- Thank you received: 0
25 Jun 2025 22:10 - 25 Jun 2025 22:13 #330876
by LucDav
Solving Reversed Spindle Speed: HAL Inversion for PWM-to-Analog (Pi5, hal_gpio) was created by LucDav
Hello everyone,
I'm setting up a PWM-controlled spindle for my LinuxCNC machine. My analog DC motor controller requires a 0-10V input, which I'm generating with this specific PWM-to-analog converter: www.amazon.co.uk/Digital-Analog-Module-C...&smid=A2BXCFIGGD7VDT.
The PWM signal is sourced directly from a Raspberry Pi 5's GPIO, routed through our custom-designed isolator board HAT, V1.1, which you can find details about here: github.com/data124001/Isolation/wiki. We're running LinuxCNC version 2.9.1 and using the hal_gpio library.
The core issue is that this specific PWM-to-analog converter appears to invert the control signal: a 100% PWM duty cycle from the Pi (and hal_gpio) results in zero motor speed, while a 0% PWM duty cycle results in full motor speed. This means my spindle speed control is completely reversed from what's expected (higher LinuxCNC speed command = lower motor RPM).
We have confirmed that the PWM signal generated by the Raspberry Pi 5's GPIO (whether directly or via our custom isolator board) is behaving correctly in terms of duty cycle interpretation (e.g., 50% duty cycle is "half on"). However, without this specific PWM-to-analog converter in the loop, we have no meaningful 0-10V speed control for the motor controller, only basic on/off, as the raw PWM is unsuitable.
Therefore, the problem lies squarely with the inversion introduced by the Amazon PWM-to-analog converter itself when converting the standard Pi PWM.
My question is: What are the most effective and robust methods within LinuxCNC's HAL configuration to invert the hal_gpio PWM signal before it reaches this converter? I'm looking for a HAL-based software solution to achieve the correct 0-10V spindle speed control (where a higher LinuxCNC spindle.0.speed-out value corresponds to a higher analog voltage to the motor controller and thus higher motor RPM).
I will be attaching my HAL and INI files to this post to provide full context of my current setup.
Any specific HAL configurations or example code would be incredibly helpful!
Thanks in advance.
I'm setting up a PWM-controlled spindle for my LinuxCNC machine. My analog DC motor controller requires a 0-10V input, which I'm generating with this specific PWM-to-analog converter: www.amazon.co.uk/Digital-Analog-Module-C...&smid=A2BXCFIGGD7VDT.
The PWM signal is sourced directly from a Raspberry Pi 5's GPIO, routed through our custom-designed isolator board HAT, V1.1, which you can find details about here: github.com/data124001/Isolation/wiki. We're running LinuxCNC version 2.9.1 and using the hal_gpio library.
The core issue is that this specific PWM-to-analog converter appears to invert the control signal: a 100% PWM duty cycle from the Pi (and hal_gpio) results in zero motor speed, while a 0% PWM duty cycle results in full motor speed. This means my spindle speed control is completely reversed from what's expected (higher LinuxCNC speed command = lower motor RPM).
We have confirmed that the PWM signal generated by the Raspberry Pi 5's GPIO (whether directly or via our custom isolator board) is behaving correctly in terms of duty cycle interpretation (e.g., 50% duty cycle is "half on"). However, without this specific PWM-to-analog converter in the loop, we have no meaningful 0-10V speed control for the motor controller, only basic on/off, as the raw PWM is unsuitable.
Therefore, the problem lies squarely with the inversion introduced by the Amazon PWM-to-analog converter itself when converting the standard Pi PWM.
My question is: What are the most effective and robust methods within LinuxCNC's HAL configuration to invert the hal_gpio PWM signal before it reaches this converter? I'm looking for a HAL-based software solution to achieve the correct 0-10V spindle speed control (where a higher LinuxCNC spindle.0.speed-out value corresponds to a higher analog voltage to the motor controller and thus higher motor RPM).
I will be attaching my HAL and INI files to this post to provide full context of my current setup.
Any specific HAL configurations or example code would be incredibly helpful!
Thanks in advance.
Last edit: 25 Jun 2025 22:13 by LucDav.
Please Log in or Create an account to join the conversation.
- tommylight
-
- Away
- Moderator
-
Less
More
- Posts: 20387
- Thank you received: 6933
25 Jun 2025 22:21 #330877
by tommylight
Replied by tommylight on topic Solving Reversed Spindle Speed: HAL Inversion for PWM-to-Analog (Pi5, hal_gpio)
1 No double posting
2 most VFD's can do 0-5V or 0-10V settable, see manual
3 to invert pins on LinuxCNC it is as simple as :Should be similar for RPI, but i do not use RPI so no way of confirming from my side, give it a try.
2 most VFD's can do 0-5V or 0-10V settable, see manual
3 to invert pins on LinuxCNC it is as simple as :
setp parport.0.pin-01-out-invert 1
Please Log in or Create an account to join the conversation.
- PCW
-
- Offline
- Moderator
-
Less
More
- Posts: 18778
- Thank you received: 5187
25 Jun 2025 23:07 - 25 Jun 2025 23:10 #330878
by PCW
Replied by PCW on topic Solving Reversed Spindle Speed: HAL Inversion for PWM-to-Analog (Pi5, hal_gpio)
A guess:
setp hal_gpio.pin-40-out-invert true
Running LinuxCNC and then running:
halcmd show all | grep invert
in a terminal window should give the the exact naming syntax
setp hal_gpio.pin-40-out-invert true
Running LinuxCNC and then running:
halcmd show all | grep invert
in a terminal window should give the the exact naming syntax
Last edit: 25 Jun 2025 23:10 by PCW.
The following user(s) said Thank You: tommylight
Please Log in or Create an account to join the conversation.
- Configuring LinuxCNC
- Basic Configuration
- Solving Reversed Spindle Speed: HAL Inversion for PWM-to-Analog (Pi5, hal_gpio)
Time to create page: 0.183 seconds