PSON Macro not working as intended.
-
My current setup is:
Duet 3 clone with RRF 3.4
24v PSU
Duet tool board v1.2
RPI4 on it's own dedicated PSU
5v PSU powering a latching relay and PSON to the Duet clone. The latching relay closes the neutral circuit for the main 24v PSU.
A momentary button wired as NO to io3.in configured in config.g asM950 J1 C"!0.io3.in" ; Create GPIO pin for On button wired NO M581 T2 P1 S1 R0 ; T2-Run Trigger 2; P1-J1; S1-When button pressed; R0-trigger any time
The trigger file is configured as:
M80 C"pson" ; Power on G4 P200 ; wait 2ms M98 P"config.g" ; run config.g to re-recognize toolboard G4 P400 ; wait 2ms if sensors.gpIn[1].value = 1 ; check if button still pressed M291 P"Power off" S1 T2 ; G4 S1 ; give time to let go of the button to prevent accidental power on M81 ; turn off power
When the button is quick pressed it will power on the printer, when the button is long pressed it will power off the printer.
I know this works because I have it setup in the exact same manner on my other Duet 3. Only difference is it's not a clone. I have it setup this way because after M81 is ran and the main PSU is off but the Duet 3 clone is in standby mode powered by the 5v PSU, the tool board doesn't reconnect to the Duet 3 clone without running config.g again so the normal On/Off button in DWC doesn't work correctly.
If I press the power button or run the macro manually it will power on the main PSU but power it off again.
-
Anyone have any ideas what's going on?
-
@dhusolo could it be caused by a difference in how long it takes config.g to run?
Why not run config.g only if power was off at the start of the macro? You can test whether power is present either using the atxPower field in the OM if M80 or M81 has already assigned a pin, or by testing the reported VIN voltage.
-
@dhusolo said in PSON Macro not working as intended.:
Anyone have any ideas what's going on?
Your trigger macro works more or less "by accident", depending on the timing of config.g as @dc42 points out, and depending on the bouncing behaviour of your button. In addition (and as @dc42 says), you forgive the chance to check power before you turn it on, regardless of state, which, in turn, ultimately runs the config.g.
I think you should rework your macro:
- wait 50-100 ms for the button to debounce, then, check its state again: if it is open, quit the macro with
M99
. - if ATX power is off, put it on, then, run your config.g
- else, wait another second or two (whatever you consider a long press), then check its state: if it is still pressed, turn ATX power off.
Depending on your timings (aka "button press habits"), you can add a loop to wait for the button to be released; this would then be called after steps 2. or 3., regardless of which branch you took.
- wait 50-100 ms for the button to debounce, then, check its state again: if it is open, quit the macro with