News:

  • May 02, 2024, 07:27:30 AM

Login with username, password and session length

Author Topic: How do you program a stepper with an encoder for feedback?  (Read 15252 times)

mikep

  • Jr. Member
  • **
  • Posts: 17
How do you program a stepper with an encoder for feedback?
« on: October 24, 2008, 10:43:57 AM »
I have a DL06 PLC,HO-CTRIO Counter Module,STP-DRV-4035 Stepper Driver,TRDSH 100BD Encoder, and a Stepper I already had.
Done all of the wiring and all works well with the CTRIO Workbench Programs.
I have been able to use some of examples to move the stepper motor and read the counts of the Encoder.
My problem is trying to put both the stepper moving part of the program with the Encoder reading part of the program.
Can anybody help me?
 
« Last Edit: October 24, 2008, 10:50:28 AM by mikep »

Greg

  • HostTech
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 684
  • Hmmm...
    • Host Engineering, Inc.
Re: How do you program a stepper with an encoder for feedback?
« Reply #1 on: October 27, 2008, 03:55:36 PM »
If you can get them to work in the CTRIO Workench (using Monitor I/O function), then this is basically teaching you exactly what you need to do in ladder logic to get it to work. Every button you press in Monitor I/O to get things to work, is a bit or parameter that you would manipulate in ladders to get it to work from there.

Does that help?
There are two types of people in the world; those that can extrapolate from incomplete data sets.

mikep

  • Jr. Member
  • **
  • Posts: 17
Re: How do you program a stepper with an encoder for feedback?
« Reply #2 on: October 30, 2008, 07:32:25 AM »
I am a Newbie and have very little experience in programming pls's.
In refeference to your comments on MOTION CONTROL.
This is just what I want to do, but I am having trouble understanding the summary of steps.
CAN YOU PLEASE GIVE ME A LETTLE MORE HELP IN UNDERSTANDING THE STEPS?


  "If I understand your application, then all you need to do is configure the CTRIO output as you have stated (Pulse/Direction) and     create a Dynamic Positioning Pulse Profile. Dynamic Positioning will allow you to simply put the absolute position (not the relative one) in a V-memory location, and set the Goto Position bit; the Pulse Output of the CTRIO will then move the stepper to the proper position.

You can "know" the absolute position in two ways:
     - Hook an encoder from the stepper to the CTRIO input and monitor it.
     - Use a System Function of the CTRIO and read the CTRIO Output count

I would also advise you to use the CTRIO IBoxes (not covered in the manual).

Summary of steps:

1. Configure CTRIO Output (Pulse/Direction).
2. Configure CTRIO Input (if you are going to use a quadrature encoder to read the position).
3. Configure Pulse Profile (Dynamic Position).
4. Configure CTRIO I/O mapping.
5. Download configuration to CTRIO.
6. In ladders, put IB-1000 (CTRIO) at top; use Help file to understand parameters.
7. Use IB-1001 (CTRLDPR) to load the Dynamic Positioning Pulse Profile.
8. Set the Enable Output bit.
9. Write the absolute position desired (signed decimal) into Parameter 3 (double word).
10. Set the Goto Position bit.

Lather. Rinse. Repeat Steps 9 & 10 as many times as you need. There is no need to relaod the table each time... that is why it is called "dynamic" positioning."

Greg

  • HostTech
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 684
  • Hmmm...
    • Host Engineering, Inc.
Re: How do you program a stepper with an encoder for feedback?
« Reply #3 on: October 31, 2008, 04:48:10 PM »
OK, I'll try to explain each one, but this is going to be a long response:

1. Configure CTRIO Output (Pulse/Direction): This means to pull up CTRIO Workbench and press the <Config IO...> button. On the right at the Outputs tab, select Pulse (Step/Dir) for which ever output you have wired to the drive. Press the <OK> button to take you back to the main screen.

2. Configure CTRIO Input (if you are going to use a quadrature encoder to read the position): The encoder you chose (TRD-SH100-BD) is indeed a quadrature encoder and thus can count up and down thus indicating clockwise and counterclockwise rotation. Thus, to configure, press the <Config IO...> button. On the left in the Channel tab pick Quad Counter. Press the <OK> button to take you back to the main screen.

3. Configure Pulse Profile (Dynamic Position): Press the <Pulse Profiles> button. Press the <Add...> button. Type in a Name for your table (i.e. DynaPos, or Fred...). In the Profile Type window choose Dynamic Positioning. After this is chosen you can then input the parameters for how this Dynamic Positioning will act; Minimum Frequency (the slowest you want the motor to travel), Maximum Frequency (the fastest you want the motor to travel), Acceleration Rate (how fast you want to the motor to reach its Minimum and Maximum Frequencies). Notice at the bottom that this Pulse Profile has a File Number (if it is the only one you have, it will be 1). Press the <OK> button. You should now see the Pulse Profile listed. Press <Exit> button.

