547,593 active members*
2,610 visitors online*
Register for free
Login
IndustryArena Forum > OpenSource CNC Design Center > Arduino > Change spindle pwm pin in GRBL-Mega1.1
Results 1 to 4 of 4
  1. #1

    Join Date
    Aug 2021
    Posts
    2

    Change spindle pwm pin in GRBL-Mega1.1

    Hello, long-time lurker here with a question that I cannot for the life of me solve on my own. I have been at this for a couple weeks now and I am hoping that I can solicit some help here.

    I have learned lots about GRBL in the past weeks, but most of it is thinks I was doing wrong and teaching me that I don't like the way grbl is supposed to be compiled, or how the pins are called out.

    I have a laser that I am wanting to control with pwm using the GRBL-Mega fork. I am using a MKS Gen L board, so the default pin 8 for PWM spindle control is too high of a voltage. My other problem is that pin 6 is also not working and therefore I need to switch to another PWM pin. I have Pin 11 free right now, but even if I switch the DDR and PORT to B and the PWM-Bit to 5, nothing happens on pin 11. I am assuming that it has something to do with the other lines above that make no sense to me.

    Does anyone have a good method or resource for changing the pins used in grbl? I would be forever indebted to you as this is a project for my wife and she is not happy that I cannot get it working.

    Thanks

  2. #2
    Registered
    Join Date
    Mar 2015
    Posts
    335

    Re: Change spindle pwm pin in GRBL-Mega1.1

    I had a short look at the Grbl-Mega code
    void spindle_init()
    {
    // Configure variable spindle PWM and enable pin, if required.
    SPINDLE_PWM_DDR |= (1<<SPINDLE_PWM_BIT); // Configure as PWM output pin.
    SPINDLE_TCCRA_REGISTER = SPINDLE_TCCRA_INIT_MASK; // Configure PWM output compare timer
    SPINDLE_TCCRB_REGISTER = SPINDLE_TCCRB_INIT_MASK;
    SPINDLE_OCRA_REGISTER = SPINDLE_OCRA_TOP_VALUE; // Set the top value for 16-bit fast PWM mode
    SPINDLE_ENABLE_DDR |= (1<<SPINDLE_ENABLE_BIT); // Configure as output pin.
    SPINDLE_DIRECTION_DDR |= (1<<SPINDLE_DIRECTION_BIT); // Configure as output pin.

    pwm_gradient = SPINDLE_PWM_RANGE/(settings.rpm_max-settings.rpm_min);
    spindle_stop();
    }
    It seems the PWM signal is generated by a hardware timer. The PWM pin can't be changed without changing the Timer.

    If the voltage level of the default pin is the only problem, use a level converter to solve this problem.
    https://www.sparkfun.com/products/12009

  3. #3

    Join Date
    Aug 2021
    Posts
    2

    Re: Change spindle pwm pin in GRBL-Mega1.1

    Unfortunately I would be converting 24V to 5V. So that level converter won't work.

    Do you have any idea if there are resources on how to change the timer to work with the changed pin? I know some arduino, but not this much.

  4. #4
    Registered
    Join Date
    Mar 2015
    Posts
    335

    Re: Change spindle pwm pin in GRBL-Mega1.1

    I googled your MKS Gen L board board. It seems to be a ramps compatible board and could run on grbl-mega or Marlin firmware. On my Mega board and ramps shield (1.4 & 1.6) the output is 12V because the ramps shield is powered by 12V!
    The proposed level converter can handle an input of 20V and a supply voltage of 50V


    - You could drive an optocoupler board (may need a resistor in series, depending of the optocoupler board) as level converter
    - You could solder a wire on the FET input than you have 5V PWM
    - You could power your board by 20V and use the proposed level converter

    If you google
    ramps pwm laser
    you can find more info for remapping pins for laser support

Similar Threads

  1. How to find the right pin and Port for my PWM / and or Analog voltage output?
    By johnansaro in forum Mach Software (ArtSoft software)
    Replies: 2
    Last Post: 05-01-2018, 05:42 PM
  2. GRBL: EN pin on the Pololu A4988 driver board is staying high.
    By crchisholm in forum Uncategorised CAM Discussion
    Replies: 7
    Last Post: 02-24-2018, 01:55 AM
  3. PWM 10V on PIN
    By marek.m in forum Machines running Mach Software
    Replies: 1
    Last Post: 12-28-2017, 03:35 AM
  4. Spindle PWM, issues changing PWM prescale, X-axis "rings"!
    By durbs in forum Dynomotion/Kflop/Kanalog
    Replies: 1
    Last Post: 12-10-2016, 07:40 PM
  5. RetinaEngrave PWM Output pin
    By Greolt in forum General Laser Engraving / Cutting Machine Discussion
    Replies: 2
    Last Post: 08-15-2012, 04:26 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •