Magnus

How to work with encoder. "Beginner"

23 posts in this topic

Hi everyone, Im completely new to PLC programming. First of all a short description of what i want to do: I have one DC motor that runs my whole "application". One revolution completes the application cycle and then its repeated. But at certain points (between 0 to 360 degree of revolution) i want to check if some requirements are met using some basic sensors. if not, the motor should stop since something is wrong. So i have this incremental encoder (2000ppr) to determine the position of the motor axis. My question: How do i set up a high speed counter in the CX-one programer software to determine the axis position (between 0 to 360 degree) I have the basic understanding of contacts, memory bits, addresses, etc. PLC: CP1L-L14 Thanks in advance. /Magnus

Share this post


Link to post
Share on other sites
make sure that encoder is correct type, wired correctly and to correct inputs (not all inputs can be used with high speed counters - check documentation).

Share this post


Link to post
Share on other sites
Thanks for the reply. This is the specification of my encoder: E6B2-CWZ1X https://industrial.omron.co.uk/en/products/catalogue/sensing/rotary_encoders/incremental/e6b2_c/default.html Im guessing that i should use a high speed counter since the high amount of ppr. Maybe im wrong? could i use a regular counter? still i need help to get started setting this up in the software.

Share this post


Link to post
Share on other sites
This is what i have so far: (see attached img) So the "port specifier" is #0010 which refers to the high speed counter 0 according to the instruction help. The "control data" is #0000 which refers to the PV. The "First destination word" is D0. From what i understand the value of the encoder will be registered in that "Data register" In the settings -> Built in input tab i activated "high speed counter 0" and choose linear. Reset: Software reset. (im not sure about this one but i guess this mean that i manually have to reset the counter. this is done with the A531 in the logic.) Input setting: up/down. This will increment the value up or down depending on C or CW rotary motion. it would be really appreciated if someone could make a comment about this setup, if its right or wrong. or if i missed something. Additional question is as follows: How do i use D0 to open/close a contact at a certain value? i want to close a contact when the position is 120 degrees. 2000/360 = 5.555 5.5 * 120 = 666 So the position is 120 degrees when the pulse is 666. (The start button in the picture has the wrong address. This is now corrected) Edited by Magnus

Share this post


Link to post
Share on other sites
Unless I am mistaken, the CP1L cannot accept a line driver input (the only CP1 that can is the CP1H-Y). You need a different encoder. Either the E6B2-CWZ5B or the E6B2-CWZ6C. Your rungs are red (error, will not compile) because you are putting multiple rungs in the space that one rung should be in. See my picture below. Each rung should be in its own rung space as shown. The counter should be set up as differential phase input as shown below. It should be set up to use circular mode with a circular max count of 8000 (in this mode, if you have a 2000 line encoder, you will count 8000 pulses per rev). This will make the counter count up to 8000 and then roll over to 0 as it goes past 8000. The present count value for counter 0 will be in A270 (and A271) as a Double Integer. Depending upon how fast your encoder counts and how accurate you need your output control to be (closing a contact at 120 degrees), there are two ways to do this. One method would be to simply do a >=L comparison instruction with A270 and &2667 (120 degrees * 8000/360). This would turn the output on when it was above 120. If you wanted to turn it off when it was above 150, then you would add another comparison in series with the first <=L A270 &3333. If this is not responsive enough for you, then you would look at using the CTBL instruction and calling an interrupt from that instruction. Lets just start with the comparison instructions and see if that works first.

Share this post


Link to post
Share on other sites
Michael, thank you very much for helping me out. Now i have refined my logic as you suggested. Se attached image below: If Sensor 1 "returns false" when position is between 120-121 degree the "fail switch" bit is set, thus canceling the motor latching. Same thing with Sensor 2 but at 280-281 degrees. This gives a window of 1 degree for the sensor to operate which is enough for my application. Now my next question is: instead of hard-coding the comparison variable i want to obtain it from a stored variable. My plan is to create a HMI to allow calibration of the machine. in other words, the possibility to change the comparison variable value through the interface. is there a simple concept for achieving this? Also, where do i find the documentation about A270 and similar. Thanks again for all the help

Share this post


Link to post
Share on other sites
To obtain the comparison values from a variable, just change out the constant values for a Data memory address. You could then have this: >=L A270 D0 <=L A270 D2 Set W1.00 Note that you need to use two DM addresses as the comparison is long (Double Integer), so the comparison point is also long. Your HMI would then write a double integer to D0 and D2 in this example. You can find further information in section 5-1 the CP1L Operations manual (Manual number W462). Here is one link to the manual: http://downloads.omron.eu/IAB/Products/Automation%20Systems/PLCs/Compact%20PLC%20Series/CP1L/W462/W462-E1-08+CP1L-CPU+OperManual.pdf

Share this post


Link to post
Share on other sites
Also, how fast is the DC motor turning? My concern is that you may miss the 1 degree window that you have programmed using this method. The scan time of the PLC is certainly a concern when trying to look at such a small window. Unless your motor is moving very slowly, you will likely need to use the CTBL instruction and an interrupt program.

Share this post


Link to post
Share on other sites
"Note that you need to use two DM addresses as the comparison is long (Double Integer), so the comparison point is also long. Your HMI would then write a double integer to D0 and D2 in this example." So basically, all i have to do is to make sure that i write a Double integer from the HMI Application? And thanks for sharing the operations manual. This will help a lot.

Share this post


Link to post
Share on other sites
So this can happen if the "scan time" is longer then what it takes for the pulses to go past the comparison window? In other words, if scan time is 20ms and and the pulse frequency is larger then 20ms, one or more pulses is not registered. Motor speed is fairly slow tho, 60 to 100 rpm Edited by Magnus

Share this post


