Colin Carpenter

FOR NEXT LOOPS

3 posts in this topic

For the first time in my career, I find that I'm looking to write "For Next" loops using index registers to solve a problem, but am struggling to make sense of the way these things work.

As shown on the attached graphic, I have an old FX2N hooked up and the entire ( 4 rung) programme is shown as two screen shots.

Rung 1 - Meaningless code just to have something there

Rung 2 - Labelled START_1 and purely adds 1 to V7 (an index register) as long as  V7 is less than 100

Rung 3 - If V7 is less than 100, then it should jump to Rung 2 (START_1)

Rung 4 - Purely there so that I can see if Rung 4 is being run as part of the programme. (M2701 should be on when it is)

I start the routine with V7 set to a large negative number (-32,000) to give me time to monitor the programme.

The top of the graphic shows that scenario and I would have thought that the programme would go through Rung 1 and Rung 2 and then when it gets to Rung 3 it would loop back to Rung 2 and carry on looping  until V7 gets to 100. 

If that is correct, then Rung 4 would not be run during that time and M2701 would be OFF - and yet it is ON, showing that Rung 4 is clearly operational.

I'm obviously missing something and wonder if someone could advise what that is please.

Thanks

FORNEXT3.png

1 person likes this

Share this post


Link to post
Share on other sites

I read up on the CJ command a bit more and rearranged the rungs as shown in this graphic and also changed the CJP command for a CJ command.

According to the manual, it should skip Rung 3 when V7 is less than 100 (which it is in the top graphic as confirmed by M2702 being ON), and yet Rung 3 still seems to be operational as M2701 is still ON.

Really confused now .....

 

fornext2.png

Share this post


Link to post
Share on other sites

Ah, sorted it.

Put a line of code in at the start to "first run pulse write" the value of -32000 into V7 to ensure that it didn't get to 100 before I could start monitoring.

Toggled off M2701 by hand and sure enough, it didn't come back on until V7 got to be 100, indicating that Rung 3 was now operational as expected.

Phew ....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now