Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: tantan on January 13, 2016, 01:15:19 PM

Title: Edge detection on input
Post by: tantan on January 13, 2016, 01:15:19 PM
i need to detect a falling edge of an input to control my turret

i think the code is right but it hangs mach3?

wanted_position = 6
counter = 0
marker = 0
'input 1 = the couter of the turretpostion

message "c = " &counter
sleep(100)

activatesignal(output3) 'start run turret
While ismoving()
Wend


While (counter <> wanted_position)

   If Not isactive(input1) And marker = 0 Then
      counter = counter + 1
      marker = 1
   End If
   

   If isactive(intput1) And marker = 1 Then
      marker = 0
   End If

   message "c = " &counter

Wend

deactivatesignal(output3) 'stop turret

tnx for your reply!
Title: Re: Edge detection on input
Post by: BR549 on January 13, 2016, 02:18:01 PM
OK what do you mean by it hangs Mach3 ?? Have you single stepped through the code to see what line causes it to hang ?
Title: Re: Edge detection on input
Post by: tantan on January 13, 2016, 02:45:21 PM
hi,

the counter does not count up futher than 1. then the while loop hangs mach3 because the counter never reaches 6.

i did use the right input, i did checked that

tnx tantan
Title: Re: Edge detection on input
Post by: BR549 on January 13, 2016, 04:34:30 PM
If you single step down through the code you will see the problem as to WHY you are stuck in an endless loop with no way out(;-)

The first loop sets  specific conditions  after that the escape conditions do not exist as I see it from here so around and around you go.

The counter can NEVER count up past teh first loop because teh count incrementing is in the wrong position inside teh loop. As teh condition is not met it hops over teh counting code .

(;-) TP
Title: Re: Edge detection on input
Post by: TPS on January 13, 2016, 05:51:45 PM
can you see Input1 changing signal in diagnostic Screen ?

While is moving
Wend

is useless because no 'real' axis is moving.

TPS
Title: Re: Edge detection on input
Post by: BR549 on January 13, 2016, 06:23:11 PM
Ismoving() does not only pertain to motion it is about any time that mach3 is doing something internally such as uipdating a dro writing something to mem ,etc

(;-) TP
Title: Re: Edge detection on input
Post by: tantan on January 14, 2016, 11:33:37 AM
hi

yes the input changes in the diagnostic screen. i hope the frequency of the inputsignal is not to high for this basic code. i will test it tomorrow with a manual switch,

as far as i can see the code should detect an edge...

tnx for your replies.

Title: Re: Edge detection on input
Post by: tantan on January 16, 2016, 03:01:29 PM
hi,
it works,
mach does not read inputs within a while loop.

https://youtu.be/39QgfGTrPZo (https://youtu.be/39QgfGTrPZo)

tnx for your replies
Title: Re: Edge detection on input
Post by: BR549 on January 16, 2016, 04:23:15 PM
I do not think that is true "" mach does not read inputs within a while loop. ""  Can you give me an example of where you  that is true ???

(;-) TP


Title: Re: Edge detection on input
Post by: tantan on January 17, 2016, 10:40:00 AM
see code i posted in my first post. that did not see input1 changing.
i call a sub in the while loop that reads the input. that works.

tnx
Title: Re: Edge detection on input
Post by: stirling on January 17, 2016, 11:01:53 AM
Look again at the code in your first post. The reason it doesn't read the input (in the second if) is simply down to a typo.
Title: Re: Edge detection on input
Post by: BR549 on January 17, 2016, 02:53:45 PM
I have used while and do loops for years to wait on an input signal. I have never seen one programmed correctly that did not work in Mach3.

(;-) TP