Modbus drivers for NF 9000 VFD

More
17 Apr 2018 14:51 #109192 by Donno
Thanks for quick reply

NF9000.ini

[MB2HAL_INIT]
INIT_DEBUG=3
HAL_MODULE_NAME=mb2hal
SLOWDOWN=0.0
TOTAL_TRANSACTIONS=3

[TRANSACTION_00]
#REQUIRED: You must specify either a "serial" or "tcp" link for the first transaction.
#Later transaction will use the previous transaction link if not specified.
LINK_TYPE=serial
SERIAL_PORT=/dev/ttyS0
SERIAL_BAUD=19200
SERIAL_BITS=8
SERIAL_PARITY=none
SERIAL_STOP=2
SERIAL_DELAY_MS=3
MB_SLAVE_ID=1
FIRST_ELEMENT=58
NELEMENTS=1
MB_TX_CODE=fnct_03_read_holding_registers
MB_RESPONSE_TIMEOUT_MS=500
MB_BYTE_TIMEOUT_MS=500
HAL_TX_NAME=OutputSpeed
MAX_UPDATE_RATE=0.0
DEBUG=1

[TRANSACTION_01]
MB_TX_CODE=fnct_16_write_multiple_registers
FIRST_ELEMENT=14
NELEMENTS=16
HAL_TX_NAME=Control
MAX_UPDATE_RATE=0.0

[TRANSACTION_02]
MB_TX_CODE=fnct_16_write_multiple_registers
FIRST_ELEMENT=0
NELEMENTS=1
HAL_TX_NAME=SetSpeed
MAX_UPDATE_RATE=0.0

custom.hal

loadusr -W mb2hal config=NF9000.ini

net spindle-speed-out-rps-abs => mb2hal.SetSpeed.00
net spindle-cw motion.spindle-forward => mb2hal.Control.10
net spindle-ccw motion.spindle-reverse => mb2hal.Control.14

VFD Modbus

Main Speed frequency set is on #Register 0

Value of 0.00hz~650.00 hz but its unsign int need to write 0-65000 [Write]

Forward, Reverse and stop is on same #Register 14 [Write]
Stop = 00
Forward = 10
Reverse = 14

Output speed in RPM is on #Register 58 [Read or Monitor]

When mb2hal.Control.10 it does not change on the vfd P014 to 10 and mb2hal.Control.14 does not change P014 to 14 any idea why ?

Please Log in or Create an account to join the conversation.

More
17 Apr 2018 15:01 #109197 by Todd Zuercher
In a hal file command line such as:
net spindle-cw motion.spindle-forward => mb2hal.Control.10
mb2hal.Control.10 would be a pin name. (which in this case shouldn't exist and should stop Linuxcnc from starting.)
It does not set the value to 10, it would set the value of that pin to the value of the signal it is connected to by the net command (in this case probably a 1 or 0)

I misunderstood what you were trying to do in my first post and tried to correct in my last one.
Hopefully my last post will clear some of the water I muddied.

Do you have a link to your drives modbus documentation?

Please Log in or Create an account to join the conversation.

More
17 Apr 2018 15:19 - 17 Apr 2018 15:24 #109198 by Donno
Hi if mb2hal.Control.00 is the pin name how do you write value 14 to it ?

The Register #14 uses decimal values think the vfd converts it to octal. If you look at my second post on page one you can see i am using Modbus poll on windows to read and write to the vfd

My VFD is NF-9000 found exactly same manual online but they just call it a WL-9000

WL-9000 Manual

On page 39 it uses all the Same Commands except for P014 "Temperature examining form
set " changes to Control code CC on page 119 in chapter 7

So when using modbus the P014 changes to Control code CC example :

So P000 is Register#0
So P001 is Register#1
So P002 is Register#2
So P003 is Register#3
....
Except P014 changes to Control code CC[page 119] so the Control code CC is Register#14
....
So P099 is Register#09

I have personally gone through all of them and read them by modbus poll
Last edit: 17 Apr 2018 15:24 by Donno.

Please Log in or Create an account to join the conversation.

More
17 Apr 2018 16:06 #109203 by Grotius
Hi Donno,

If you start up linux with terminal, and say in terminal by option's, do it quick during start up "only read option" what is your terminal saying during
the modbuss connection?

Please Log in or Create an account to join the conversation.

More
17 Apr 2018 16:09 #109204 by Todd Zuercher
From what I see in the manual your register #14 is set up as an octal (4bit) int.

Stop = 0 (Bits 0,0,0,0)
Reset = 1 (Bits 0,0,0,1)
Forward = 2 (Bits 0,0,1,0)
Reverse = 6 (Bits 0,1,1,0)
FWD Jog = 10 (Bits 1,0,0,0)
REV Jog = 14 (Bits 1,1,0,0)

So you files would be:
NF9000.ini
[MB2HAL_INIT]
INIT_DEBUG=3
HAL_MODULE_NAME=mb2hal
SLOWDOWN=0.0
TOTAL_TRANSACTIONS=3

[TRANSACTION_00]
#REQUIRED: You must specify either a "serial" or "tcp" link for the first transaction.
#Later transaction will use the previous transaction link if not specified.
LINK_TYPE=serial
SERIAL_PORT=/dev/ttyS0
SERIAL_BAUD=19200
SERIAL_BITS=8
SERIAL_PARITY=none
SERIAL_STOP=2
SERIAL_DELAY_MS=3
MB_SLAVE_ID=1
FIRST_ELEMENT=58
NELEMENTS=1
MB_TX_CODE=fnct_03_read_holding_registers
MB_RESPONSE_TIMEOUT_MS=500
MB_BYTE_TIMEOUT_MS=500
HAL_TX_NAME=OutputSpeed
MAX_UPDATE_RATE=0.0
DEBUG=1

[TRANSACTION_01]
MB_TX_CODE=fnct_15_write_multiple_coils
FIRST_ELEMENT=14
NELEMENTS=4
HAL_TX_NAME=Control
MAX_UPDATE_RATE=0.0

[TRANSACTION_02]
MB_TX_CODE=fnct_16_write_multiple_registers
FIRST_ELEMENT=0
NELEMENTS=1
HAL_TX_NAME=SetSpeed
MAX_UPDATE_RATE=0.0

custom.hal
loadusr -W mb2hal config=NF9000.ini

net spindle-speed-out-rps-abs => mb2hal.SetSpeed.00
net spindle-on => mb2hal.Control.01
net spindle-ccw motion.spindle-reverse => mb2hal.Control.02

Please Log in or Create an account to join the conversation.

More
17 Apr 2018 16:11 #109205 by Todd Zuercher
Both pins mb2hal.Control.01 and mb2hal.Control.02 will need to be true for the spindle to run in reverse. That is easily done if the hal files is configured correctly.

Please Log in or Create an account to join the conversation.

More
17 Apr 2018 16:58 #109209 by Donno
Thanks for reply :)

