config: Fix M300 beeper example. ()

The M300 example macro now sets the PWM cycle time to generate the requested
frequency. 'scale' did not have the desired effect. Duty cycle is now
fixed at 0.5. All S parameter values less than 1 generate a 1Hz 'tone'
to avoid division-by-zero.

Signed-off-by: Stefan Holst <mail@s-holst.de>
This commit is contained in:
s-holst 2021-07-21 00:00:11 +09:00 committed by GitHub
parent 103dcf27ff
commit c20a830e63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -72,9 +72,7 @@ value: 0
shutdown_value: 0
# Disable at emergency shutdown (no PWM would be available anyway).
cycle_time: 0.001
# PWM frequency : 0.001 = 1ms will give a base tone of 1kHz
scale: 1000
# PWM parameter will be in the range of (0-1000 Hz).
# Default PWM frequency : 0.001 = 1ms will give a tone of 1kHz
# Although not pitch perfect.
[gcode_macro M300]
@ -83,7 +81,7 @@ gcode:
{% set S = params.S|default(1000)|int %}
# Use a 10ms duration is P is omitted.
{% set P = params.P|default(100)|int %}
SET_PIN PIN=BEEPER_pin VALUE={S}
SET_PIN PIN=BEEPER_pin VALUE=0.5 CYCLE_TIME={ 1.0/S if S > 0 else 1 }
G4 P{P}
SET_PIN PIN=BEEPER_pin VALUE=0