# Home + Limit from just 1 input pin: HAL config explained

12 Jul 2021 23:40 - 13 Jul 2021 11:58 #214455
Hey there, first post, still learning.

I have been configuring LinuxCNC 2.8 trying to understand what is happening so it wont bite me later...

When I set HOME+LIMITS on input pin 10 of parport, StepConf has put code like this in the HAL File:
```loadrt lut5
net all-limit-home  <= parport.0.pin-10-in
setp lut5.0.function 0x10000
net all-limit-home => lut5.0.in-4
net all-limit <= lut5.0.out
net homing-x  <= joint.0.homing => lut5.0.in-0
net homing-y1 <= joint.1.homing => lut5.0.in-1
net homing-y2 <= joint.2.homing => lut5.0.in-2
net homing-z  <= joint.3.homing => lut5.0.in-3
net all-limit-home => joint.0.home-sw-in
net all-limit => joint.0.neg-lim-sw-in
net all-limit => joint.0.pos-lim-sw-in
net all-limit-home => joint.1.home-sw-in
net all-limit => joint.1.neg-lim-sw-in
net all-limit => joint.1.pos-lim-sw-in
net all-limit-home => joint.2.home-sw-in
net all-limit => joint.2.neg-lim-sw-in
net all-limit => joint.2.pos-lim-sw-in
net all-limit-home => joint.3.home-sw-in
net all-limit => joint.3.neg-lim-sw-in
net all-limit => joint.3.pos-lim-sw-in```

I have edit to reflect my gantry y1 and y2 joints.
I now kind of understand what is happening in LUT5.

So far, I understand that:

1. LUT5 have 5 inputs and one output (IN4, IN3, IN2, IN1, IN0 and OUT) ;
2. IN4 receives the signal from the serial circuit of physical switches and is TRUE when the circuit is closed;
3. Homing operation doesn't depends upon LUT5 output, but Limit detection does;
4. IN3, IN2, IN1, IN0 are TRUE when joints 3,2,1,0 are homing, respectively;
5. LUT5 OUT is TRUE only when IN4 is FALSE and IN3, IN2, IN1, IN0 are TRUE
6. Only when LUT5 OUT is TRUE the joints limit switches input pins are TRUE (meaning a switch have been tripped)

My conclusion is that joint limit switches inputs are never TRUE because IN3, IN2, IN1, IN0 are never TRUE at the same time;

Where is my logic failing ?

Can someone explain the step-by-step events and states ocurring when a physical switch is tripped ?

Thanks guys,
Last edit: 13 Jul 2021 11:58 by fernandosf. Reason: editor messed up my post

13 Jul 2021 11:51 #214554
Tried to edit the post and the forum editor is fighting me back, the harder I try, the worst it gets.

13 Jul 2021 11:56 #214558
Click on the "source" in the upper left of the editor.
It will still mess up, but less.

13 Jul 2021 12:43 - 13 Jul 2021 12:53 #214569 by BigJohnT
Don't know if I can explain lut5 but here are some links that might help.
wiki.linuxcnc.org/cgi-bin/wiki.pl?Lut5
linuxcnc.org/docs/2.5/html/man/man9/lut5.9.html
linuxcnc.org/docs/2.8/html/hal/rtcomps.html#_lut5

trying to test it myself but running out of time this morning.

Hmm looks like setting the function to 0x1000000 is the output is never on.

JT
Last edit: 13 Jul 2021 12:53 by BigJohnT.

13 Jul 2021 12:51 - 13 Jul 2021 12:51 #214571
Hey John,

I understand LUT5.
if I have code like this:
```loadrt lut5
setp lut5.0.function 0x10000```
I understand that LUT5 will only be TRUE when IN4=FALSE and IN3, IN2, IN1, IN0 are TRUE

Problem is what this logic represents in the wiring of HAL from the first post, it does not make sense to me.
Last edit: 13 Jul 2021 12:51 by fernandosf.

13 Jul 2021 12:55 #214573 by BigJohnT
I just tested that with the axis sim and out is never on... gotta run to work now.

JT

13 Jul 2021 13:05 - 13 Jul 2021 14:11 #214576 by BigJohnT

I understand that LUT5 will only be TRUE when IN4=FALSE and IN3, IN2, IN1, IN0 are TRUE

setp lut5.0.function 0x8000

This is the function for the above.

JT
##### Attachments:
Last edit: 13 Jul 2021 14:11 by BigJohnT. Reason: editor ate my quote tags
The following user(s) said Thank You: tommylight

13 Jul 2021 14:40 - 13 Jul 2021 14:41 #214588
hum... maybe I've got LUT5 logic wrong.
I was expecting function 0x10000 to be:
`IN4=FALSE IN3=TRUE IN2=TRUE IN1=TRUE IN0=TRUE`

but your debug shows LUT5 function to be 0x8000 for that situation.
in fact the difference between both in binary is this:
```0x8000:
1000 0000 0000 0000
0x10000:
1 0000 0000 0000 0000```

Could you explain how did you wired sim.axis to simulate this LUT5 output ?
I'm still learning HAL and could not reproduce your screen
Last edit: 13 Jul 2021 14:41 by fernandosf. Reason: editor bugs

13 Jul 2021 14:42 #214589 by BigJohnT
Actually setp lut5.0.function 0x10000 is:
```lut5.0.in-0 Off
lut5.0.in-1 Off
lut5.0.in-2 Off
lut5.0.in-3 Off
lut5.0.in-4 On
lut5.0.out On```

JT
##### Attachments:

13 Jul 2021 14:48 #214591
I have done this comparison of HAL wiring in sim.axis homing and lut5 homing+limits:

but don't know how to translate to simulated env.