text: <s>[INST] Ultra 5000 logic for a leading edge sensor for registration mark Ok, so I am one of the sick people that use the Ultra 5000, it fit the budget and the project design. I was wondering if anybody has any better logic than this for a registration sensor. The sensor starts off blocked, clears between parts, and then I want to start a function when the next part comes into position (i'm using it as a registration offset for a labeler). This is the code I'm using right now: while ((!InputGetState(2)) && (TimerDone(1)==0)) { pe4=0; } while((InputGetState(2)) && (TimerDone(1)==0)) { pe4=1; } while((!InputGetState(2)) && pe4==1 && (TimerDone(1)==0)) Just wondering if anybody has any better way to do it that isn't as verbose. Thanks [/INST] Can I assume from this logic that the final step to break out of these while loops is the Timer1 going done? Why aren't you utilizing the LatchOnIndex command? You apparently don't need the motor feedback from the latch but it would provide you with a function that operated automatically. In this example you check that the count has increased on the latch then store it in memory in case you want to run an operation off that memory with TriggerShot. if(LatchGetCount(1)!=CountBuffer && TriggerShot==0) { TriggerShot=1; CountBuffer=LatchGetCount(3); } if(TriggerShot==1 && TimerDone(1)==0) function_call(); I don't know your exact use case, but this is just another way to tackle it. I've got this running on many machines right now and we don't have any issues with the timing. I'm just concerned with all of your while statements that the code will be trapped in there and unable to run any error handling routines elsewhere in the code. \\n </s>