Laser intensity control - RAMPS 1.4 and TTL (5V) diode laser how to

Hi All,

I am new to this forum and would like to start new discussion about TTL laser control and installation of TTL laser with Repetier firmware. I  have intent to install laser on a 3D printer and I have gone through number of forums and discussions in order to get ready for this installation. Unfortunately, I realized that there is no plain explanation on what is the best method of connecting TTL controlled diode laser to a RAMPS 1.4 board with Repetier firmware. I would like to focus the discussion on engraver with Arduino Mega board with 1.4 RAMPS board and Repetier firmware. The laser I have is 15W diode laser with 5V TTL control and standalone power supply.

 Here is summary of what I learned and possible options/solutions:

 Solution 1:

Here is the link to a step by step guide on how to use laser with Marlin firmware and RAMPS 1.4 https://www.vicious1.com/wp-content/uploads/2016/01/MPCNC-laser-add-on-walk-through.pdf Very simple to follow and an excellent guide. The key point here is to remap fan output D9 (12V) to pin 44 (5V) and then use fan speed control to control laser intensity. Using the analogy from Marlin the same could be done in the Repetier firmware. Open pins.h file find where fan pin is assigned and change it from 9 to 44. Save the file and reload to Arduino. Connect Laser TTL to pin 44. Please note that I have not tried this method and I don't know if this would work (getting ready to test in few weeks). If someone has tried this with Repetier firmware and RAMPS 1.4 please share your experience within this forum. It seems that this is not recommended solution from Repetier but sounds attractive to me.

 Solution 2:

In Repetier firmware Laser mode can be enabled in the configuration process. What I hear and read is that Repeitier firmware will provide only ON and OFF laser control by using this method (correct me if I am wrong).This would not satisfy my expectations for laser control.

 Solution 3:

This is something that "Repetier" is recommending as a solution for laser intensity control. This solution requires creation of something what is called custom extensions and custom events. Although,  it sounds simple it may be difficult option for us who are not good in programming and code editing. I have not found any complete step by step guide on how this code can be changed and implemented. From my point of view this is the best option to control laser intensity with Repetier firmware but…… I don't know how to edit the code. Does anyone out there has the link or can provide how to guide for laser intensity control within Repetier firmware.

 

Regards and thank you in advance

Comments

  • 1) While it will might work. the pwm frequency is very low. V1 firmware has only software PWM normally 15Hz but can be increased up to 64Hz. If that is ok for you do it.

    2) Correct. V1 firmware has no handling for hardware PWM. With V2 this is now solved, but V2 only works on due based boards at the moment.

    3) Best solution and there are plenty of discussions about that in this forum including some code samples on how to write it. Easiest solution uses analogWrite to set intensity on the pin as if you do it in the original code directly it is just one line. Main problem is to find a pin that uses timer 4 or 5 and is not in use for anything else. Timer 0-3 are used already for stepper interrupts etc. So you can not define own hardware pwm on these pins.
  • Thank you for your answer. Solution number 3 seems to be the best and I would like to implement it. I am reading all possible forums regarding laser intensity control and I have to say that I can't close the loop and understand what to do here.... it will take some time.

    Let's assume that pin 44 is not used by timers 0-3 and it is eligible for laser intensity control. Based on your answer all I need to do is to change one line in the original code to analogWrite and this should work fine ??? This is fairly simple to do. 

    What are all those discussions about adding custom events etc.... How about frequency. The laser I have comes with independent power supply and driver (15W power  with 5V TTL input).

  • The solution with event system is the clean way that would survive updates. The one liner is a hack in the firmware source directly.

    It is all in driver.cpp

    void LaserDriver::changeIntensity(secondspeed_t newIntensity) {
    #if defined(DOOR_PIN) && DOOR_PIN > -1
        if (Printer::isDoorOpen()) {
            newIntensity = 0; // force laser off if door is open
        }
        if (EVENT_SET_LASER(newIntensity)) {
            // Default implementation
    #if LASER_PIN > -1
            WRITE(LASER_PIN, (LASER_ON_HIGH ? newIntensity > 199 : newIntensity < 200));
        }
        intens = newIntensity; // for "Transfer" Status Page
    }

    that is the original source. You see with events it can be overridden. Or you replace
            WRITE(LASER_PIN, (LASER_ON_HIGH ? newIntensity > 199 : newIntensity < 200));
    with
            analogWrite(LASER_PIN, newIntensity) ;

    analogWrite is a arduino function that sets hardware pwm using the correct time. But is also unknowing about firmware timers used so it will just modify timer settings if that pin uses timer 0-3. And if pin has no timer it won't work.
  • Great - I now understand that there tare 2 different ways of doing it. There is an advantage when the modification survives the updates so that is the way to go.

    First thing first so let's get focused on hacking source file for now.

    I used Repetier on-line configuration tool to generate configuration.h file which meets my laser engraver requirements. I have checked "support laser/engraver" check box, set "laser" as a default mode and assigned digital pin 44 as a laser enable pin. Downloaded complete firmware and opened up "Drivers.cpp" file. Here is the code from the file and it is different than what was provided in your respond (again thank you for quick respond):

    void LaserDriver::changeIntensity(uint8_t newIntensity)
    {
        if(EVENT_SET_LASER(newIntensity))
        {
            // Default implementation
    #if LASER_PIN > -1
            WRITE(LASER_PIN,(LASER_ON_HIGH ? newIntensity > 199 : newIntensity < 200));
        }
    }
    #endif // SUPPORT_LASER

    There is also Events.h file in the main directory. It looks to me that the code is calling an event (no experience with programming).

    Can you help explaining what should be done here. The version of the firmware was 0.92.9

    Thank you in advance.
    Lou
     
  • Same line to change here also same events. But why starting with such an old version. My code is from 1.0.4dev which is the currently best one.

    You either implement it in EVENT_SET_LASER which returns false after setting intensity or change the line I told you.
  • Thank you for the suggestion to use newer version.

    The reason I was using an older version is because it is the default version in online configuration tool. I assumed that the latest stable version should be set as a default.

    I have switched to 1.0.3 version which is downloaded when selecting version 1 through online configuration. This is definitely better version and now I see the same codes as in your previous respond. I think I will be OK for the next few weeks when I get my machine ready for software installation.

    By the way how do I get revision 1.0.4 which you mentioned?

    Regards,
    Lou
  • In 1.0.3 there is a selector to go to dev version which is 1.0.4dev at the moment. It will become next stable one soon. It is already more stable then 1.0.3.
Sign In or Register to comment.