Hello everyone, I'm facing a challenge in converting a %MW to a %MF using Machine Expert Basic on a Modicon M221 PLC. The software's help files only show a conversion from a word to a double (%MD:=DWORD(%MW)), but there doesn't seem to be a way to directly convert %MW to a floating-point %MF for simple multiplication operations like "* 1.5". Does anyone have a workaround to help the processor perform this mathematical operation? Unfortunately, we do not have a SCADA application at this site to assist the processor. Thank you for taking the time to read this post.
I have discovered a workaround solution for the issue mentioned in my previous post. The EcoStructure Machine Expert Basic on this particular model has the capability to perform division and multiplication operations using whole number integers. By implementing a two-step process in the rung logic, it is possible to achieve a fractional result. For example, to multiply %MW100 by 1.5, you can multiply the integer by 9 and then divide the result by 6, which is equivalent to 1.5. This approach is accepted by the program compiler. This workaround saves the hassle of purchasing a higher-end controller just for a few mathematical functions in small installations.
To enhance performance, consider optimizing further using the 3/2 ratio. Keep in mind that when performing integer division, the remainder is usually ignored, so it's best to multiply first to avoid overflow. I primarily utilize discrete IO and timers on the M221, but I am willing to refresh my knowledge and explore new features.
In this code snippet, a new Program Organization Unit (POU) named "New POU" with Section Number 0 is defined. Within this POU, there is a ladder logic program containing three instruction lines. The first instruction line loads data from address 1. The second instruction line calculates a value by multiplying the value at memory word 1 by 3 and then dividing by 2. The third instruction line converts the value at memory word 1 to a real number and then multiplies it by 1.5. The ladder logic program is organized into rungs, with each rung containing the necessary ladder elements.
Utilize the "into_to_real(%MWx)" and "real_to_int(%MFx)" instructions on the M221 PLC for efficient data conversion. These instructions are essential for converting integers to real numbers and vice versa, optimizing PLC programming and operations.
It sounds like you're in a bit of a bind, but there's a possible workaround you can try! You might consider reading the value from %MW as an integer and then performing the conversion to a floating-point number manually. You can scale the integer value to a representation that can be used as a float in your calculations. For example, you could divide by 10,000 (if your percentage value is in parts per ten-thousand) to get the actual float before doing your multiplication. It might not be as clean as a direct conversion, but it should let you perform the operations you need!
✅ Work Order Management
✅ Asset Tracking
✅ Preventive Maintenance
✅ Inspection Report
We have received your information. We will share Schedule Demo details on your Mail Id.
Answer: - Unfortunately, Machine Expert Basic does not provide a direct way to convert %MW to a floating-point %MF for simple multiplication operations. The software's help files only show conversions between different data types like word to double.
Answer: - One workaround could involve using intermediate data types or registers for the conversion process. For example, you could convert %MW to %MD (double word) and then perform the multiplication operation before converting the result back to a floating-point %MF.
Answer: - Yes, you can still perform the necessary conversions and mathematical operations directly on the Modicon M221 PLC using Machine Expert Basic, even without a SCADA application. By utilizing the available data types and registers effectively, you can achieve the desired functionality.
Answer: - While the software's help files may not provide a direct solution for converting %MW to %MF, you can refer to programming guides, user manuals, or online forums for specific examples and guidance on implementing these conversions and mathematical operations efficiently on a Modicon M221 PLC
Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.