Controlling my Huanyang inverter using the X-Controller

Hi. Controlling my Huanyang inverter using the X-Controller.

For sometime now I’ve wanted to forward start and set the rpm using the x-controller.

I have a 1.5 kw water cooled spindle mounted on my Shapako2, upgraded to an X-Carve. So far this setup as worked fine.

manually starting the vfd using the front panel.

After some help from members on this forum I think I’ve got external control using g-code in my .nc files.

This is what works for me:

To forward start I connected the DCM and FOR inputs on the VFD to a 5v relay. The relay is controlled by the M8 and GND outputs on the X-Controller.

To control the RPM I connected the ACM and VI inputs on the VFD to the Spindle (0-10v) and GND outputs on the X-Controller.

My Huanyang settings:

Pd001 set to 1 (this allows external control for starting/run, forward in my case)
Pd002 set to 1 (this allows external control for RPM)
Pd014 set to 3 (this ramps up the zero to full rpm time to 3 seconds)
Pd015 set to 3 ( this ramps down the rpm to zero in 3 seconds)

All other settings were left the same in my case.

Arduino settings:

$30 set to 24000.
$31 set to 0.


I’ve modified my post processor to include:

This line at the beginning of the file.
M8 M3 S? (whatever rpm you want, 0 - 24000 in my case)

This line at the end.
S0 M5 M9

These settings work for me on my machine.

Back story - I’m using an x-controller to control my cnc machine (not x-carve), movement works fine. Started working on VFD connections and figured this working example would be fine. I have 0 wires connected to the X-controller, just testing for correct V responses.

So I continued to test this evening with my x-controller. I’m seeing what i think is strange behavior. I have my X-controller connected to power and my laptop via USB - no wire connections. Using a voltmeter I am trying to check voltages for my VFD (0-10V Spindle) and Spindle ON/Off relay on M7 port.

What I would expect to see is close to 0V on both those connections and then when I issue the M7 command to turn on my spindle I should get a constant 5V from the M7 connection for my relay. Then I issue the M3 S24000 command and I should expect to see 10V or close to it from the Spindle (0-10V) connection. Then if I change the “S” value for speed I should see the Volts change on Spindle(0-10V) connection as thats how my VFD will read the speed input. When I issue the command M9 M5 S0 - everything should go back to 0V.

What I do see is 0.06V on both M7 and Spindle(0-10V) at rest. When I issue the M7 command I get a spike of ~0.43V quickly and then returning to .06V, M9 gives me a quick spike of ~0.18V returning to the 0.06V within a second. M3 S24000 (max of my spindle) will give me a quick spike to 0.18V and then return to 0.06V, changing speed will give a quick spike to .10V and return to 0.06V.

Using M7/M8 to activate a 5V relay for accessories should be doable, correct? I never seen that 5V to activate and keep my relay active and if I never get ~10V out of the analog spindle connection, my VFD will never get up to speed.

Am I missing something?

Thanks - Jer

The behavior that you expect is correct assuming that your rpm range is set to 0 - 24000 in grbl.

Check the internal cables to make sure they are all seated in their sockets properly. The retaining clips will close without the cables being fully seated.

Issue an M3 S0 command and measure the voltage on the PWM output of the X-controller. Should be close to 0 volts. Issue an M3 S24000 and measure the voltage on the PWM output. Should be close to 5 volts.

As a side note you can only draw a maximum of 40mA from any Atmega328P pin which the M7/M8 outputs use on the X-controller.

You may have a bad main circuit board.

Try using the M8 (flood) to activate a 5 volt relay. I think M7 (mist) needs to be setup when grbl is compiled.
M8 = on M9 = off.

Spindle (0-10v). Have you set:
$30 set to 24000.
$31 set to 0.
M8 M3 Sxxxxx (xxxxx - whatever rpm you want, 0 - 24000 in my case)
S0 M5 M9


Thank you both for replying.

I get the same results with M8, I measured it at the same time I was doing the others. I do have $30 and #31 set correctly.

I’ll take apart the X-Controller and see if I missed anything. I figured it was good as movement X/Y/Z is perfect but there could be something wrong in the cables that connect top card to the bottom card.


After opening the X-Controller I tried to verify everything and noticed some weird Voltage from the power supply. I had an extra laying around so I replaced it and things seem MUCH better with the voltage tests. M8 and M7 will give a solid 4.99-5.01V when activated and M3 S24000 shows 9.98V, S12000 shows 5.01V. This seems to be acting as expected now.

Thanks - I’ll let you know how it goes tonight when connected to the relay and VFD.


1 Like

So glad you found the problem. If you have any issues connecting or setting up the VFD please just ask.

I’m having issues now with the VFD actually doing anything from UGS. I did set PD001 * PD002 to 1. I think my settnigs are correct in for the VFD,If I set PD001/2 back to 0 and try to manually run the spindle by pressing the “RUN” button it spins up to 400Hz in the 4 seconds I set via PD014.

FIXED THIS PART - PD002 = 1 is control knob!! The knob doesn’t seem to do anything, it did when I first had it plugged in and tested manually but now as soon as I hit run it spins up to 400HZ, this happened after I did a Reset, so I’m guessing that is a setting somewhere.


Update - I now have the spindle speed being controlled by UGS. M3 S## commands work fine - only AFTER I manually hit the RUN button on the VFD. If I set PD001=1 and issue M8 my relay lights but it doesn’t seem to do anything on the VFD.


What type of relay are you using? (picture).

Please tell me I’m a moron and it has to do with the fact that its input of VDC and LOAD of VAC and it should be VDC for both.

No, you have it hooked up correctly, but the Arduino (X-controller) I/O pin cannot supply enough current to turn that type of relay on directly.

Depending on how good you are with electronics there are several ways to correct it so that your system will work with that relay.

1 Like

That’s a better answer than I’m a moron :slightly_smiling_face:

I figured that since it was 3-32VDC and my M8 pinout was giving me 4.98V I would be ok. Is there a relay you would recommend that could work.


1 Like

Here is the best off the shelf solution, an IoT relay box.

It’s 120 vac at 12 amps if that works for you.

You can make yours work with less money, but not quite as convenient.

It all depends on the characteristics of the relay.

Here is one that will turn on with 15mA and should work in your system.

The data sheet.

Well, I think I’ll just try hooking a light up to my SSR and see if M8 activates it.

This I’m certain wont work as the purpose of activating the relay is just to create a “short” between two pins"DCM and FOR". There is no power needed for the application.



Ok, I was looking at your setup, not the issue.

Here is what you need. It’s a relay module designed to work with 5 volts (eg. micro-processor I/O pins).

I have many of these and they work well.

Here is another relay that would work.

The SSR that you have in your system will not work as it depends on having an AC signal across the high voltage terminals.


I have a generic version of that module and I don’t remember what I found when I tested it. If I get some free time I’ll check it again to see if it works when using a direct connection from the micro-processor.

Since I added circuitry to bump the control voltage up to 24 volts (just something higher than 5 volts I had available) I think there was a problem running with a 5 volt control signal.

EDIT: Actually, I have the exact module that Jeremiah has.

Larry, thanks for the help. That makes sense as to why it’s not working then. I ordered a few of the relay modules your suggested as well as a few others.

Will let you know how it goes when they come in.


1 Like