How use MB2HAL with Huanyang FC01 :
1) Install userspace component if you don't have it:sudo apt install linuxcnc-uspace linuxcnc-uspace-dev
2) create fc01_vfd.ini
Code:
[MB2HAL]
# === Serial Port Settings ===
TYPE=rtu
DEVICE=/dev/ttyUSB0
BAUD=9600
PARITY=E
STOPBITS=1
DATABITS=8
SLAVE=1
POLL_RATE=100 ; ms
#=========================================================
# WRITE REGISTERS
# =========================================================
# HAL pin: hy.fc01.control → Modbus register 0x2000
# Example values:
# 0x0001 = Forward Run
# 0x0002 = Reverse Run
# 0x0005 = Stop
# 0x0006 = E-Stop
# 0x0007 = Reset Fault
[WR_REG_1]
MBREG=0x2000
HALPIN=hy.fc01.control
TYPE=u16
# HAL pin: hy.fc01.freq_set → FC01 expects freq ×100
# Write float in Hz, MB2HAL will convert via SCALE
[WR_REG_2]
MBREG=0x2001
HALPIN=hy.fc01.freq_set
TYPE=float
SCALE=100 ; multiply when writing
# =========================================================
# READ REGISTERS
# =========================================================
# Output frequency (×100)
[RD_REG_1]
MBREG=0x3001
HALPIN=hy.fc01.freq
TYPE=float
SCALE=0.01 ; divide when reading
# Bus Voltage
[RD_REG_2]
MBREG=0x3002
HALPIN=hy.fc01.busvolt
TYPE=float
# Output Voltage
[RD_REG_3]
MBREG=0x3003
HALPIN=hy.fc01.outvolt
TYPE=float
# Current
[RD_REG_4]
MBREG=0x3004
HALPIN=hy.fc01.current
TYPE=float
# Speed (RPM)
[RD_REG_5]
MBREG=0x3005
HALPIN=hy.fc01.speed
TYPE=float
# =========================================================
# ERROR HANDLING
# =========================================================
# Create a HAL bit pin that becomes TRUE if MB2HAL detects a Modbus exception
[ERROR_BIT]
HALPIN=hy.fc01.fault
3) create vfd.hal
Code:
loadusr -W mb2hal fc01_vfd.ini
net spindle-enable => hy.fc01.control
loadrt mux2 count=1
addf mux2.0 servo-thread
# select direction code
setp mux2.0.in0 1 # forward
setp mux2.0.in1 2 # reverse
net spindle-reverse mux2.0.sel
net spindle-code mux2.0.out => hy.fc01.control
net spindle-speed-cmd => hy.fc01.freq_set
4) add vfd.hal to your machine ini file