Hello Guest it is January 08, 2026, 02:10:11 PM

Author Topic: Can't seem to get PWM output  (Read 438 times)

0 Members and 1 Guest are viewing this topic.

Can't seem to get PWM output
« on: December 31, 2025, 07:02:37 PM »
Hello all,

I am trying to convert from a simple spindle on/off relay to full control with speed.  I have choosen Port 2 Pin 4 as my PWM port, and Port 2 pin 5 as my DIR port.  The DIR works fine and is switching the CNC4PC C41 board appropriately.    But I cannot get Mach4 to send PWM at all.  I am using an Ethernet Smoothstepper and have followed all of their instructions, and double checked that against the Mach4 instructions for PWM spindle, and that also jives with the CNC4PC published instructions.   I have an oscilloscope on the PWM line to monitor it.  I do have pins 2-9 on port 2 set as output, have set all appropriate settings in both the ESS spindle config, output pins, pins config menus as well as the spindle menu in Mach4 under general config.
I know the pin works ok as when I switch it back and forth from active high to active low in PINS Config, I see the Oscope trace move from 0 to 5 volts and back.  But regardless, I cannot get ANY PWM out.
Would anyone have any suggestions on where I might look to see my error?
Thanks
James
Re: Can't seem to get PWM output
« Reply #1 on: January 01, 2026, 11:35:52 AM »
OK, further testing has helped me narrow the problem down.

If I start Mach4, and hit either of the Spindle CW or Spindle CCW buttons, the appropriate relay is selected but I get no PWM.  If I go to MDI and issue a spindle command (M03 S24000 for example), everything works perfectly.  I get exactly the right PWM, the spindle spins to 24K CW.  From this point on, ALL buttons and sliders work perfect.  The On/Off CW/CCW and speed slider adjusts the spindle exactly how it's supposed to!  It's only when Mach4 starts up and before issuing an MDI command manually that PWM will not work.   I checked into the screenset (using wxRouter) and I see that the CW button calling a lua script called "StartCW()" which I assume is an internal script.

I am doing my best learning about screensets and Lua scripts, but it seems like when Mach4 starts, some variable isn't passed into the Lua script to give it a value for the PWM/Speed?  I'll continue learning about this, but if anyone has an idea on what might be missing on startup, I'd appreciate any pointers.
Thanks!

James
Re: Can't seem to get PWM output
« Reply #2 on: January 02, 2026, 06:00:50 AM »
The C25 has LEDs on all I/Os, so you should see the LED for the PWM light up as soon as it is sending 100%.  There are other parameters that you are not showing in the screenshots.

It may be easier if you set up a new test profile and just run the installer to configure the C25XP on it: https://www.cnc4pc.com/knowledge/article/249

That way, you will have a working profile from which you can copy the working configuration.

Arturo Duncan
https://cnc4pc.com
Re: Can't seem to get PWM output
« Reply #3 on: January 02, 2026, 07:46:25 PM »
Thanks Arturo,  but I don't have a C25.   I don't really think I need it, I've got the PWM problem resolved, I just can't figure out the Mach4 spindle buttons.  Very strange that they work (the on/off and speed slider) fine AFTER you issue ANY M03 or M04 command, but not until then.  Gotta be a variable or something not populating at Mach4 startup I am thinking, but I am deep in learning how all the Lua stuff works right now in hopes that that will uncover what's going on here.

Thanks
James
Re: Can't seem to get PWM output
« Reply #4 on: January 03, 2026, 04:16:20 AM »
Isn't this just a case of it doesn't know what spindle speed you want, so it's not going to start until you tell it a speed? You could type a speed into the 'PGM RPM' DRO below the Spindle On/Off button before pressing the button, or you could modify the SpinCW() function to set an S value.
Re: Can't seem to get PWM output
« Reply #5 on: January 03, 2026, 10:00:27 PM »
SwiftyJ,

You nailed it... sometimes I have to remember to step back and look at the bigger picture. I didn't even realize you could enter into that particular box.  When I do this, it works just as it should.  I was mistakenly interpreting the SRO slider bar as the spindle output, but by it's own definition, it's an override % and not the absolute value of the speed!  I keep thinking that hitting 100% would set the speed to 100% but that's 100% of the set value (which was zero). 

Thank for the insight there. Sometimes it takes another set of eyes to help get a fresh perspective.  Many thanks for the pointer, it's working exactly right and I just didn't understand all the screen elements!

Thanks again,
James