So if i understand correctly,
Reverse =Bits ( 0, 1, 1, 0)
Writing coils will write the individual bits (mb2hal.Control.03, mb2hal.Control.02, mb2hal.Control.01, mb2hal.Control.00) that is fnct_15_write_multiple_coils and fnct_16_write_multiple_registers will write an integer ?

I also tried those setting but it is not working is there a test program in linux like modbus poll using debain ?

it does not even change on the physical vfd !

Please Log in or Create an account to join the conversation.

More
17 Apr 2018 17:41 #109212 by Todd Zuercher
Classicladder in Linuxcnc also has modbus capabilities. I used it initially with my setup for testing. It's been a long time and I don't remember much of the details.

I could not use it with my final set up because I needed to write to too many registers (I am controling 8 VFDs on 1 machine and with it I could only run 4)
With it I was able to at least test the registers and commands to them.

You can test hal commands using halrun. Open a terminal, type halrun. You will then get a halcmd prompt. From there you can type any command that you would use in a hal file (with tab completion).
, load mb2hal from there, type showpin to get a list of avalible hal pins. Use setp to change the value of any avalible hal pins.

Please Log in or Create an account to join the conversation.

More
19 Apr 2018 08:41 #109285 by Donno
After spending the last 2 days figuring out the problem this is what i came up with so far. The main problem was

SERIAL_PORT=/dev/ttyS0 in NF9000.ini should be SERIAL_PORT=/dev/ttyUSB0 that is why linuxcnc never gave an error when disconnecting the USB because i was writing to parallel port :dry:

So i tried to use hal commands(Read the manual for few hours but not ready for it yet) but i rather decided to go and use modbus-master program after 4 failed attempts because of cmake is old version and wheezy not supporting qt5 to compile these modbus programs. I build an arduino uno modbus slave for debug.This is overkill but it was good school fees for future projects in linuxcnc.



So i Created a feedback loop using the arduino ide serial monitor and changed the SERIAL_PORT=/dev/ttyUSB0 to arduino SERIAL_PORT=/dev/ttyUSB1



When i put the spindle in ccw the pin change 1010 and 0000 and 1010 <-- (we get back to this now) So now i know it is working, writing the data to Modbus. i changed settings to VFD and nothing happens i remember that the speed needs to be changed as well for the VFD to move forward . I wrote this in my custom.hal file

loadusr -W mb2hal config=NF9000.ini

# Bin 1010 = Des 10 = 10 Inch Forward Running
setp mb2hal.Control.00 0
setp mb2hal.Control.01 1
setp mb2hal.Control.02 1
setp mb2hal.Control.03 1

# Bin 0111 1101 0000 = Des 2000 = 20.00hz
setp mb2hal.SetSpeed.00 0
setp mb2hal.SetSpeed.01 0
setp mb2hal.SetSpeed.02 0
setp mb2hal.SetSpeed.03 0

setp mb2hal.SetSpeed.04 1
setp mb2hal.SetSpeed.05 0
setp mb2hal.SetSpeed.06 1
setp mb2hal.SetSpeed.07 1

