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

Spindle Enable pin isn't initialized as output. Easy fix. #63

Open
Alfrederson opened this issue Dec 17, 2018 · 7 comments
Open

Spindle Enable pin isn't initialized as output. Easy fix. #63

Alfrederson opened this issue Dec 17, 2018 · 7 comments

Comments

@Alfrederson
Copy link

Alfrederson commented Dec 17, 2018

With the code the way it is, you cannot use M3 and M5 to toggle the state of the Spindle Enable pin because it's not initialized as an output. The fix is really simple.

If you add those two lines:

GPIO_InitStructure.GPIO_Pin = 1 << SPINDLE_ENABLE_BIT; GPIO_Init(SPINDLE_ENABLE_PORT, &GPIO_InitStructure); // <--- initializes the spindle enable pin

To the file spindle_control.c, after the line 68, which initializes the Spindle Dir pin with the function

GPIO_Init(SPINDLE_ENABLE_PORT, &GPIO_InitStructure);

Then M3 Sx will turn the spindle en bit high and M5 will turn it low, just like it was supposed to be.

@robomechs
Copy link

There is USE_SPINDLE_DIR_AS_ENABLE_PIN definition.
I suppose, this repeats the functionality of the native GRBL, where the number of outputs is limited. I think it's better to leave it as is. What do you think?
see line 64 of spindle_control.c for SPINDLE_ENABLE_BIT

@Alfrederson
Copy link
Author

Alfrederson commented Dec 18, 2018

There is USE_SPINDLE_DIR_AS_ENABLE_PIN definition.
I suppose, this repeats the functionality of the native GRBL, where the number of outputs is limited. I think it's better to leave it as is. What do you think?
see line 64 of spindle_control.c for SPINDLE_ENABLE_BIT

Look elsewhere in the code. On spindle_set_state it calls a macro to change the spindle enable pin when you don't have variable spindle speed, but it does nothing because after line 64 there's a conditional define and it only configures spindle enable bit if USE_SPINDLE_AS_ENABLE_PIN is defined, and they have sepparate definitions (enable is PB 13 and dir is PB 14), so it's likely the intention was to have separate spindle enable and dir controls. Some brushless spindles have an input to change the rotation direction, and with an H-bridge a regular DC motor can be reversed as well.

When you have variable spindle enabled, the spindle dir can be toggled with M4, and the spindle pwm pin can be set to different duty cycles, therefore I think it makes sense that spindle enable be controlled separately. When variable spindle is disabled, there's no output on spindle PWM. If that was supposed to work as spindle enable too, it should be toggled, instead you have no output on either spindle pwm and spindle enable.

@robomechs
Copy link

Maybe.
You can still use spindle PWM at 100% and 0% as spindle enable bit))
Ok, we can add something like USE_BOTH_... (defined default) to use both spindle en and dir.
It is important to leave some free I/O to use it as cnc controlled I/O by M62-66 (linuxcnc style) codes at future.

@Alfrederson
Copy link
Author

Alfrederson commented Dec 18, 2018

Maybe.
You can still use spindle PWM at 100% and 0% as spindle enable bit))

Kind of. The relay will hum if I do that.

@robomechs
Copy link

Why? 0% is full off, 100% is full on. It is equal to digital output off/on.

@Alfrederson
Copy link
Author

Just think of it this way: there's a pin definition for a spindle enable pin, which is different from the spindle dir. If the code is kept the way it is, the spindle enable pin will never be toggled, regardless of #defines, because it isn't ever initialized as an output. Does that sound like an intented feature?

The relay hums with an S value of anything other than 100. Yes, always use M3 S100, but how about the fact that the pin does nothing when reading through the comments would indicate it does?

@Blocheren
Copy link

I have this issue, and I can't figure it out. I'm on the verge of buying a blackbox.. 🤷😅🥴

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants