Before we can use the encoder we have to do a few things.
First, we have to wire the encoder to the CTRIO2. For this example we will be using
the CTRIO2 Channel 1A and 1B inputs and the common is 1M.
Now we have to configure the inputs on the CTRIO2 module. To do that we go back to System
Configuration, Module Configuration, and we double click on our module. Click on Configure
IO to setup all the individual IOs.
This one is setup from before where we had assigned channel 1’s output 0 and 1 to be
a Step and Direction for our stepper motor.
Now we want to add a single quad encoder to the inputs. Well, I just say I want a quad
counter. That takes up channels A and B because we had two wires and I can even count those
encoder pulses as one count per quadrature cycle, 2 counts or even 4 counts per quadrature
cycle. We’ll leave it at 1 right now to keep things simple. And that’s all there
is to configuring the CTRIO2 Module. We have our outputs and our inputs, so we hit OK,
OK and OK.
So, we have wired the CTRIO for the encoder, and configured the CTRIO IO. Now we just use
it!
To enable the encoder, you just go into the configuration block and tell it which CTRIO2
Channel to use. We wired ours to Channel 1, so we should probably use that one.
Here is the key point. It is rare that your Encoder PPR will match your stepper PPR. So
right here you need to put the ratio of the two: Divide the Motor PPR by the Encoder PPR
– just like it shows in the parenthesis here, and put that number here. In our example
we have a 20,000 PPR motor divided b a 360 PPR encoder and so our ratio is going to be
55.56. Because of that mis-match, the CTRIO can’t
always get exactly the right number of pulses it needs and it will try to bounce back and
forth between the count on either side of perfect. You can eliminate that jitter by
specifying a dead band here. We’re not going to fool with that in this demo, but just know
you have it available.
Also know that these don’t have to be constants. You could put registers here and change both
of these on the fly as the program is running. Again, we don’t need to mess with that right
now.
So all we did was check our encoder channel - which looks like I missed – Channel 1
– and setup our ratio of the motor PPR to the encoder PPR.
Now that the config block has told the CTRIO how to handle the encoder we just use it.
For this demo we’ll just use a Trapezoid Function, and nothing changes. We use the
same CTRIO module, we’re still going to do a relative move. And we are going to specify
a target position to be put in D0. So no changes required there at all.
This is important, now that we have enabled the encoder in our config block – all positions
you use with the CTAX commands need to be in encoder PPRs.
Using this Trapezoid Function, let’s move the carriage 10 shaft rotations. Remember,
in the previous video, that took 200,000 pulses. Now that we have encoders enabled, we only
need 3600 pulses.
Notice that down here I added some more logic for our convenience. If X7 is on, we are going
to put 3600 into D0. If X7 is off, we are going to put a -3600 in D0. That just gives
me a convenient way to flip back and forth.
I’m going to turn on X7, which will write a +3600 to D0. And now when we set X0, we
expect the carriage to move 10 shaft rotations. And sure enough it does. And since this was
a relative move I can do it again. Turn X7 off, which writes a -3600 to D0, now
when I engage X0, the carriage moves back. But again, it moves back 3600 pulses, not
200,000 because we are using encoders.
Note that while we used the Trapezoid function in this example, these comments apply to all
of the CTAX commands on the CTRIO2.
We’ll, that’s all there is to using encoders with the CTRIO2 and the Do-more processor.
Do-more designer software makes it easy and it just works the way you would expect it
to. Be sure to check out the other videos in this series for more on using motion. And
as always, please send us any comments you may have, we appreciate the feedback.
Spend Less. Do-more. From AutomationDirect.