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

Invert VARIABLE_SPINDLE PWM output #246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dingorock
Copy link

Adds the option to invert the duty cycle of the variable speed spindle output pin.
Tested with VFD Controller (Huanyang Invertor Model: HY01D523B)

@Ruisjm1
Copy link

Ruisjm1 commented Aug 27, 2017

Is possible star a file on specific line?

@dgarrigop
Copy link

It doesn't work for me, no signal on the 11 pin.

@dingorock
Copy link
Author

Sorry to hear that. Did you remember to uncomment line 214 in config.h?

// Invert the PWM signal for VARIABLE_SPINDLE
// #define INVERT_SPINDLE_PWM // Disabled by default. Uncomment to enable.

It's disabled by default for the pull request.

Maybe an interaction with some other spindle related setting?

@dgarrigop
Copy link

Yes I did, But now I'm trying with the normal code and no pwm signal on D11. Any suggestion?

@dingorock
Copy link
Author

dingorock commented Sep 25, 2017 via email

@dgarrigop
Copy link

I've tried with 2 different arduinos, both connected to cnc shield and disconnected. Checking the D11 with a tester.

@biasedlogic
Copy link

You sure you are on the right pin? The pin changes when you enable PWM

@jahnj0584
Copy link

jahnj0584 commented Sep 25, 2017 via email

@dgarrigop
Copy link

dgarrigop commented Sep 25, 2017

yeah, I did it, and doesn't work. The only way I can make my Laser work It's to enable USE_SPINDLE_DIR_AS_ENABLE_PIN and plug the laser to the spindle dir pin. (No pwm enabled)

PS: Now PWM is working but no inverting, even uncommenting INVERT_SPINDLE_PWM

@dgarrigop
Copy link

Updating: I used a nand on the output and comment out the INVERT_SPINDLE_PWM, eveything works fine now.

@Harvie
Copy link

Harvie commented Mar 16, 2019

Why do you need to invert duty cycle? For me it worked uninverted with HY VFD...

@OhmsLawBreaker
Copy link

hey,

any more detail on how anyone was able to get this to work? ive tried enabling USE_SPINDLE_DIR_AS_ENABLE_PIN and VARIABLE_SPINDLE with no luck. my laser just stays active on the +Z pin

@JBSchueler
Copy link

my laser just stays active on the +Z pin
Why do you connect your laser to +Z?

image
The laser must be connected to pin 11 (Variable Spindle PWM).

@Harvie
Copy link

Harvie commented Nov 23, 2020

Now there seems to be quite elegant solution integrating Huanyang RS485 communication directly to GRBL, i would be happy if you can help with testing:
terjeio/grblHAL#68

@oMtQB4
Copy link

oMtQB4 commented May 4, 2021

Does not work for me. I added a new pull request (#1040) with a different approach to invert PWM signal.

@semka95
Copy link

semka95 commented Dec 7, 2021

This PR does not work for me, I applied it to the latest available commit (bfb67f0). PR #1040 from @oMtQB4 works fine, except in my case laser does not operating at full power, it much weaker than it was before. I tried to fix #1040 version, but I wasn't successful. So I fixed this PR.
I took this code from @oMtQB4 PR:

uint8_t corr_pwm_value;
#ifdef INVERT_SPINDLE_PWM
  corr_pwm_value = 255 - pwm_value;
#else
  corr_pwm_value = pwm_value;
#endif
SPINDLE_OCR_REGISTER = corr_pwm_value; // Set corrected PWM output level.

and replaced SPINDLE_OCR_REGISTER = pwm_value; at the beginning of void spindle_set_speed(uint8_t pwm_value) function.

After this correction everything works perfect, PWM is inverted and laser is operating at full power.
I want to thank everyone involved in this discussion, without your help, I could not get the laser to work.

This is whole code for the function void spindle_set_speed(uint8_t pwm_value)
// Sets spindle speed PWM output and enable pin, if configured. Called by spindle_set_state()
// and stepper ISR. Keep routine small and efficient.
void spindle_set_speed(uint8_t pwm_value)
{
uint8_t corr_pwm_value;
#ifdef INVERT_SPINDLE_PWM
  corr_pwm_value = 255-pwm_value;
#else
  corr_pwm_value = pwm_value;
#endif
SPINDLE_OCR_REGISTER = corr_pwm_value; // Set PWM output level.
#ifdef SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED
  if (pwm_value == SPINDLE_PWM_OFF_VALUE) {
    spindle_stop();
  } else {
    SPINDLE_TCCRA_REGISTER |= (SPINDLE_TCCRA_ENABLE_PWM_MASK); // Ensure PWM output is enabled.
    #ifdef INVERT_SPINDLE_ENABLE_PIN
      SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT);
    #else
      SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT);
    #endif
  }
#else
  if (pwm_value == SPINDLE_PWM_OFF_VALUE) {
    SPINDLE_TCCRA_REGISTER &= ~(SPINDLE_TCCRA_ENABLE_PWM_MASK); // Disable PWM. Output voltage is zero.
  } else {
    SPINDLE_TCCRA_REGISTER |= (SPINDLE_TCCRA_ENABLE_PWM_MASK); // Ensure PWM output is enabled.
  }
#endif
}

@dimanjy
Copy link

dimanjy commented Dec 20, 2022

Is there any way to include this PR into GRBL?

@sandmanRO
Copy link

Hello @dingorock, just a suggestion... when you turn off the PWM the D11 pin goes low (0V), right? In terms of inverted PWM this is equivalent of 100% duty cycle. Would not be more consistent when turning off the PWM to also set the D11 high, that is, again in terms of inverted PWM equivalent of 0% duty cycle? So the inverted PWM disable code would look like this:

SPINDLE_TCCRA_REGISTER &= ~(SPINDLE_TCCRA_ENABLE_PWM_MASK);
SPINDLE_PWM_PORT |= (1 << SPINDLE_PWM_BIT);

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

Successfully merging this pull request may close these issues.

None yet