4. Configure CTRIO I/O mapping: Press the <I/O Map...> button. This is where you decide what V-memory in your PLC will be used to interface to the CTRIO. At the left top click on PLC - Mapped Addresses (4 ranges). Put a checkmark in Enable Write to PLC and Enable Read from PLC. In Starting V address for word inputs, you might put V2000. Notice this uses a range (V2000-2017). In Starting V address for bit inputs, you might put V40600 (this is the first C-bit memory location). Notice it takes bits V40600.0-40605.15 (or C0-C137). In Starting V address for word outputs, you might put V2030. Notice this uses a range (V2030-2061). In Starting V address for bit outputs, you might put V40610 (this is the start of C200). Notice it takes bits V40610.0-40615.15 (or C200-337) At this point you might want to make a Report of this mapping for easy reference when writing your ladder logic. Press <Report...> button. From here you can save the configuration to a file, or you can print it directly. After you are finished press <Close> button. Another thing you can do here is to make a .CSV (comma separated variable) file that will create Nicknames for these V-memory locations. After this file is made you can then import it into DirectSOFT and the Nicknames will be used there. If you want to do that press the <Export...> button. If not, press the <OK> button.

5. Download configuration to CTRIO: In order to download the CTRIO must be in PROGRAM mode. In CTRIO Workbench notice, on the right, the box Utility Functions. The name of the first button will tell you if you need to put the CTRIO in PROGRAM mode. If the button says <Goto PROGRAM!>, then press it. Notice it will change to <Goto RUN!>. The CTRIO's mode above changes to yellow Program. Now press the <Write Module> button. It only takes a few seconds to load (the cursor changes). If it fails there will be a message; if it is successful there will be no message at all.

6. In ladders, put IB-1000 (CTRIO) at top; use Help file to understand parameters: On the first rung of ladders, Edit it and put a CTRIO IBox there. Its parameters:
  • The CTRIO # is just an arbitrary number you will use to refer to the particular CTRIO you have installed and are going to use. You need a CTRIO IBox for each CTRIO in your PLC. We'll designate this one as 1 (enter K1; "K" just means constant like "V" means variable).
  • Slot is the slot in which the CTRIO is installed. In a DL06, the first open slot is 1.
  • Workspace is a unique V-memory location this IBox needs to use internally. The default is V400... just don't use this anywhere else.
  • The CTRIO Location, in this case seems like it should be Local Base. But I know something you don't here, so trust me, and pick EBC (Connected via ERM). I do this so that I can get 4-range CTRIO memory addressing. If you just pick Local Base, then you will only get 2-range addressing. We need 4 because that's what we picked in CTRIO Workbench in Step 4 above.
  • Word Input wants to know where you mapped your CTRIO word inputs. If you used what I said in Step 4 above, then enter V2000.
  • Bit Input wants to know where you mapped your CTRIO bit inputs. Enter C0.
  • Word Output: V2030.
  • Bit Output: C200

Now, click the checkmark button.

7. Use IB-1001 (CTRLDPR) to load the Dynamic Positioning Pulse Profile: In the 2nd rung of ladders, put a CTRLDPR IBox. Since the CTRIO has the possiblilty of many different Pulse Profiles being configured, you will need to tell the CTRIO which one to use. You are going to use the Dynamic Position one we configured. This, if you will remember, has a File # of 1. The IBox CTRLDPR means "CTR" = CTRIO, "LD" = Load, "PR" = Profile. Its parameters are:

  • CTRIO # is which CTRIO you are going to use. Since you could have more than one CTRIO in your DL06, and thus more than one CTRIO IBox, this tells the CTRLDPR IBox which one you are going to use. Use K1 if that is what you defined yours as above.
  • Output # is which CTRIO output you are going to use. In your CTRIO Workbench configuration, this is which physical output was configured for Pulse (Step/Dir). I picked 0, thus K0 here.
  • File # is the file number inside the CTRIO that we configured. It was 1 in mine, thus K1. This could be a variable, but not in this case.
  • Workspace needs to be unique, so don't reuse V400. I picked V401.
  • Success is what bit is to be SET if the CTRLDPR was successful. I picked C400.
  • Error is what bit is to be SET if the CTRLDPR failed. I picked C401.

Now, click the checkmark button. At the beginning of this rung you will need a contact to tell it when you want to execute. I chose a normally open C402.

In the 3rd rung just put an END instruction.


Now at this point I don't want to write your program for you, but I will tell you what you must do to get this to work using a Data View in DirectSOFT. Thus create a Data View (Debug --> Data View --> New). Press the Edits button in Data View (yellow E button).

