You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old February 17th, 2018, 09:47 AM   #1
spkrman15
Member
Canada

spkrman15 is offline
 
Join Date: Jan 2016
Location: Gatineau
Posts: 7
Cool Modicon 221 encoder issues

Hey Everyone,

I have a Modicon TM221C16T hooked up to a Dynapar ha625 2000ppr encoder. It is sending the information to a Magelis HMI.

I am setting it up so the user can enter a value in the hmi and then the plc will close a contactor to make the motor go forward or reverse, depending on the entered value.

the user enters a number and then presses a button to activate the movement. I am setting a bit in the HMI and using the PLC to reset the bit when the encoder drops above or below depending on the motion.

the issue is that when i turn the encoder by hand fast, the reset bit is being activated approximately 1 revolution before the targeted value. I can hit the go button again and the coil will activate until the correct value is reached.

If i turn slowly, the coil will stay on until the desired value is reached.

This issue is pretty consistent and turning by hand is not the same speed as a motor can.

I am using Somachine basicfor the PLC and Vijeo Designer for the HMI.

I am doing this for a learning experience, (i am a millwright by trade) but after several days of testing i am lost. Any help would be greatly appreciated.

Thanks In advance.

Rob

p.S. I have a 100ppr encoder and it does the same thing as well.
  Reply With Quote
Old February 19th, 2018, 10:56 PM   #2
spkrman15
Member
Canada

spkrman15 is offline
 
Join Date: Jan 2016
Location: Gatineau
Posts: 7
Hey everyone,

so i found my problem. I am converting my High speed counter to a floating point (real) variable and dividing it by the number of pulses on the encoder . 2000 in my case. I had the program set for when the value of my encoder would read 0.999 it would increment a WORD value by one and reset the counter to 0 (my preset). the same was done for -0.999 but it would decrease the same word value by one.

unfortunately that value was too close and the WORD value was being increased before the reset of the High speed counter which would give me a false value as the encoder added a few pulses before it was reset and that value was being used if i rotated the encoder too fast.

I reduced the trip point to 0.9 and -0.9 respectively. No more intermittent issues.

I have been racking my brain for days! I have been reading the forum and watching videos and someone mentioned scan time. That helped me and i played with my trip points. It would be nice to get back to the hours i spent on this but it is part of the learning curve i guess.

To those of you sharing your knowledge thank you.

Now to make the HMI look good.

Rob
  Reply With Quote
Old February 20th, 2018, 11:09 AM   #3
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,048
never ever use float / reals to counting up or subtracting counter.
Best is to use Dint (double integers) values and you won't have precision problems because of rounding or exponent part of float
  Reply With Quote
Old February 20th, 2018, 12:32 PM   #4
spkrman15
Member
Canada

spkrman15 is offline
 
Join Date: Jan 2016
Location: Gatineau
Posts: 7
Hey lare,

I am increasing or decreasing an int value and then converting it to a float and adding the encoder present value divided by the pulse per rotation which are also converted to float values before the addition.

If i have a Dint value say 375 / 2000 that value isn't going to work as a Dint as i will get a fraction value in return no?

I will post the code later tonight. There's probably a better way to do things
Rob
  Reply With Quote
Old February 21st, 2018, 12:56 AM   #5
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,048
you counting pulses to int, that is good.

You can change int to dint and multiple with 1000, then divide by 2000 and you get dint value With 3 "decimals".
You can also place Full part of (int) division to one word and remainder to another word.
(Not sure if M221 have division remainder somewhere at system words.)

One dint can have value -2147483648 to +2147483647 so you can even multiple by 10000 and still place value to dint (2000*10000)




375/2000 0.1875
375 *1000 /2000 = 188
375*10000 / 2000 = 1875

Does this make any difference?
  Reply With Quote
Old February 21st, 2018, 08:07 PM   #6
spkrman15
Member
Canada

spkrman15 is offline
 
