pwm_tool: Add support for high-speed PWM pin updates

The output_pin module is only capable of updating an output pin at
most once every 100ms.  Add a new pwm_tool module that is capable of
queuing updates in the micro-controller and thus allowing for much
higher update rates.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2023-10-13 21:10:11 -04:00
parent 48a05eaa54
commit 29b7550ce5
8 changed files with 201 additions and 17 deletions

View file

@ -3127,6 +3127,26 @@ pin:
# parameter.
```
### [pwm_tool]
Pulse width modulation digital output pins capable of high speed
updates (one may define any number of sections with an "output_pin"
prefix). Pins configured here will be setup as output pins and one may
modify them at run-time using "SET_PIN PIN=my_pin VALUE=.1" type
extended [g-code commands](G-Codes.md#output_pin).
```
[pwm_tool my_tool]
pin:
# The pin to configure as an output. This parameter must be provided.
#value:
#shutdown_value:
#cycle_time: 0.100
#hardware_pwm: False
#scale:
# See the "output_pin" section for the definition of these parameters.
```
### [static_digital_output]
Statically configured digital output pins (one may define any number

View file

@ -834,7 +834,8 @@ commands to manage the LED's color settings).
### [output_pin]
The following command is available when an
[output_pin config section](Config_Reference.md#output_pin) is
[output_pin config section](Config_Reference.md#output_pin) or
[pwm_tool config section](Config_Reference.md#pwm_tool) is
enabled.
#### SET_PIN

View file

@ -318,7 +318,8 @@ is defined):
## output_pin
The following information is available in
[output_pin some_name](Config_Reference.md#output_pin) objects:
[output_pin some_name](Config_Reference.md#output_pin) and
[pwm_tool some_name](Config_Reference.md#pwm_tool) objects:
- `value`: The "value" of the pin, as set by a `SET_PIN` command.
## palette2

View file

@ -1,7 +1,7 @@
# Using PWM tools
This document describes how to setup a PWM-controlled laser or spindle
using `output_pin` and some macros.
using `pwm_tool` and some macros.
## How does it work?
@ -26,14 +26,6 @@ so that when your host or MCU encounters an error, the tool will stop.
For an example configuration, see [config/sample-pwm-tool.cfg](/config/sample-pwm-tool.cfg).
## Current Limitations
There is a limitation of how frequent PWM updates may occur.
While being very precise, a PWM update may only occur every 0.1 seconds,
rendering it almost useless for raster engraving.
However, there exists an [experimental branch](https://github.com/Cirromulus/klipper/tree/laser_tool) with its own tradeoffs.
In long term, it is planned to add this functionality to main-line klipper.
## Commands
`M3/M4 S<value>` : Set PWM duty-cycle. Values between 0 and 255.