Local time not correct

Jozir

Member
Join Date
May 2018
Location
Vlaams-Brabant
Posts
55
Hello everyone,

I'm currently working with a S7-1200 PLC (AE30 V2), software program V13.

My problem:
Whenever I start the CPU, the time is set at 1970-01-01-00:00:00 instead of the current local time.
I took a look at the online&diagnostics, went to 'set time' under 'functions', this was correctly configured and also 'Take from PG/PC' was checked so I honestly don't know what the problem is.

What I want to do:
1)Read local time when signal on I0.0 (using RD_LOC_T)
2)Read local time again when signal on I0.1 ^^
3)Divide those and put in a variable ( using T_DIFF)
4)Use math functions to get from nano seconds to seconds.

This is not possible when the local time is not correctly.

All help is welcome.
Thanks in advance!
 
I think the internal clock is run by some capacitor that holds its charge for X amount of time (a few weeks?) while the PLC is off. It will go back to default once the cap is drained. How long are the PLCs off for?

Also, I thought the 1200's and 1500's defaulted to a more recent time (2011 or something?) than 1970, could be wrong tho. I think 1970 is the value of an empty DATETIME datatype. If all your reads are coming back as 1970 Jan 1 0 sec, you might just be reading/writing the wrong tags.

If it's really resetting back to 1970 each power cycle, you might try utilizing an NTP server, or sync back to a GPS clock.

Edit: another thought: just because the take time from PG/PC box is checked, doesn't mean it automatically happens. You still need to press the button to set the time in the PLC. What time is the PLC telling you it is set to on that screen?
 
I think the internal clock is run by some capacitor that holds its charge for X amount of time (a few weeks?) while the PLC is off. It will go back to default once the cap is drained. How long are the PLCs off for?

Also, I thought the 1200's and 1500's defaulted to a more recent time (2011 or something?) than 1970, could be wrong tho. I think 1970 is the value of an empty DATETIME datatype. If all your reads are coming back as 1970 Jan 1 0 sec, you might just be reading/writing the wrong tags.

If it's really resetting back to 1970 each power cycle, you might try utilizing an NTP server, or sync back to a GPS clock.

Edit: another thought: just because the take time from PG/PC box is checked, doesn't mean it automatically happens. You still need to press the button to set the time in the PLC. What time is the PLC telling you it is set to on that screen?

it shows the current time so that one is right
 
I think the internal clock is run by some capacitor that holds its charge for X amount of time (a few weeks?) while the PLC is off. It will go back to default once the cap is drained. How long are the PLCs off for?

Also, I thought the 1200's and 1500's defaulted to a more recent time (2011 or something?) than 1970, could be wrong tho. I think 1970 is the value of an empty DATETIME datatype. If all your reads are coming back as 1970 Jan 1 0 sec, you might just be reading/writing the wrong tags.

If it's really resetting back to 1970 each power cycle, you might try utilizing an NTP server, or sync back to a GPS clock.

Edit: another thought: just because the take time from PG/PC box is checked, doesn't mean it automatically happens. You still need to press the button to set the time in the PLC. What time is the PLC telling you it is set to on that screen?

https://ibb.co/nPhnNo

currently have this. Time still remains 1970 hmm
 
Those are just the start values, ie what the tag is initialized to when the PLC starts up. You'd need to monitor the tags, blocks, or create a watch table to find out the actual value.

I can't monitor an interrupt since it's only executed one cycle. I tested it this morning but the 'Tijd_nano' remained 0.
 
I can't monitor an interrupt since it's only executed one cycle. I tested it this morning but the 'Tijd_nano' remained 0.

Fair. For now, try to do something simple. Do you know the interrupts are being called?

I'd recommend testing two things:

1) move the code from interrupt 0.0 and 0.1 into your Main OB, and then trigger the calls on the value of the appropriate input. That way, you can test the IO and the time code. The times won't be as accurate, but you should get SOMETHING. Note that it may require you to trigger the inputs with a finger or roll the ball slowly, instead of properly rolling the ball at speed.

2) set a new tag in each interrupt that says it has been executed. you can reset it manually, from a watch table.

When you test the code, you should be able to see if the inputs trigger at all, and if so, if the time code seems to do anything. You should also find out if the interrupts are triggering at all.
 
Fair. For now, try to do something simple. Do you know the interrupts are being called?

I'd recommend testing two things:

1) move the code from interrupt 0.0 and 0.1 into your Main OB, and then trigger the calls on the value of the appropriate input. That way, you can test the IO and the time code. The times won't be as accurate, but you should get SOMETHING. Note that it may require you to trigger the inputs with a finger or roll the ball slowly, instead of properly rolling the ball at speed.

2) set a new tag in each interrupt that says it has been executed. you can reset it manually, from a watch table.

When you test the code, you should be able to see if the inputs trigger at all, and if so, if the time code seems to do anything. You should also find out if the interrupts are triggering at all.

When I cross my sensor with my hand I see 2 inputs (1 normal 1 configured as interrupt) flashing on the plc, same for my other sensors. So the interrupt definitely triggers.
Btw what do you mean with setting a tag that shows whether or not it has been executed?