Join Date: Jan 2016
Location: Gatineau
Posts: 7
Still having problems

Lare,

I think i am going to have to try that. I thought i had it figured out but when i did some more testing the issue came back.

I will set up the parameters like you suggested. I noticed last night that i can have the HMI show the decimal point in a Dint value so what you suggested is what i think i will try.

In the mean time here is the code i wrote. Well part 1
Attached Files
File Type: zip Ambico_Encoder_4 part 1.zip (341.8 KB, 9 views)
  Reply With Quote
Old February 21st, 2018, 08:11 PM   #7
spkrman15
Member
Canada

spkrman15 is offline
 
Join Date: Jan 2016
Location: Gatineau
Posts: 7
And now for part 2

Rob
Attached Files
File Type: zip Ambico_Encoder_4 part 2.zip (298.4 KB, 6 views)
  Reply With Quote
Old February 22nd, 2018, 12:26 PM   #8
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,048
I see that you are reseting HSC every time when float value is more tha 0.9 or less than -0.9
Can this lead to problem that you have little error to counter every time when HSC is resetted.

It can be also scan issue, espicially if movement works with slow speed.
PLC counts HSC at first rung, then later you do math for %MF56 and set bits %M0 and %M1.
Bits are readed and HSC reseted on 2nd PLC scan, so there is offset of one scan time now for HSC.
Maybe addind another HSC counter block (%HSC0), which only resets HSC after rung3 is also good?
  Reply With Quote
Old February 22nd, 2018, 12:57 PM   #9
OkiePC
Lifetime Supporting Member
United States

OkiePC is offline
 
OkiePC's Avatar
 
Join Date: Mar 2005
Location: ENE of Nowhere Oklahoma
Posts: 9,981
Never reset the counter... okay, maybe rarely reset the counter for things like out of the box startup or when mechanical service has been performed, but not for normal operations. Use an offset value to record your home position or use the high speed counter built in functions to deal with it. Let it rollover naturally and use logic to detect this and account for it. Resetting the counter with normal PLC logic is asking for trouble since the encoder can move and increment faster than a typical PLC scan time...

I speak in general terms since I know nothing about your particular PLC model.
__________________
It's not all the variables I am most concerned with, it's the undiscovered constants.
  Reply With Quote
Old February 22nd, 2018, 01:39 PM   #10
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,048
https://www.schneider-electric.com/en/faqs/FA241661/

AS OkiePC staded, this probably is scan issue and you loose counts for HSC when resetting.

Record your home position when needed and use offsetting from home position.
You can change your HSC also to double word counting if it makes things easier. I didn't notice that there is rollover bits.
There is overflow bit, but will it change automatically to count from 0?
  Reply With Quote
Old February 23rd, 2018, 02:02 PM   #11
spkrman15
Member
Canada

spkrman15 is offline
 
Join Date: Jan 2016
Location: Gatineau
Posts: 7
OkiePc,

Thanks for the feed back about the resetting. Makes sense. I will do things another way and see how that goes

Lare,

After reading yours and OkiePc's comments i am going to redo everything using DW and then use the HMI to show the decimal point

I will let you know how it turns out

Rob
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Rotary Encoder in PLC Modicon M340 dannu LIVE PLC Questions And Answers 3 January 5th, 2017 10:14 AM
Encoder woes PLC Pie Guy LIVE PLC Questions And Answers 18 September 9th, 2015 05:32 AM
Help with encoder connected to logic circuit Zenith63 LIVE PLC Questions And Answers 6 October 24th, 2011 03:26 AM
Mitsubishi Pulse gernerator and encoder? Tim LIVE PLC Questions And Answers 0 August 23rd, 2010 11:02 AM
Powerflex 700S2 / 2 encoder problem Bitpopler LIVE PLC Questions And Answers 3 August 31st, 2008 10:21 AM


All times are GMT -5. The time now is 03:20 AM.


.