I must also insert an extra step I left out, I'll call it 7B:

7B. Execute the CTRLDPR: Make sure the ladder program is written to your PLC, and that it is in the RUN mode. In Data View enter a C402. Double-click on the <ON> button in the Edits column to turn this bit ON. After doing this, enter a C400 and C401 in Data View and make sure C400 is ON (indicating Success of the CTRLDPR IBox). If it was successful, turn C402 OFF.

8. Set the Enable Output bit: According to your CTRIO I/O mapping, the Enable Output bit for CTRIO Output 0 is C240. So in Data View enter a C240. Double-click on the <ON> button in the Edits column to turn this bit ON. The CTRIO output is ready to work.

9. Write the absolute position desired (signed decimal) into Parameter 3 (double word): According to your CTRIO I/O mapping, Parameter 3 is V2030-2031. Enter V2030 in Data View. Make sure it is indicating DWORD and Signed Decimal at the top of Data view. In the Edits column, enter a position you would like the CTRIO output to go to... like 10000. Press the write button at top (single arrow pointing toward PLC symbol). This should write a 10000 to V2030.

10. Set the Goto Position bit: According to your CTRIO I/O mapping, this bit is C241. Enter a C241 in Data View, and turn it ON. The motor should move to this position and stop.

The motor is now at absolute position 10000 and it "knows" this. Now you can repeat Steps 9 & 10 above as often as you like telling it to go to other absolute positions. If you now, for example, picked something less than 10000 (say, 5000), then the motor would move backwards to that position.

Whew! :)

How's that?
« Last Edit: October 31, 2008, 04:50:44 PM by Greg »
There are two types of people in the world; those that can extrapolate from incomplete data sets.

mikep

  • Jr. Member
  • **
  • Posts: 17
Re: How do you program a stepper with an encoder for feedback?
« Reply #4 on: November 04, 2008, 02:42:49 PM »
Greg,
I want to thank you for all your effort helping me.
I just couldn’t find any information on how to do this.
Thanks Again,
Mike P.



mikep

  • Jr. Member
  • **
  • Posts: 17
Re: How do you program a stepper with an encoder for feedback?
« Reply #5 on: November 18, 2008, 01:07:02 PM »
Steps 9 and 10 don't seem to work as you wrote.
If I enter 10000 in V2030 it moves, but if I enter 5000 it moves in the same direction just not as far.
If I enter a negative number in in V2030 it will travel in the opposite direction.
I also noticed if I removed the Encoder wires to the ctrio, the motor stills runs telling me that the encoder in not being used in the program.
If I go to the workbench program and look at the outputs they do count.
Have I done something WRONG !!!!
« Last Edit: November 18, 2008, 01:24:38 PM by mikep »

Greg

  • HostTech
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 684
  • Hmmm...
    • Host Engineering, Inc.
Re: How do you program a stepper with an encoder for feedback?
« Reply #6 on: November 20, 2008, 09:20:59 AM »
Hi mikep & alida,

Steps 9 & 10 should work (they work here in the lab for me). Dynamic Position does not use the encoder input to determine where it is, it remembers, instead, the positions you have told it to move to and keeps up with the number of pulses it outputs.

Perhaps you have the CTRIO Output configured wrong, or wired wrong. Or perhaps you hit the Reset (e.g. C201) between moves. If you toggle C201 (Reset) ON between moves, this will reset the CTRIO to position "zero" and it won't remember the previous move.

These outputs, if configured for Pulse (Step/Dir), mean that Output0 will always just output pulses regardless of direction. However, this also means Output1 is the Direction bit. Thus:

If Dynamic Position Parameter3 (V2030-2031) = 5000, and Goto Position bit (C241) is toggled ON, then:
     - Output0 --> Outputs 5000 pulses
     - Output1 --> Remains OFF
After execution of the above, the CTRIO "knows" it is at position 5000 and the motor should've moved in a particular direction.

If then Dynamic Position Parameter3 (V2030-2031) = 2000, and Goto Position bit (C241) is toggled ON, then:
     - Output0 --> Outputs 3000 more pulses (has now output a total of 5000 + 3000 = 8000 pulses)
     - Output1 --> Turns ON (reverse direction)
After execution of the above, the CTRIO "knows" it is at position 2000 and the motor should've moved in the opposite direction.

The key above is having a motor drive that utilizes Pulse/Direction. If the drive properly understands this then this will work just fine (like it does for me here in the lab).

If, however, you have the CTRIO Outputs configured for Pulse (CW/CCW), this means Output0 will output pulses for one direction, and Output1 will output pulses for the other direction. Thus:

