Giorgio

calculation of a "% Efficiency" value to display on HMI

4 posts in this topic

Very new to CX-Programmer, I had a question, hopefully someone here has done something similar and there's some easy copy-paste sample code.

 

Programming a CJ2M-CPU32 using CX-Programmer V9.4 with an NS8 HMI on CX-Designer V3.411

I want to calculate a REAL Operator_Efficiency value from PARTS_COUNT / SHIFT_GOAL_COUNT in the PLC, and display it on the HMI AUTO_CYCLE screen. 

PARTS_COUNTSHIFT_GOAL_COUNT are both DINT,  I tried using the /F (457) Floating Point Divide to calculate a value to REAL Operator_Efficiency , and it calculates properly as long as both PARTS_COUNTSHIFT_GOAL_COUNT are >0, when the Operator first starts PARTS_COUNTSHIFT_GOAL_COUNT are of course both 0 ...

... then using *F(456) Floating Point Multiply for Operator_Efficiency X 100. 

I feel like I'm reinventing the wheel here, I like to have all my logic in the PLC and the HMI just basically be momentary push-buttons and numeric displays with no HMI MACROs/logic to confuse the Industrial Maintenance guys. 

Any help would be nice, modifiable sample code even better,  right now my best guess is try to use a macro in Designer on the NUMERIC_DISPLAY showing Operator_Efficiency to display something meaningful at the beginning when either PARTS_COUNTSHIFT_GOAL_COUNT are 0. 

Including a copy of what I've done so far, its the PARTS_COUNT section

 

AS259-12.bak

Share this post


Link to post
Share on other sites

For starters, you must use a REAL value for all operands in the /F (457) instruction. You cannot mix data types nor will it automatically convert them for you.

EDIT:  It appears you have attempted the conversion with the MOV(021) instruction. This will not work as the MOV will transfer the contents bit for bit (no change). Replace the MOV(021) instruction with the FLTL(453) instruction. This will properly convert DINT to REAL.

Edited by IO_Rack

Share this post


Link to post
Share on other sites

I agree with keeping all your logic in the PLC. You can certainly do this. Do a compare of >0 on your values before performing the calculation. You can then write "0.0" or "100.0" or whatever you want if it is not true.

When comparing the REAL values, be sure to use Floating Point compares. (Example:  >F(333)). When entering static values as an operand, be sure to use a sign and a decimal point. (Example:  +0.0 or +100.0).

Check your compile warnings.

Edited by IO_Rack

Share this post


Link to post
Share on other sites

Thanks IO_Rack, FLTL was exactly the conversion instruction I needed,

I assumed the CXP MOV instruction worked the same as MOV in Logix500/5000, converts Source data-type to Destination data-type, so the CXP MOV instruction is the Logix equivalent of the CPY instruction (for anyone else coming from Logix).

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