Link to post
Share on other sites
The counter will not miss the pulses as the high speed counting is independent of the scan time. However, value in A270 is only checked in the comparison instructions one time each scan, so you are dependent upon the scan with this method. The CTBL instruction, using an interrupt is not dependent upon the scan and will definitely run the interrupt code when it is within the range. 100 rpm = 1.666 revs / s, which is 0.6s /rev. Therefore each degree takes about 1.7ms. If your window is only 1 degree wide, it is highly unlikely that you will check your sensor each time. I will try to test out some code and post a sample for you using an interrupt and the CTBL instruction.

Share this post


Link to post
Share on other sites
Thanks for the explanation, it makes sens. I agree that a CTBL is needed for this application. If you have time to make some sample code for a CTBL instruction i would be very grateful. Meanwhile, im going to try to make it myself with the manual as reference. Again i want to thank you for all the help.

Share this post


Link to post
Share on other sites

I was able to write up a sample program today. It is attached below: CTBL Example.cxp Note that it is necessary to disable the input filter so that the input for the sensors can be detected immediately and not have to be on for 8ms (default). This setting is shown below: Also, the contact for the sensors need to be set up for immediate refresh. To understand why, you need to know how the PLC updates its I/O. At the beginning of each scan of the cyclical programs, the inputs are updated, then the program scans and the outputs are updated. If an input turns on mid-scan, it will not be detected until the next scan. Immediate refresh updates the input point when the rung that has the immediate refresh contact hits. This is a simple checkbox for the contact, see below: This code will run the associated interrupt programs as many times as it can while within the range. You can change the ranges on the fly (eventually from your HMI), but if you make a lower limit greater than an upper limit in the process of changing the setpoints, you will get an error with the CTBL instruction. Check it out.

inputfilter.jpg

ImmedRefresh.jpg

Share this post


Link to post
Share on other sites
Thank you, looks great! Well, let me just sum it up to make sure that i understand. And also since im new too this i have some questions :) 1. the CTBL instruction does replace the PRV. Instead of putting the encoder value into a variable it compares the value with a comparison table. 2. The first rung (0) in the main section 1 is only to put hardcoded values into the LowerLimitSPRange1, UpperLimitSPRange1 variable etc. (this can be done directly from the HMI and could then be removed?) 3. The second rung (1) sets up the variables for a comparison table for the CTBL instruction. From the LowerLimitSPRange1 to LowerLimitRange1 variable. etc, (Cant LowerLimitRange1 etc be set directly from the HMI?) 4. When you create a new interrupt task from the insert program tab, you can choose the interrupt task "number". The CTBL will execute different interrupt task "numbers" deepening on what range that fires. Example, if range1 fires its going to automatically execute interrupt task "number" 0? 5. The CTBL always uses 8 ranges when control data is set to (#1), only 2 are used so the rest has to be disabled? 6. By setting the CTBL first comparison table word to D500 the instruction will look for range 1 lower limit rightmost in D500, upper limit in D502. Since D500 is specified in the instruction, it will continue to look for the other range values in the D500 "series". In other words, by setting D500 as the operand in the CTBL instruction, the value of the D500 is used to set the range1 lower limit, but also to specify that D5 is the series to look for the other ranges values. (range2 = D505, range 3=D510 etc,) 7. The channel filter does apply to all inputs with 0.xx addresses? including the high speed counter and other inputs connected in the 0.xx? 8. These filters are normally used to prevent false input signals? Edited by Magnus

Share this post


Link to post
Share on other sites
See my underlined responses below.

Share this post


Link to post
Share on other sites
Alright, now when i did look at it again i recognized that the interrupt task number was defined manually, just like you said. apart from that it feels like i did understand the rest correctly. Thank you very much for sharing your knowledge. Regards, Magnus

Share this post


Link to post
Share on other sites

Hi Guys,

Could someone from the administrators, fix this page.  The program sample link is not accessible anymore.  I currently have a project, bag machine, wherein I have to use a CTBL instruction with interrupt.  I just need the guidance on how to move forward with the code.

Thank you very much.

Cheers,

Leo

Share this post


Link to post
Share on other sites

Dear Michael,

 

Thanks for fixing the page.  I was able to look into the sample program.  My encoder program is basically for a bagging machine, using an unprinted wrapper material ( no registration mark ).  I make the CTBL as a target value comparison, but I do know how to call / insert the interrupt in the program.  I already set the interrupt input IN2 to interrupt.

What I wanted is to compare the value of encoder with my PV value, and, if the same value, then set a bit. Then clear the encoder, for another cycle.

Thanks for your feedback.

Cheers.

Leo

 

Encoder Program.cxp

Share this post


Link to post
Share on other sites

I am currently reading manual W480 on the interrupt programming.  Hope I could still get more feedbacks regarding CTBL instruction.

Thanks again.

C

heers.

Leo

Share this post


Link to post
Share on other sites

Dear Michael,

Thanks for your post and sample program, I was able to make the program with interrupt task.  The program I have made has only 1 target value, and after the interrupt task, the bit will not reset / clear.  

 I've tried using CLI but still the interrupt bit is always ON.  How can I reset the interrupt task?  

Cheers,

Leo

Encoder_Program_Modified_RUnning.cxp

Share this post


Link to post
Share on other sites

Dear Michael,

Hi, I already got the program running and was able to reset the CTBL, and then cycle again.

Thanks again.

Cheers,

Leo

Share this post


Link to post
Share on other sites
On 4/23/2017 at 5:18 AM, LD_M said:

Dear Michael,

Hi, I already got the program running and was able to reset the CTBL, and then cycle again.

Thanks again.

Cheers,

Leo

Hello Leo, how do you reset the CTBL for every cycle? I have a bagging machine but I have not be able to load CTBL efficiently every cycle. Regads, Andres

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