Omron dividing and multiplying numbers

Mayfield

Member
Join Date
Jun 2013
Location
Melbourne
Posts
10
Hello everyone, my name is Mick and I'm a beginner PLC programmer



I'm using an Omron CP1L and a NS5 HMI and what I trying to to do is calculate how much a piece of equipment is costing the customer based on the time it is on.


For example if Heater A were on for 3:45:45 h:m:s I could convert the time to decimal using 1 hr + (45/60) + (45/3600) = 3.7625 hrs and them multiply that by their energy costs.


How do PLCs handle numbers and fractions of whole numbers? for example When I divide 45/60 = 0.75 how can this be handled?



Thanks
Mick
 
What you have to remember is that if you use integer maths then the result will be an integer, you need to convert the hours, mins, secs to a float (often called a real) then do the maths.
Alternatively convert hours & minutes to seconds, add them all up convert to a float & then divide by the number of seconds in an hour, this will give you the hours with decimal places, you must also be aware that floating point maths will give you probably 6 or more decimal places but that should not matter.
So hours * 60, Mins *60 Add H + M + S gives you the total number of seconds, you may have to use a long integer but it will depend on the accrued total in seconds as a 16 bit integer is only 32767 & above that will go negative.
A 32 bit long integer (called double integer) will allow a value up to 2,147,483,647
So there will be standard functions within the PLC to convert integers to doubles or integers to floats & 16 & 32 bit integer maths.
I do not have Omron but here it is in Mitsubishi
I assume Omron has those equivelent functions, you will notice the number of decimal places in the total hours, this is a function of floating point maths, float maths do not have a trunk function so if you want to limit it to 3 decimal places then multiply it by 1000 Then convert it to a Double integer , then convert it back to a float, then divide by 1000
So if the original float was 2.504167 then multiply it by 1000
that gives 2504.167.
Convert to integer removes the decimal places i.e. 2504
then convert back to a float & divide by 1000 will result in 2.504 hours
There is probably a better way to do it but this is off the cuff.

Time in Hours.png
 

Similar Topics

I've come across a system running omeron cx-programmer version 9.42. Am I going to need to find a legacy version of the software to edit and...
Replies
1
Views
58
Has anyone done SMS messaging from an Omron CJ2J-CPU31 PLC? If so could you help please. Omron here in Oz have not had any experience doing this...
Replies
5
Views
188
I have an old plc in the system I have, moxa nport was used to communicate with scada, I want to replace the plc with cj2m cpu33 and eliminate...
Replies
1
Views
76
Hi all, i have 8 CJ2m plc units that show different numbers on the plc display and i am stuck on reading the info. my unit has an ip address of...
Replies
3
Views
123
Hi all, Currently having trouble getting a speed reference to write over modbus to an Omron M1... I can successfully write a run command and...
Replies
6
Views
284
Back
Top Bottom