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
Setting to alter laser PWM frequency #55
Comments
I run a 5W Laser diode and my TTL laser driver did not like the default 1KHz PWM. I changed mine to 8KHz and it runs perfectly. The drivers documented frequency is 10KHz, but 8 is close enough. I think part of the problem was the speed I am running it. If I feed at F4800 and my resolution of the raster is 10 pixels per mm, that is 800 pixels per second. This probably means that some pixels only get 1 pulse, and some get 2. At 8KHz, each pixel get 10 shorter pulses and the result is much smoother. So to answer your question, in my situation the PWM frequency does make a difference. |
I have a 5W laser engraver with a proprietary controller and software, that can change the pwm frequency (via cycle duration in ms). This gives me the option to optimize for good grayscale or depth map. |
The PWM frequency can be changed in the cpu_map.h around line 140. |
I have a question on the PWM timer. It appears to be an 8 bit timer which is not high enough for my next project. I have a 5W laser which I use between 15-60% which gives me over 100 shades of grey and it looks fantastic. Any thoughts on what could be done to improve the resolution when using a small power range. |
@mayhem2408 : Hmm. Not 100% understanding what you are asking, but I think you are saying that your laser driver works optimally between a small range of control voltages. You'd like to have a higher resolution within this range. I'll be the first to admit that I'm not an expert at laser and their controllers. So, I'm not certain if there is another way to improve raster engravings, like altering the PWM frequency, feed rate, or laser input voltage/power. For Grbl, there isn't another timer available with a higher resolution than 8-bit. The one 16-bit timer is being used by the stepper interrupts. So, I can't help you there. However, if the voltage range is low, like 1V-2V, you could try placing a voltage divider circuit on the PWM output. This will effectively scale the output down and should improve resolution by the voltage ratio. If you want a larger range, I think there might be a way to do it if you add a voltage level shifter to bring up the low side, in combo with a voltage divider. This is all theoretical though. Another option would be to use a separate controller to convert Grbl's output to something your laser likes better. This could give you the best control, but it'll require some interrupt programming to ensure that the timing is still exact. |
Not quiet. My 50W laser is extremely powerful. At 100% power it cuts 6mm plywood. If I want to do light engraving, I need to use very low power settings. The laser controller itself is TTL triggered, so it only accepts 0 and 5V signals. Sending it 4V is still on and 1V is still off. Using PWM at 8KHz+ allows power modulation. I have an idea of using another Arduino to simply control the PWM at a higher resolution and have GRBL output power level data via i2c or onewire that the second Arduino would read. Not sure is the GRBL Arduino will have enough memory left to use these libraries though. |
@mayhem2408 : The Mega2560 would be a lot more ideal than trying to shoehorn more into the 328p version, which is completely maxed out. Over the break, I plan on updating Grbl-Mega to v1.1, so I would wait until I did that. |
Another option would be to take the PWM from GRBL, feed it into another Arduino, then scale it accordingly. So I would have a smart laser controller. GRBL outputs 0-100% at 256 steps, but the second Arduino only sends out 5-15% duty using a 16bit timer or even scaling that back to 10-12 bits giving a resolution of 100-400 steps. There would be plenty of resources in the second Arduino to have LCD screens and buttons to set it up. However, running on a Mega2560 could solve the problems. Is moving the PWM to a 16 bit timer something you would be looking at doing? |
@mayhem2408 : It's already on a 16-bit timer, but limited to 1024 levels. I can't remember the exact reason why. I think it had to do with an OEM request. |
1024 levels sounds good to me. My current driver for the 50W CO2 has 0.1% increments, which is 1000 levels and it works fine. My current 5-15% range would give me 102 levels, which is a little more that I am getting now. Can't wait to see grbl-mega with 1.1. I'll be very happy to do testing. |
Just thinking about it, at 16MHz clock, 1024 levels means about 15.6KHz PWM which is almost smack bang on the 16KHz optimal PWM of the 50W Laser Drivers power supply. |
@mayhem2408 Would you mind try my port of GRBL 1.1 on STM32 target? It can have 16 bit of PWM timer. Should be enough for your requirement. |
@usbcnc I do not have a STM32 at the moment. Can you recommend one? |
@mayhem2408 Nucleo has arduino pinout and cost ~$10 |
@mayhem2408 This is the one I use (<$2). I also bought a STlink (also < $2) to quickly program it. It can also be programmed via serial port. |
@mayhem2408 : Hang tight. I just did a preliminary port to the Mega branch. It compiles but I haven't tested yet. |
@chamnit : I'm hanging. I've got my Mega2560 on standby ready for flashing |
@mayhem2408 : Sorry, didn't get to it tonight. I was wrapped up trying to track down a critical bug related to alarms, homing, and an infinite loop. Theoretically Grbl-Mega should be good to go. If you are feeling adventurous, there's a good chance that it'll work fine. Otherwise, I'll have to get to it tomorrow. It's getting late. |
I've uploaded it to my barebone Mega2560 and so far so good. CNC.js, LaserWeb and LaserGRBL all working and reporting OK. Next is to wire up my stepper drivers to make sure they are responding OK. |
My laser cutter (HPC) has a voltage control on it. I am taking the pwm output to a simple integrator to generate a voltage for the laser based on the PWM. In order to create finer control at the lower end I am going to try a simple op-amp configured to operate with a logarithmic input to output. The circuit is simple and it should give me finer control at lower power levels. |
I just came across this and its very close to my problem. I'm looking to control welding current pulsing. I'd like to add parameters to the S word to accomplish the pulsing, for example: This should not be very complicated feature to add, but my big question is where in the code As already 8 bit pwm gives 0.5 amp resolution on 100A welder so spindle speed control should work I'm planning to use usbcnc's STM32 port Rgds, |
I have a 60W CO2 power supply, an HY-T60 as a matter of fact. It has several inputs; a TH and TL lines, as kind of enable pins; if the TH line is pulled up to 5V OR the TL line is pulled to ground, it fires. It also has an IN line, which can be controlled by 0-5V analog signal or "5V PWM f >= 20kHz". |
You should do two things:
|
@mayhem2408 could you send me the changed code that you have used. my laser is 2.5W with arduino nano but I could not make the change of kHz I think part of the problem was the speed I am running it. If I feed at F4800 and my resolution of the raster is 10 pixels per mm, that is 800 pixels per second. This probably means that some pixels only get 1 pulse, and some get 2. At 8KHz, each pixel get 10 shorter pulses and the result is much smoother. So to answer your question, in my situation the PWM frequency does make a difference."" |
Could bit banging the pulse be an option, I have my milling machine spindle driven by a variable frequency drive (Its a whopping 2 hp 3 phase motor). The frequency drive accept a 0-10v input to change its output frequency to somewhere in the region of 100hz at 50hz i get 3600R pm but at 100hz i get 7600 Rpm. The pwm from Grbl is a data value from 0 to 255 no matter what Spindle RPM min max are set. It would be nice if a digital pulse train could be output which represented pulse/hz ie a digital written frequency pulse instead of pwn (like blink without delay - basic example) Then upto 2mhz pulse is possible (without any other code) to get 2khz or even better 20khz pulse train would be damn useful. |
@MeJasonT Grbl doesn't use the arduino analogWrite, it's highly optimized and already generates the PWM itself with a timer interrupt! There is nearly no space left in the AVR328 to add a I2C or RS485 interface. I suggest to use a Mega256 or even better a 32 bit MCU. |
Hi cprezzi, I looked at cpumap.h and discovered that the output was already a bit banged signal and not analogue write. Do you have any idea how i can step up up the frequency to provide an 50% on/off pulse providing say a 2khz variable frequency. My plan is to read the frequency into another Atmega 328 which already has an rs485 interface attached and transmit a 2 byte value to a third Atmega328 which is receiving the RS485 and transmitting value to my variable frequency drive via i2c DAC IC. |
Why do you need variable frequency? That's what the VFD is for. Ususally you feed the VFD with a analog 0..10V signal (which can also be used with a potentiometer). |
@MeJasonT To get a higher resolution you could probably make a PWM to voltage converter that only creates 0..5V and add 0V or 5V in series with a mosfet from one of the digital outputs like mist or flood. |
I think, better, to use OP Amp with gain of 2, and rail-rail ability. But
you need power source with voltage over 10V.
пн, 29 окт. 2018 г., 21:19 Claudio Prezzi notifications@github.com:
… @MeJasonT <https://github.com/MeJasonT> To get a higher resolution you
could probably make a PWM to voltage converter that only creates 0..5V and
add 0V or 5V in series with a mosfet from one of the digital outputs like
mist or flood.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#55 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AU_Oc212rypCYg31amsRn0_jPRC7PLO9ks5up0aWgaJpZM4LIAu5>
.
|
ok chaps, you have missed the great big elephant. Im using an RS485 link between my control box and the Inverter panel for the milling machine, I did try to make the point that the VFD generates a hell of a lot of hf noise. Hence to separation via a 485 coms link. I have looked into plastic fibre like toslink but cant transmit the pwm/RPM signal. The receiving board attached to the vfd has an DAC ic and an opamp generating the 10v signal for the drive. |
I think sniffing the serial connection is a good idea. But be aware that Grbl has an internal serial buffer and planer queue. Command execution will be delayed by some lines, so you should count the returned ok's to know when the spindle command is executed. |
Thanks cprezzi, good point i hadn't thought about the planer queue. |
cprezzi, ive sussed out that i can sniff the verbose response using another arduino. I set up software serial and got the messages being output. i also saw the advantage of it showing the spindle speed as set in the gui (ie 7500 RPM appears as 7500) it switches as soon as the grbl gui shows the on/off function of the spindle. Now for the issue - GRBL outputs 115200 baud and the second arduino is set to communicate via software serial at the same speed - its bloody asking a lot. obviously some of the data is fragmented. Im wondering if altering the software baud rate would bring it into sync - any thoughts. The next experiment is to remove the uP IC from the second arduino board (using the board as a TTL to USB converter) and see what the data looks like then. |
Sure you could reduce the baudrate that Grbl uses, but this would also slow down the speed you can send commands to Grbl, which could lead to stutter. |
Ok Buddy, huge success sort of. I can sniff the messages being sent from GRBL back to GUI listening in on the TTL TX pin. works a treat and does not affect GRBL. Now all I have to do is parse the string and split out the bits i want (that,s the sort of bit). whats more the GUI is sending the desired RPM and not the PWM - that must be handled in the spindle code, perfect for me. Once i work out hot to parse the string i can then use the sniffer Arduino to create and send the RS485 messages to the remote device. (Just used a serial echo to bang out what was received from the GRBL TX pin) <Idle|MPos:0.000,0.000,0.000|Bf:15,128|FS:0,1000|Ov:100,100,100|A:SF> so im looking for delimiters FS: and taking the second set of values for spindle speed If you felt like writing some example parse code for me it wouldn't go unappreciated and would certainly speed things up for me. I have discovered the the same could be used to interface a Torch Height controller to my CNC Plasma table (also on GRBL). Sonny is a star, if I ever get to meet him in person he will be so drunk on the beer I owe him. I was originally thinking that i needed to control the RPM for cornering and HSM machining techniques but working on this Inverter interface i have discovered that the RPM stays constant and the feedrate is adjusted for cornering etc. I guess that's how its meant to be, so the way i'm currently running the machine by manually starting and stopping the spindle and setting the speed isn't so bad. Just a pain when i need to stop for a crash or whatever. will keep you updated on progress. J. |
Be aware that you could also override the spindle speed by 10-200% which is reflected by the Ov: response. You probably need to watch that too. Do you know "laser mode" ($32=1)? This could eventually be helpfull for your plasma cutter. See https://github.com/gnea/grbl/wiki/Grbl-v1.1-Laser-Mode for details. |
Th plasma is working 100%, I have not bothered with the laser mode. its basically 0 or 255 PWM o/p and the suds command for pilot and arc ignition. The Torch goes down to 0.5mm of the sheet metal ish. the suds is enabled - enabling the pilot relay (a 300A Motorbike starter relay) this energises for 1.5 to 2 seconds. During this time the ark is struck by switching on the spindle (Ark Trigger). The pilot is then disengaged as hopefully by this time the plasma has been created and maintains the flame - not failed yet, apart from on really shitty steel. Ive had the odd flame out when working close to the edge of the material as you would expect. The High freq noise at this point tends to kill GRBL. Best to keep inside the material edge, i now keep a 5mm border around work. all of this is operated withing the Cambam Post Processor. You know when something is working it gets left alone, i'm kind of there tight now. |
The plan for THC is to use a capacitive or laser sensor to calculate height. get the activation commands the same as i'm trying to achieve now with the serial snoop. and using the command to bypass or control the Z stepper motor. I'm not convinced i even need one, unless i'm going to cut up inclines or corrugated surfaces, like never. i need to get on and make chips really instead of all these gota have niceties. |
@chamnit hi and thank you for your effort. Have you released the 1.1f for mega already? Or is it the docwelsh the most recent? Thanks |
@mayhem2408 Can you share your hex file with 8khz pulse frequency. I have 15W laser with Elekslaser GRBL firmware and I think 8Khz would work better for engraving stainless steel. Thank you. Or is there a different way to recompile GRBL because I cant use Arduino IDE because Nano has limited memory. |
Hi, I'm jumping in to check if the frequency switch feature has been implemented. I tried to follow the different threads but couldn't find the answer. I'm sorry if I missed it in this (very long) issue ! I'm using a relay to divert the PWM from one tool to a second but they are not using the same frequency. I use M7 and M9 to set/reset the relay. So I'd like to have 2 frequency presets and be able to switch between them when using M7/M9. If the solution is not already available I don't mind modifying the source code myself but I could use some pointers on what to do / not do. Thank you in advance ! |
From #34 (comment).
Add a '$' setting to allow different laser PWM frequencies. Will likely implement this as value with the current
$32
laser mode setting, such that1
,2
, or3
would indicate different frequencies.Need to research how PWM frequencies effect lasers and whether or not this is even required.
The text was updated successfully, but these errors were encountered: