Feature request: Proper M300 implementation

I would like an official M300 implementation which is not a macro. The macro does work for me, but it is quite slow, and with faster music, it causes delays. I am requesting an M300 implementation that can work properly with faster paced music/beeps.

Hello @Vintorez !

Jukebox?

1 Like

I should clarify, between M300 commands there is a delay, in my case around 200ms between each M300 command since the only way currently is the Macro.

I load M300 music GCode files, and the faster ones have timing issues with the Macro

I’m pretty sure that this is not going to happen with main-line Klipper.

  • Klipper is focused on high-speed and high-quality printing.
  • It should be in your best interest to minimize unrelated functionality, as they can and will lead to errors like Timer too close sooner or later. Diverting precious timing resources away from relevant tasks can cause these issues.
2 Likes

Okay, thanks for letting me know, I might create a fork to do some experimentation.

After a little bit of tinkering, I have discovered that there is a GCode bottleneck of around 10 commands per second in my case, confirmed by tinkering with a klippy extra to see if the Macro was to blame. I see now that an official implementation would not be feasible with this bottleneck.

It really would depend on your MCU processor and ram
A pi zero might bottleneck as to where a pc repurposed with 3ghz and 4 pkus GB ram would not.
Things like this are probably why additional timers are not implemented

If you’re running a PC fork it into klipper and see how it goes, but a small PI will likely struggle !

Amd since klipper is mostly built around the Pi it probably wont be inplimented!

This has not to do with processor power.
The “bottleneck” is the command queue that has to be worked through until the M300 command appears.

Use M400 after M300

this is my M300:


[gcode_macro M300]
description: Gcode para generar sonidos en el altavoz
gcode:
    # Use a default 1kHz tone if S is omitted.
    {% set S = params.S|default(880)|int %}
    # Use a 10ms duration if P is omitted.
    {% set P = params.P|default(300)|int %}
    SET_PIN PIN=BEEPER_pin VALUE=0.5 CYCLE_TIME={ 1.0/S if S > 0 else 1 }
    #SET_PIN PIN=BEEPER_pin VALUE=0.5 CYCLE_TIME=0.0011363
    #G4 P{P}
    SET_PIN PIN=BEEPER_pin VALUE=0

and this one my Macro BEEP, this is enough from my point of view:


[gcode_macro BEEP]
description: Emite un pitido.
gcode:
    M300 P200 S880