Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing hangs when toggling pin #17747

Closed
aero4 opened this issue Apr 27, 2020 · 2 comments
Closed

Printing hangs when toggling pin #17747

aero4 opened this issue Apr 27, 2020 · 2 comments

Comments

@aero4
Copy link

aero4 commented Apr 27, 2020

Bug Description

I made my own gcode to toggle the LED lighting of my printer.
I am working with Marlin V2.0 (newest).
I added the new gcode (777) function to gcode/gcode.cpp (inside the switch case of "GcodeSuite::process_parsed_command") and also to gcode/gcode.h to the class "GcodeSuite".
For the actual code I added a new file called 777.cpp with the following content:

#include "../gcode.h"
#include "../../MarlinCore.h"

/**
 * M777: Switch printer lighting on/off
 *
 *  P(pin)      - Pin number
 *  T(bool)     - Toggl lighting on/off
 *  S(state)    - Switch lighting on if 1 and off if 0
 */
void GcodeSuite::M777()
{

  const int pin_index = PARSED_PIN_INDEX ('P', GET_PIN_MAP_INDEX (LED_PIN));
  //SERIAL_ECHO_MSG("pin_index: ", pin_index);
  if (pin_index < 0) return;

  const pin_t pin = GET_PIN_MAP_PIN(pin_index);

  if(parser.seenval('S'))
  {
    const byte status = parser.value_byte();

    if(status == 1)
    {
     pinMode(pin, OUTPUT);
     extDigitalWrite(pin, 1);
    }else if(status == 0)
    {
     pinMode(pin, OUTPUT);
     extDigitalWrite(pin, 0);
    }else
    {
     return;
    }
  }

  if(parser.seenval('T'))
  {
    pinMode(pin, OUTPUT);
    extDigitalWrite(pin, !extDigitalRead(pin));
  }
}

Expected behavior:
Pin / LEDs toggle on or off

Actual behavior:
Pin / LEDs are toggling but the printer movements are hangig for about 2s but only when switching the pin off...

Additional Information

This only happens when switching off (S=0)... This happens with the T command and the S command.
To send the gcode and control the printer I use a MKS TFT32 V3.0. My Mainboard is Bigtreetech SKR V1.3.
I also implemented a switch wchich is polled inside the endstop timer-interrupt with a smilar code and it also happens when i trigger the switch to off...

I additionally found out that the pause probably happens after the gcode buffer is empty.
With a "normal" gcode it's happening, but not with the following:

M82
M106 S0
M104 S200 T0
M104 S0 T1
M104 S0 T0
M280 P0 S90 ; push BLTouch pin up
M106 S0 ; switch off part fan
G28 X Y; home all axes
G0 X0 Y0 F6000 ; go to home position with 6000mm/min speed
G0 Z10
T0 ; select tool 0

G1 F6000 Y50 X100

G1 F6000 X200
G1 F6000 X100
G1 F6000 X200
G1 F6000 X100
G1 F6000 X200
G1 F6000 X100
G1 F6000 X200
G1 F6000 X100
G1 F6000 X200
...
@aero4
Copy link
Author

aero4 commented Apr 27, 2020

I found that this problem is pin related.
I used pin 1.31 of my board which is additionally SCK1/AD0.5.
When I changed the pin to 3.25 which is additionally MAT0.0/PWM1.2 (which is simply the pin below at the plug I used) everything works fine!

I am not familiar enough with Marlin but I think this pin is used anywhere and problems are caused when switching it...
So the bug is "resolved"...

@aero4 aero4 closed this as completed Apr 27, 2020
@github-actions
Copy link

github-actions bot commented Jul 2, 2020

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant