Setting pin value based on other pins

More
31 May 2025 05:47 #329425 by kubes
I am using mb2hal (modbus) and it exposes a pin `mb2hal.00.00.int` that is an input, the values can be 1, 2, or 5. I need to set the values based on other bit pin:

if spindle.0.forward = true then mb2hal.00.00.in = 1
if spindle.0.reverse = true then mb2hal.00.00.in = 2
if spindle.0.on = false then mb2hal.00.00.in = 5

How do I create this logic in the hal?

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

More
31 May 2025 07:00 #329426 by juliankoenig87
Replied by juliankoenig87 on topic Setting pin value based on other pins
One easy way is to use a mux8:
linuxcnc.org/docs/2.5/html/man/man9/mux8.9.html

This way you can net your three spindle signals to the three selections of the mux and you can define your modbus values to the corresponding inputs of the mux.

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

More
31 May 2025 09:21 #329434 by rodw
Replied by rodw on topic Setting pin value based on other pins
Look at the example in the docs for a MPG for axis selection and scaling. I think there is also a MUX4

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

More
31 May 2025 13:01 #329441 by juliankoenig87
Replied by juliankoenig87 on topic Setting pin value based on other pins
Yes there is a mux4. But then you will one have 2 selction bits and he needs three. Assuming there is a fourth state where nothing is active otherwise mux4 is doable I would say.

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

More
31 May 2025 18:34 - 31 May 2025 18:36 #329460 by kubes
Replied by kubes on topic Setting pin value based on other pins
Thanks! mux4 worked.

In case others need it, here is my solution:

loadusr -Wn modbus mb2hal config=mb2hal-gt.ini
loadrt mux4 count=1

addf mux4.0 servo-thread

# esnure all is stopped! (int and float are add together and the result is sent to modbus)
setp modbus.vfd.command.int 0
setp modbus.vfd.command.float 5

# set the logic of that command to send the vdf
# 5 = stop, 1 = forward, 2 = reverse
setp mux4.0.in0 5
setp mux4.0.in1 1
setp mux4.0.in2 2
setp mux4.0.in3 5

net vfd-cmd1 mux4.0.sel0 <= spindle.0.forward
net vfd-cmd2 mux4.0.sel1 <= spindle.0.reverse
net vfd-command modbus.vfd.command.float <= mux4.0.out

net spindle-speed-fb <= modbus.vfd.status.rotation_speed.float

 
Last edit: 31 May 2025 18:36 by kubes.

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

Time to create page: 0.175 seconds
Powered by Kunena Forum