setp mb2hal.SetSpeed.08 1
setp mb2hal.SetSpeed.09 1
setp mb2hal.SetSpeed.10 1
setp mb2hal.SetSpeed.11 0

So go in LinuxCNC and boom VFD goes on to 20.00hz then off and on and ....



If you look at the image of the serial monitor you can see the bits look corrupted i thought this was normal because modbus-poll in Win 10 did the same thing and it works great with the VFD.

Any suggestions will be appreciated i also double checked my settings baud , parity etc.

Another question is how can i set the 4 bits of mb2hal.Control in custom.hal file for example like :

net spindle-ccw motion.spindle-reverse =>
Function () {
setp mb2hal.Control.00 0
setp mb2hal.Control.01 1
setp mb2hal.Control.02 1
setp mb2hal.Control.03 1
}

is there like type function cmd ?

And how would you write 16bit mb2hal.SetSpeed pin to ? Example :

net spindle-at-speed => mb2hal.SetSpeed
Attachments:

Please Log in or Create an account to join the conversation.

More
11 May 2018 14:22 #110578 by Donno
So after a few weeks i wrote a Driver for VFD NF-9000 in Python

First Step to install MODBUS in the terminal

wget bootstrap.pypa.io/get-pip.py
python get-pip.py
pip install MinimalModbus

open home directory and create file NF9000
#!/usr/bin/env python

import sys
import linuxcnc
import os
import time
import hal
import minimalmodbus 

l = linuxcnc.stat()

c = hal.component("NF")
c.newpin("setSpeed",hal.HAL_BIT,hal.HAL_IN)
c.ready()

instrument = minimalmodbus.Instrument("/dev/ttyUSB0", 1,"rtu")
instrument.serial.baudrate= 19200
instrument.serial.bytesize = 8
instrument.serial.parity = 'N'
instrument.serial.stopbits = 2
instrument.serial.timeout = 0.05 # seconds
instrument.write_register(14,0)
time.sleep(.5)
data = instrument.read_registers(0,16)

Speed = 0
Dir = 'Stop'
cSpeed = 0
cDir = 'Stop'

try:
	
	while 1:
		l.poll()
		cSpeed = l.spindle_speed
		if(l.spindle_speed == 0):
			cDir = 'Stop'
		if(l.spindle_speed < 0):
			cDir = 'Rev'
		if(l.spindle_speed > 0):
			cDir = 'Fwd'
		if (Dir != cDir):
			if (cDir == 'Stop'):
				instrument.write_register(14,0)
				time.sleep(.5)
				data = instrument.read_registers(0,16)
			if (cDir == 'Fwd'):
				instrument.write_register(14,3)
				time.sleep(.5)
				data = instrument.read_registers(0,16)
			if (cDir == 'Rev'):
				instrument.write_register(14,6)
				time.sleep(.5)
				data = instrument.read_registers(0,16)
			Dir = cDir
			c['setSpeed'] = 0
		if(Speed != cSpeed and cDir != 'Stop') :
			Value = abs(l.spindle_speed)/20
			instrument.write_register(15,round(Value,2),2)
			time.sleep(.5)
			Speed = cSpeed
			c['setSpeed'] = 0
		if(Speed != cSpeed and cDir == 'Stop') :
			Speed = cSpeed
			c['setSpeed'] = 0
		if (c['setSpeed'] == 0 and cDir != 'Stop'):
			data = instrument.read_registers(58,1)
			time.sleep(1)
			if(abs(l.spindle_speed) == data[0] or abs(l.spindle_speed) == data[0]-1 or abs(l.spindle_speed) == data[0]+1):
				c['setSpeed'] = 1
		if (c['setSpeed'] == 0 and cDir == 'Stop'):
			data = instrument.read_registers(58,1)
			time.sleep(1)
			if(data[0] == 0):
				c['setSpeed'] = 1
		time.sleep(0.01)

except KeyboardInterrupt:
	instrument.write_register(14,0)
	time.sleep(.5)
	data = instrument.read_registers(0,16)
    	raise SystemExit

Open Terminal in NF9000 file Directory
sudo cp NF9000 /usr/bin/
cd /usr/bin
sudo chmod u+x NF9000
sudo chown -r cnc NF9000

Right click on /usr/bin/NF9000 and make executuble

In step-conf Include custom PyVCP GUI panel -> Spindle speed display

Edit custom_postgui.hal

loadusr -Wn NF NF9000
net spindle-cmd-rpm-abs => pyvcp.spindle-speed
net spindle−at−speed => pyvcp.spindle-at-speed-led
net spindle−at−speed => NF.setSpeed



Some Notes on VFD Settings:
F014 STOP=0 FWD = 3 REV = 6
F058 RPM Feedback
F015 SET HZ
F093 22.01
F096 1
Rest of Parameters Factory Default

OS:
Using Debian Weezy and Python 2.7
The following user(s) said Thank You: diep

Please Log in or Create an account to join the conversation.

Moderators: cncbasher
Time to create page: 0.146 seconds
Powered by Kunena Forum