If Dynamic Position Parameter3 (V2030-2031) = 5000, and Goto Position bit (C241) is toggled ON, then:
     - Output0 --> Outputs 5000 pulses
     - Output1 --> Remains OFF
After execution of the above, the CTRIO "knows" it is at position 5000 and the motor should've moved in a particular direction.

If then Dynamic Position Parameter3 (V2030-2031) = 2000, and Goto Position bit (C241) is toggled ON, then:
     - Output0 --> Remains OFF
     - Output1 --> Outputs 3000 pulses
After execution of the above, the CTRIO "knows" it is at position 2000 and the motor should've moved in the opposite direction.

Again, the encoder that you may have wired to the input of the CTRIO has no bearing on the CTRIO Outputs when using Dynamic Positioning.

Direction is determined in different ways, depending on the CTRIO function you are using. A good summary is here in this FAQ:

http://www.hosteng.com/FAQFiles/CTRIO.htm#FAQ0048

Hope this helps!
« Last Edit: November 20, 2008, 10:08:32 AM by Greg »
There are two types of people in the world; those that can extrapolate from incomplete data sets.

mikep

  • Jr. Member
  • **
  • Posts: 17
Re: How do you program a stepper with an encoder for feedback?
« Reply #7 on: November 20, 2008, 10:58:44 AM »
I checked Outputs 0 and 1 from the Ctrio to the Drive.
They are correct,even verified them with a scope.
Workbench is setup for Pulse(Step/Dir).
Still works the same.

mikep

  • Jr. Member
  • **
  • Posts: 17
Re: How do you program a stepper with an encoder for feedback?
« Reply #8 on: November 20, 2008, 11:04:50 AM »
Here is my Ladder Logic.

mikep

  • Jr. Member
  • **
  • Posts: 17
Re: How do you program a stepper with an encoder for feedback?
« Reply #9 on: November 20, 2008, 11:37:18 AM »
I got it to work it was turning on C240 and C241 at the same time.
After entering Parameter 3 I have shut off C241.
Then turn it on again.After entering Parameter 3.
Thank You Very Much
« Last Edit: November 20, 2008, 11:44:45 AM by mikep »

Greg

  • HostTech
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 684
  • Hmmm...
    • Host Engineering, Inc.
Re: How do you program a stepper with an encoder for feedback?
« Reply #10 on: November 20, 2008, 12:03:24 PM »
Yes, that is probably what was resetting the position (C240); I didn't think of that. Also, you might want to consider putting a normally-open contact on the input leg of the CTRLDPR to control when the table is loaded.
There are two types of people in the world; those that can extrapolate from incomplete data sets.

mikep

  • Jr. Member
  • **
  • Posts: 17
Re: COMPARE ENCODER VALUE WITH CURRENT POSITION
« Reply #11 on: December 22, 2008, 09:44:09 AM »
Since the encoder is not used with the CTRLDPR I Box, I am trying to compare the encoder position with the actual position.
I know the encoder is V2000 but I can't find what variable is the Current Position?

Greg

  • HostTech
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 684
  • Hmmm...
    • Host Engineering, Inc.
Re: How do you program a stepper with an encoder for feedback?
« Reply #12 on: December 23, 2008, 01:25:01 PM »
Current Position is remembered by the CTRIO itself. In other words, it knows how many pulses have been sent out. The encoder you have (provided it is a quadrature type) is giving you current position. If you want to read current position from the CTRIO itself you will have to use a System Function to do this. And even then, you will have to do some math because depending on whether you have the output configured for Pulse (Step/Direction) or Pulse (CW/CCW), will determine how you figure out what the CTRIO already knows. (See above posts).

But, again, if you have provided an encoder attached to the motor you are controlling and are reading what the encoder is giving you (and that encoder is quadrature), then the reading you are seeing in V2000-2001 is the current position.
There are two types of people in the world; those that can extrapolate from incomplete data sets.

gjones

  • Newbie
  • *
  • Posts: 6
Re: How do you program a stepper with an encoder for feedback?
« Reply #13 on: September 30, 2009, 01:56:59 PM »
I am doing exactly this using Run To Position mode.  If you set up the scaleing wizzard for the encoder in work bench you can use the engineering units that you establish there as inputs to the I-Box in your ladder program. when entering a desired position, compare it with the current position and use the comparison to establish direction and which logic to use (greater,equal or less than)

mikep

  • Jr. Member
  • **
  • Posts: 17
Re: How do you program a stepper with an encoder for feedback?
« Reply #14 on: October 05, 2009, 07:34:21 AM »
I abandoned this PLC project. I am using a more suitable motion control system. Intelligent Motion Systems MDrive Motor+Driver Plus Motion Control, it is a much better system.
http:///http://www.imshome.com
« Last Edit: October 06, 2009, 03:36:11 PM by mikep »