I've started writing a program and its a sequence of steps that it will go through. The sequence commands seemed a little complex to me so I opted to go with using counters/timers as well as 2 input bits that is set when a move operation is not being performed.
Basically I've got a motor controller that I pass a command to that will run a motor for a specific speed/number of steps. This is a two axis controller and each axis has a bit that is set whenever a move is not being performed. Whenever a move is commanded this input bit will be cleared and then reset when the move has complete.
Using this info, I created the Main ladder (LAD 2) as a set of rungs that given a certain bit set in a bit data file, it will set required parameters (given from an LCD) and do a JSR to the ladder which will perform the required step.
The JSR will go to LAD 5 in almost all the steps, so its a general sub routine that performs its logic based on the parameters set before the JSR. LAD 5 is the ladder I would like to make sure is valid logic.
The process of LAD 5 is as follows:
First we check to see that the Not Moving bits for Axis 1 AND Axis 2 are cleared and if the C5:0 accumulator value is equal to a preset value, If those are all true, we would do a COP to command the axis to go to home position, and then jump to the end of the ladder (this will eventually also change internal data so that in LAD 2 we would move to the next step rung).
Next, we check if axis1 AND axis 2 Not Moving bits are set, if they are, we would jmp to the end of the ladder, which skips the program until such time the move has completed.
Next, two toggle bits are checked if they are both clear, if they are, we initiate Motor2 move command (using a copy to the output), set the toggle1 bit, set the toggle2 bit, and then jump to the end of the ladder. This causes the axis 2 move to initiate and the axis 2 move bit to be cleared which causes the 0001 rung to skip the entire ladder until the move completes, at which point the axis 2 move bit will be set.
Once the axis 2 move bit is set, because of the toggle bits,rungs 0002 and 0003 are skipped over and we move to rung 0004. Here we again set an output via copy in order to command a move on axis 1. We then unlatch toggle2. If toggle3 is set, we start a counter. toggle 3 is then latched (toggle 3 exists to fix an off by 1 error ).
Now once we have finished rung 0004, the program begins from the beginning again and we skip the ladder until the move has completed. Once it has, because of the toggle bits we would go into rung 0003, this rung performs a similiar operation as rung 0002 except that it will run the axis 2 in an opposite direction. Once rung 0003 finishes, the program repeats and would eventually go back to rung 0004 and then 0002 and then 0004 and 0003 and so on until rung 0000 becomes true and we home the motor and set data such that the next subroutine runs in LAD 2.
The entire point of LAD 5 is to run motor 2 say 180deg CW, then increment 1 step motor 1, then run motor 2 180 deg CCW, then increment 1 step motor1, and repeat until motor 1 has been incremented a specific number of steps.
I hope i've done okay trying to explain this, I'm attaching my ladder program so hopefully if you follow along with the post it should make sense. I am just looking to confirm that my method will work.. it makes sense to me but I am a novice at this.
Thanks.
Basically I've got a motor controller that I pass a command to that will run a motor for a specific speed/number of steps. This is a two axis controller and each axis has a bit that is set whenever a move is not being performed. Whenever a move is commanded this input bit will be cleared and then reset when the move has complete.
Using this info, I created the Main ladder (LAD 2) as a set of rungs that given a certain bit set in a bit data file, it will set required parameters (given from an LCD) and do a JSR to the ladder which will perform the required step.
The JSR will go to LAD 5 in almost all the steps, so its a general sub routine that performs its logic based on the parameters set before the JSR. LAD 5 is the ladder I would like to make sure is valid logic.
The process of LAD 5 is as follows:
First we check to see that the Not Moving bits for Axis 1 AND Axis 2 are cleared and if the C5:0 accumulator value is equal to a preset value, If those are all true, we would do a COP to command the axis to go to home position, and then jump to the end of the ladder (this will eventually also change internal data so that in LAD 2 we would move to the next step rung).
Next, we check if axis1 AND axis 2 Not Moving bits are set, if they are, we would jmp to the end of the ladder, which skips the program until such time the move has completed.
Next, two toggle bits are checked if they are both clear, if they are, we initiate Motor2 move command (using a copy to the output), set the toggle1 bit, set the toggle2 bit, and then jump to the end of the ladder. This causes the axis 2 move to initiate and the axis 2 move bit to be cleared which causes the 0001 rung to skip the entire ladder until the move completes, at which point the axis 2 move bit will be set.
Once the axis 2 move bit is set, because of the toggle bits,rungs 0002 and 0003 are skipped over and we move to rung 0004. Here we again set an output via copy in order to command a move on axis 1. We then unlatch toggle2. If toggle3 is set, we start a counter. toggle 3 is then latched (toggle 3 exists to fix an off by 1 error ).
Now once we have finished rung 0004, the program begins from the beginning again and we skip the ladder until the move has completed. Once it has, because of the toggle bits we would go into rung 0003, this rung performs a similiar operation as rung 0002 except that it will run the axis 2 in an opposite direction. Once rung 0003 finishes, the program repeats and would eventually go back to rung 0004 and then 0002 and then 0004 and 0003 and so on until rung 0000 becomes true and we home the motor and set data such that the next subroutine runs in LAD 2.
The entire point of LAD 5 is to run motor 2 say 180deg CW, then increment 1 step motor 1, then run motor 2 180 deg CCW, then increment 1 step motor1, and repeat until motor 1 has been incremented a specific number of steps.
I hope i've done okay trying to explain this, I'm attaching my ladder program so hopefully if you follow along with the post it should make sense. I am just looking to confirm that my method will work.. it makes sense to me but I am a novice at this.
Thanks.