TheJacobsDad

Converting Floating Point - TIME...Help needed please

9 posts in this topic

Hi all,

I am back again with another head scratcher well (2 actually but they are related). First up I am using Logix Studio with a CompactLogix at v24.00

First up I have a time input from Scada as a floating point (REAL) which is an operator input

I have my clocktime in the PLC set as a DINT using GSV with a resulting structure of

PLCDateTime.Year

PLCDateTime.Month

PLCDateTime.Day

PLCDateTime.Hour

PLCDateTime.Minute

PLCDateTime.Second

PLCDateTime.Millisecond

How can I take the operator input (for example 16.30) and split it so I can send the Hours (16) to a DINT in a similar structure called ScadaSchedule.Hour and the minutes (30) to ScadaSchedule.Minute. I then want to compare the .Hour and .Minute from ScadaSchedule and PLCDateTime and trigger start stop times based on the comparison

Next I need to set up 5 time schedules (not disimilar to a central heating timer)

1. A fixed start time and stop time which runs every day - 16:00 - 19:00

2. 4 Manual schedules which the operator can input in Scada based on the information he gets for that days generation requirements, so he might get a manifest that says to run between 08.00 and 10.00 then later at 12.00 to 14.00 and so on

I need to be able to store the schedules in the PLC and issue my start and stop commands and account for any overlap with the automatic schedule. At Midnight I want to reset all schedules and ignore them until the operator inputs the schedule times.

Any help would be greatly appreciated

Thanks

 

Dan

 

 

 

 

 

 

Edited by TheJacobsDad

Share this post


Link to post
Share on other sites

Will you be utilizing Daylight Savings Time?  This can throw a huge wrench in the works.

Share this post


Link to post
Share on other sites

Hi,

 

I was planning on syncing the PLC clock time to the Scada Server time using clock update tool

 

Share this post


Link to post
Share on other sites

The ControlLogix rounds when you move a REAL to a DINT, so you can't just move it to a DINT or 16.59 will become 17.  However, you can subtract:

SUB Float_Input 0.5 DINT_Hours

I got the minutes in 2 steps: MOD and MUL:

MOD Float_Input 1 HoldingRegister01 MUL HoldingRegister01 100 DINT_Minutes 

HoldingRegister01 is a REAL tag used as an intermediate step

You will want to limit check both values to make sure the operator didn't enter something like 16.8 instead of 16.08.  Unless you want them to be able to enter 16.8, in which case you'll need some more complicated code...

Share this post


Link to post
Share on other sites

Joe,

Nice one that works a treat, not used a MOD instruction before so I have learnt something new so my sincere thanks to you.

I know have my float input being spat out into two DINT's nicely so I can use it in my program.

Now if anyone can come up with some help on the schedule side of things in an elegant way keeping the amount of code down I would appreciate any help on doing this

 

1. A fixed start time and stop time which runs every day - 16:00 - 19:00

2. 4 Manual schedules which the operator can input in Scada based on the information he gets for that days generation requirements, so he might get a manifest that says to run between 08.00 and 10.00 then later at 12.00 to 14.00 and so on

I need to be able to store the schedules in the PLC and issue my start and stop commands and account for any overlap with the automatic schedule. At Midnight I want to reset all schedules and ignore them until the operator inputs the schedule times.

Share this post


Link to post
Share on other sites

For that, it's probably easiest to convert all of your times back to a REAL, so that 3:30PM becomes 15.50, 2:54PM becomes 14.90, etc.  Then just use a LIM instruction to see if current time is between the start/stop times provided.  Parallel all of the time windows and if any are true, run.

For example, if your time is stored in 2 DINT registers, HOUR and MINUTE with TimeNow being a REAL:

DIV DateTime[4] 60 TimeNow ADD TimeNow DateTime[3] TimeNow 

You would do a similar calculation on the manual run windows (or just have the operator enter it in the correct decimal format directly).  Then you could do this:

BST LIM FixedStart TimeNow FixedStop NXB LIM ManualStart1 TimeNow ManualStop1 BND OTE Run 

TimeWindows.PNG.6686cd36583d422d335b46fd

At midnight, you can just write the value "50.0" (or similar) to all of the ManualStartx and ManualStopx tags.  The TimeNow will never get there, so those LIM instructions will always be false.

Edited by Joe E.
Added note about what to do at midnight

Share this post


Link to post
Share on other sites

Brilliant, thats a great solution with minimal code.

One last question - How can I do it so that the start stop time inputs can be made using a normal time format as oppose to a decimal ? ie the operator can enter the value as 15.30 instead of 15.50

 

Thanks for your help thus far

Dan

Share this post


Link to post
Share on other sites

Kind of combine the steps above.  While looking for an instruction that would adjust the precision of the REAL to 2 places, I discovered the TRUNCATE instruction, which strips out the decimal portion very cleanly without using SUB or rounding:

TimeWindows2.thumb.PNG.23f152837d7fa3184

The operator would enter 4:45PM as 16.45, the result would be 16.75.

 

Edited by Joe E.

Share this post


Link to post
Share on other sites

You sir are a Gentleman and a Scholar........Works like a charm.

Sincere thanks for all your help

 

Dan

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