Laser intensity control - RAMPS 1.4 and TTL (5V) diode laser how to
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:
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.
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.
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
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.
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).
It is all in driver.cpp
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));
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.
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)
Can you help explaining what should be done here. The version of the firmware was 0.92.9
Thank you in advance.
You either implement it in EVENT_SET_LASER which returns false after setting intensity or change the line I told you.
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?
I am totally agree with you now i am very happy to see this thread
Have a lovely day