Also good thinking to put the code in my main, I'll try that aswell.
 
When I cross my sensor with my hand I see 2 inputs (1 normal 1 configured as interrupt) flashing on the plc, same for my other sensors. So the interrupt definitely triggers.
Btw what do you mean with setting a tag that shows whether or not it has been executed?

Also good thinking to put the code in my main, I'll try that aswell.

If you see the LED on the input turn on, that is different than the interrupt triggering. You need to actively enable the interrupts in the device properties, there are a few settings, and it could easily be misconfigured.

What I'm suggesting to do in the interrupt is to add a rung with just a SET coil (not a regular coil). Put a new tag on it, named something like "interrupt 0.0 executed". In a watch table, monitor that tag (should be false to start), then trip the input (bit should go true). You can then reset it from the watch table if you want to, or just delete it entirely.
 
If you see the LED on the input turn on, that is different than the interrupt triggering. You need to actively enable the interrupts in the device properties, there are a few settings, and it could easily be misconfigured.

What I'm suggesting to do in the interrupt is to add a rung with just a SET coil (not a regular coil). Put a new tag on it, named something like "interrupt 0.0 executed". In a watch table, monitor that tag (should be false to start), then trip the input (bit should go true). You can then reset it from the watch table if you want to, or just delete it entirely.

Ooh that method, I used that a couple days ago with a timer in my interrupt which is not possible. Quick and easy to see if the interrupt is actually activated.

https://ibb.co/kakVso

i think my interrupt is configured right.
 
Your screenshot shows Channel 1 and 2 on the inputs, but originally you said it was 0.0 and 0.1. Is this correct?



Also, the T_DIFF instructions mentions this:



If the result of the subtraction is outside the TIME range, the result is set to "0" (0:00) and the enable output ENO = "0".


Do you see the return val of the instruction to see if all is ok?



I really don't know the TIME range... but if you're counting in nanoseconds it can't be much.
 
Your screenshot shows Channel 1 and 2 on the inputs, but originally you said it was 0.0 and 0.1. Is this correct?



Also, the T_DIFF instructions mentions this:



If the result of the subtraction is outside the TIME range, the result is set to "0" (0:00) and the enable output ENO = "0".


Do you see the return val of the instruction to see if all is ok?



I really don't know the TIME range... but if you're counting in nanoseconds it can't be much.

I just gave random inputs as example.
Originally I would execute my calculations using milliseconds but that is not an option so I'm gonna use nanoseconds. I haven't really checked the return value.
Do you suggest that I rather use a SUB block?
 
from the manual:
Real time clock retention time 20 days typ./12 days min. at 40 °C (maintenance-free Super Capacitor)
if it isn't holding the time it may just be a faulty PLC. Does the time move on whilst you are powered up or does it stay the same, you can check in diagnostics.

What I want to do:
1)Read local time when signal on I0.0 (using RD_LOC_T)
2)Read local time again when signal on I0.1 ^^
3)Divide those and put in a variable ( using T_DIFF)
4)Use math functions to get from nano seconds to seconds.

This is not possible when the local time is not correctly.
So long as the current time is moving and you are only looking for a difference between one time and another it doesn't matter that it is going back to 1970-01-01-00:00:0, time difference should be the same.


Code:
#Previous_Time:= #Current_Time;
// Transfer Current time to previous time
#"Cycle_Time_n-1":= #Cycle_Time;
// Get the new Current Time
#sPIDCalc."RD-Sys_T_return":= RD_SYS_T(#Current_Time);
// Subtract Current from Previous to get Time in ms
#Cycle_Time:= T_DIFF(IN1:=#Current_Time, IN2:=#Previous_Time);
// Convert to Real and divide by 1000 to get time in seconds
 #sPIDCalc.Time_in_Secs:= DINT_TO_REAL(TIME_TO_DINT(#Cycle_Time))/1000;
This some SCL code I use to do the same thing but within a PID Loop to get the cycle time.


In the PLC properties 'Time of Day' I have set the time zone, and I don't think it should matter but I have also defined some memory in 'System and Clock memory'.
 
Stupid question, wouldn't a timer with a large preset do?

Why RD_LOC_T and not RD_SYS_T? I would assume you need to set up a timezone for the RD_LOC_T, which I can't see where in the hardware config for this to work.

I haven't got a simulator at work, or a PLC, but we'll give it a try at home.
 

Similar Topics

Is there a way to add a local message display to Studio 5000 View Designer? If its there, I’m not finding it. I have used them in older versions...
Replies
11
Views
393
Hi, I'm trying to export data from a DataGrid to Excel using VBA, but I'm getting an error "Object doesn't support this property or method". The...
Replies
0
Views
71
So our Powerflex 525's are set up to allow REMOTE operation from PLC through network. But if network is lost we want to be able to run in LOCAL...
Replies
5
Views
556
Migrating v8 FT View SE to v13, had to export tags because after v10 the configuration is no longer supported. Imported tags to new Tag Alarm...
Replies
1
Views
502
Hello, the PLC in question is 1769-L30ER. I have a local 4-20mA Analog Output module (1769-OF4CI), and also a remote ethernet PointIO analog...
Replies
0
Views
394
Back
Top Bottom