Schneider M221 memory word and value assignment

JacksonP

Member
Join Date
Apr 2023
Location
Ontario
Posts
2
Hello,

I am programming a schneider modicon M221 in machine expert basic. I am trying to calculate a value and then assign it to another memory word.
-I name existing memory words in the tools-> memory word side panel
-I use the operation block to perform the calculation
%MW59 := %MW98*%MW99​
-I manually give %MW98 a value, %MW99 has a value from the HMI
-%MW59 remains 0, if I give it an online value it immediately reverts to 0.

The Yellow and black exclamation mark warnings are just saying I should protect my program. I tried several different %mw memory locations to move the value in. I also made sure when selecting a memory location to use that both used and equ used were unchecked before giving them a symbolic name and adding them into the programming.

I'm puzzled. but I'm sure it's something straight forward that I'm missing...I've been hunting through youtube for information but I can't find anything specific to this issue.

Thank you

Prog-Issue1.PNG
 
50/1000 => (integer division) => 0, so %MW498 * (50/100) => %MW498 * (0) => 0

try (%MW498 * %MW99) / 1000, or ((%MW498 * %MW99 + (%MW498 / 2)) / 1000 if you want some rounding.

There might be a problem with integer overflow if %MW99 and/or %MW498 get too big; this may work better if performed with REAL (floating-point) values.

(%MW498 := 1000 / 499) then (%MW99 / %MW498) is mathematically correct, but then you will have problems with roundoff.

Welcome to the forum!
 
Last edited:
50/1000 => (integer division) => 0, so %MW498 * (50/100) => %MW498 * (0) => 0

try (%MW498 * %MW99) / 1000, or ((%MW498 * %MW99 + (%MW498 / 2)) / 1000 if you want some rounding.

There might be a problem with integer overflow if %MW99 and/or %MW498 get too big; this may work better if performed with REAL (floating-point) values.

(%MW498 := 1000 / 499) then (%MW99 / %MW498) is mathematically correct, but then you will have problems with roundoff.

Welcome to the forum!

.... what an embarrassing first post.... thank you, I agree this would work better with floating point numbers. I inherited this program and for whatever reason they have been using integers with just extra spaces instead of floating point with decimals. ie 100.0% from the HMI they would bring back as 1000 into an MW (int) instead of an MF (Float). and I have just been going along with it. I can't believe I didn't see that as a problem. I thought what is going on they are all integers! where is the clown emoji...
 
.... what an embarrassing first post....


Not at all! You posted enough detailed information that a fresh set of eyes saw the problem immediately.

Usually it takes a dozen or more posts before we get to the heart of an issue, so good for you for formulating a great question!

The likely reason you didn't see it and I did is that I have made this mistake many, many, many more times than you over the course of my career (hopefully less frequently as time went on ;)).
 

Similar Topics

Hi again all, wondering if someone can help me. I have a programming running on an M221 PLC and I want to capture some analog data to a series of...
Replies
6
Views
6,273
Hello, I need to access the bits from the fire system control panel through RS-485. So, I used Read Var block to read from the panel...
Replies
0
Views
199
Hi, I am stuck with these SE cartridges, I am trying to add a second serial port rs485 to a M221 PLC. What is the difference between TMC2CONV01...
Replies
1
Views
121
I am using a M221 PLC (TM221CE24R) which provides me 1 Rs485 port, which I am already using to communicate with a sensor (Rs485/Modbus). My...
Replies
1
Views
749
Hello, I am trying to detect when the PLC changes from STOP to START mode. This can be considered an edge case scenario, but I would to analyze...
Replies
4
Views
1,569
Back
Top Bottom