I'm rebuilding a laser CNC machine and using LaserWeb4 as the control interface and GRBL 1.1 as the low-level interface to the stepper motors, limit switches and the laser. I have all the motion sorted out and am working on the laser control.

enter image description here

Figure 1. The GRBL 1.1 pinout. Pin 11 is used for spindle (cutter) speed on a milling machine or laser power control on a laser cutter.

The machine is using a Synrad 48 Series laser module which requires a 5 kHz PWM frequency (page 45 - 46).

The GRBL 1.1 sketch can be configured for a variety of PWM frequencies. See cpu_map.h.

  // Prescaled, 8-bit Fast PWM mode.
  #define SPINDLE_TCCRA_INIT_MASK   ((1<<WGM20) | (1<<WGM21))  // Configures fast PWM mode.
  // #define SPINDLE_TCCRB_INIT_MASK   (1<<CS20)               // Disable prescaler -> 62.5kHz
  // #define SPINDLE_TCCRB_INIT_MASK   (1<<CS21)               // 1/8 prescaler -> 7.8kHz (Used in v0.9)
  // #define SPINDLE_TCCRB_INIT_MASK   ((1<<CS21) | (1<<CS20)) // 1/32 prescaler -> 1.96kHz
  #define SPINDLE_TCCRB_INIT_MASK      (1<<CS22)               // 1/64 prescaler -> 0.98kHz (J-tech laser)

  // NOTE: On the 328p, these must be the same as the SPINDLE_ENABLE settings.
  #define SPINDLE_PWM_DDR     DDRB
  #define SPINDLE_PWM_BIT     3    // Uno Digital Pin 11

It seems that my options are 62.5 kHz, 7.8 kHz, 1.96 kHz or 0.98 kHz.

Why does it matter? Two excerpts from the Synrad manual:

Tickle frequencies [a 'keep-awake' signal at zero power] lower than 4.5 kHz may compromise laser performance, ..., and stress the RF [radio frequency] electronics thereby reducing long term reliability while tickle frequencies greater than 5 kHz may cause unintended lasing.

Because laser output follows PWM input with a rise and fall time constant of ~100 µs, the laser cannot precisely follow Command signal frequencies over t kHz with duty cycles greater than 50%.

Can anyone see a workaround for this within the constraints of the GRBL configuration?

I can only think of a hardware solution to filter the PWM out and run it through another device to convert the analog signal to a 5 kHz PWM.

Many thanks.

  • I'm trying to do the same thing and the answer to your question could save me a lot of time. Did you have to filter the PWM out and run it through another uno to convert the analog signal to a 5 kHz PWM? – Pete May 20 at 13:54

No, you cannot have hardware PWM at 5 kHz on pin 11 of an Arduino Uno. The closest you can get is 3.92 kHz. You get that by setting the prescaler to 8 and configuring the timer for phase correct PWM, instead of the fast PWM mode usually used by GRBL. Your options for getting 5 kHz are to use either software PWM or change the pinout.

You can get a quite accurate 5 kHz PWM signal on pins 3, 9 and 10. You can do software PWM at 5 kHz on any pin, but this is prone to have significant jitter, which your laser may well not like.


The simple way, which may interfere with the timing of your other digital outputs: https://playground.arduino.cc/Code/PwmFrequency

Or, if you are willing to put the PWM output on pin 9/10 and manipulate the AVR registers directly:

Digital pins 9 (OC1A) and 10 (OC1B) are outputs of the AVR 16-bit timer (TIMER1) on 328p. With those you can get a PWM signal at 5.000 kHz, but if you need reliability then an Arduino with external crystal resonator may be needed. You will need to set the registers TCCR1A, TCCR1B and OCR1A,OCR1B,ICR1,TIFR1 appropriately, details can be found in the AVR datasheet.

  • The ceramic resonator of the Uno is reliable, if neither accurate nor stable. – Edgar Bonet Aug 16 '18 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.