# Programmable Limit Switch

**URL:** <https://forum.deltamotion.com/t/programmable-limit-switch/406>\
**Category:** RMCTools\
**Created:** [October 4, 2016, 6:59pm UTC](https://forum.deltamotion.com/t/programmable-limit-switch/406 "2016-10-04T18:59:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndzied1](https://forum.deltamotion.com/letter_avatar_proxy/v4/letter/n/77aa72/32.png) [@ndzied1](https://forum.deltamotion.com/u/ndzied1)\
**Post date:** [October 4, 2016, 6:59pm UTC](https://forum.deltamotion.com/t/programmable-limit-switch/406/1 "2016-10-04T18:59:56Z")

</div>

I have the need to make a couple programmable limit switches based on position in an RMC75.

I came up with putting the following in a program that will run continuously on a second task. Is this the best way or is there something better?

`AT_HIGH_PT := _Axis[0].StatusBits.InPos AND (ABS(_Axis[0].ActPos-UpperPos) <= _Axis[0].InPosTolerance);
AT_LOW_PT := _Axis[0].StatusBits.InPos AND (ABS(_Axis[0].ActPos-LowerPos) <= _Axis[0].InPosTolerance);`

---

<div class="post-metadata">

**Author:** ![Jacob\_Paso](https://forum.deltamotion.com/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@Jacob\_Paso](https://forum.deltamotion.com/u/Jacob_Paso)\
**Post date:** [October 4, 2016, 7:13pm UTC](https://forum.deltamotion.com/t/programmable-limit-switch/406/2 "2016-10-04T19:13:50Z")

</div>

In general, that is a very good way to do it. In fact, I just suggested that general method to a customer yesterday. I am curious about the expressions comparing UpperPos and LowerPos. If they are the same as the command position, then all you should need to look at it the InPos status bit.

---

<div class="post-metadata">

**Author:** ![ndzied1](https://forum.deltamotion.com/letter_avatar_proxy/v4/letter/n/77aa72/32.png) [@ndzied1](https://forum.deltamotion.com/u/ndzied1)\
**Post date:** [October 4, 2016, 7:31pm UTC](https://forum.deltamotion.com/t/programmable-limit-switch/406/3 "2016-10-04T19:31:25Z")

</div>

So I think what you are saying is that I could just do this:

`AT_HIGH_PT := _Axis[0].StatusBits.InPos AND (_Axis[0].CmdPos = UpperPos);
AT_LOW_PT := _Axis[0].StatusBits.InPos AND (_Axis[0].CmdPos = LowerPos);
`  
I can’t just use StatusBits.InPos by itself as that doesn’t tell me which specific position that I’m at, just that I’m at any commanded position.

---

<div class="post-metadata">

**Author:** ![Jacob\_Paso](https://forum.deltamotion.com/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@Jacob\_Paso](https://forum.deltamotion.com/u/Jacob_Paso)\
**Post date:** [October 4, 2016, 8:00pm UTC](https://forum.deltamotion.com/t/programmable-limit-switch/406/4 "2016-10-04T20:00:43Z")

</div>

Yep, if UpperPos and LowerPos are used as the requested position in a motion command, then those expressions should work just fine. Otherwise, you should use a range like you did initially, since floating point positions are rarely identical unless purposely made identical.

---

<div class="post-metadata">

**Author:** ![Peter\_Nachtwey](https://forum.deltamotion.com/letter_avatar_proxy/v4/letter/p/f17d59/32.png) [@Peter\_Nachtwey](https://forum.deltamotion.com/u/Peter_Nachtwey)\
**Post date:** [October 5, 2016, 8:50pm UTC](https://forum.deltamotion.com/t/programmable-limit-switch/406/5 "2016-10-05T20:50:20Z")

</div>

Use Norm’s first method.  
The second method is overkill  
BTW, the in position bit will clear by itself if the error is greater than the in position tolerance.
