Modicon 221 encoder issues

spkrman15

Member
Join Date
Jan 2016
Location
Gatineau
Posts
9
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.
 
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 :)
 
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 (y)
 
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
 
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?
 
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 :)
 
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?
 
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.
 
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?
 
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 :)
 

Similar Topics

Hey Programmers, Heres todays puzzle I was trying to solve... I have a Modbus TCP network with two Modicon M221 controllers live on my work bench...
Replies
0
Views
449
Hey everyone! I have trouble making sense of the math conversion in this seconds tag of the Modicon M221 Real Time Clock. I thought I understood...
Replies
4
Views
1,554
Hi all, i am trying to scale a 0 - 1000 analogue input to a -10000 to 10000 output with 0-500 been -10000 to 0 and 501-1000 to 0-1000 is there...
Replies
7
Views
2,854
Hi All, I'm looking for some insight into what the SHORT instruction does. The help file wasn't very useful, as I found the explanation to be...
Replies
4
Views
1,448
Hi all. I’m currently trying to combine 3 memory words in to a single display on a weintek hmi as I want to display running time. I have the...
Replies
4
Views
1,784
Back
Top Bottom