Setting pin value based on other pins

More
1 year 5 months ago #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 to join the conversation.

More
1 year 5 months ago #329426 by juliankoenig87
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 to join the conversation.

More
1 year 5 months ago #329434 by rodw
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 to join the conversation.

More
1 year 4 months ago #329441 by juliankoenig87
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 to join the conversation.

More
1 year 4 months ago #329460 by kubes
Thanks! mux4 worked.

In case others need it, here is my solution:

Code:
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

 

Please Log in to join the conversation.

Time to create page: 0.079 seconds
Powered by Kunena Forum