It's working now, except when spindle is reversed the pyVCP bar shows the rpm wrong, it's 60 000 instead of 5000. Guess it's because the rpm scale from vfd is +/-. Is the some way to convert it to get the correct rpm reading?
I didn't try Classicladder because not familiar with it.
I leave the code here, maybe it's useful for someone else. And if you use Vacon remember to subtract 1 from the address number.
Code:
[MB2HAL_INIT]
INIT_DEBUG=0
SLOWDOWN=0.0
TOTAL_TRANSACTIONS=3
[TRANSACTION_00]
LINK_TYPE=serial
SERIAL_PORT=/dev/ttyUSB0
SERIAL_BAUD=9600
SERIAL_BITS=8
SERIAL_PARITY=none
SERIAL_STOP=1
SERIAL_DELAY_MS=150
MB_SLAVE_ID=1
FIRST_ELEMENT=2104
NELEMENTS=1
MB_TX_CODE=fnct_03_read_holding_registers
MB_RESPONSE_TIMEOUT_MS=500
MB_BYTE_TIMEOUT_MS=500
HAL_TX_NAME=rpm
MAX_UPDATE_RATE=0.0
[TRANSACTION_01]
FIRST_ELEMENT=2000
NELEMENTS=1
MB_TX_CODE=fnct_16_write_multiple_registers
HAL_TX_NAME=control
MAX_UPDATE_RATE=0.0
[TRANSACTION_02]
FIRST_ELEMENT=2002
NELEMENTS=1
MB_TX_CODE=fnct_16_write_multiple_registers
HAL_TX_NAME=speed
MAX_UPDATE_RATE=0.0
Code:
# Include your customized HAL commands here
# This file will not be overwritten when you run stepconf again
loadusr -W mb2hal config=mb2hal.ini
loadrt mult2
loadrt mux4
loadrt and2 count=2
loadrt near
addf mult2.0 servo-thread
addf mux4.0 servo-thread
addf and2.0 servo-thread
addf and2.1 servo-thread
addf near.0 servo-thread
setp mult2.0.in0 31.25 #320 x 31.25 = 10 000
net spindle-cmd-rps-abs => mult2.0.in1
net speed.vfd mb2hal.speed.00 <= mult2.0.out
net spindle-cmd-rps-abs <= motion.spindle-speed-out-rps-abs
net S-on and2.0.in0 <= motion.spindle-on
net S-fwd and2.0.in1 <= motion.spindle-forward
net S-on and2.1.in0
net S-rev and2.1.in1 <= motion.spindle-reverse
net S-on-fwd mux4.0.sel0 <= and2.0.out
net S-on-rev mux4.0.sel1 <= and2.1.out
setp mux4.0.in0 4 #100stop
setp mux4.0.in1 5 #101forward
setp mux4.0.in2 7 #111reverse
setp mux4.0.in3 4 #100reset
net control mb2hal.control.00 <= mux4.0.out
net rpm-abs motion.spindle-speed-out-abs => near.0.in1 #spindle rpm command
net rpm.vfd => near.0.in2 #spindle rpm from vfd
net spindle-at-speed motion.spindle-at-speed <= near.0.out
setp near.0.scale 1.02
Code:
# Include your customized HAL commands here
# The commands in this file are run after the AXIS GUI (including PyVCP panel) starts
net rpm.vfd mb2hal.rpm.00.float => pyvcp.spindle-speed
net spindle-at-speed => pyvcp.spindle-at-speed
Code:
<?xml version="1.0" encoding="UTF-8"?>
<pyvcp>
<labelframe text="VFD">
<font>("Helvetica",10)</font>
<table>
<tablerow/>
<tablesticky sticky="w"/>
<label>
<text>"Spindle at speed:"</text>
</label>
<tablesticky sticky="e"/>
<led>
<halpin>"spindle-at-speed"</halpin>
<size>"10"</size>
<on_color>"green"</on_color>
<off_color>"red"</off_color>
</led>
<tablerow/>
<label>
<text>" "</text>
</label>
</table>
<table>
<tablesticky sticky="nsew"/>
<tablerow/>
<tablesticky sticky="nsew"/>
<label>
<text>"Spindle Speed (RPM)"</text>
<font>("Helvetica",10)</font>
</label>
<tablerow/>
<tablesticky sticky="nsew"/>
<label>
<text>" "</text>
<font>("Helvetica",2)</font>
</label>
<tablerow/>
<tablesticky sticky="nsew"/>
<bar>
<halpin>"spindle-speed"</halpin>
<min_>5000</min_>
<max_>19200</max_>
</bar>
</table>
</labelframe>
</pyvcp>