System Clock PLC M340 - Unity Pro

it is bit variable, bool or ebool type.

Usually you need ebool variables, because you want change bits from panel/scada and not only via programming device (By the way you can set clock easier with programing computer at online (PLC rack viewer->PLC card -> double click -> animation. But if you want change it without prorammming device, you have to write little bit code)

For reading/writing bit example from panel variable need usually %M address and you can give %M address only to ebool type variables. For Integers you need %MW addresses and int type variables.
 
No, you want now reset or set %S50 bit, so it have to be on output side and to input pin you connect something else. Unity PLC clock is running when %S50 bit is zero, new time can be adjusted, when %S50 bit is "1" and new time is taked to use at transition "1"->"0".

If you want to use different buttons/bits to setting %s50 bit then use set and reset blocks. If you use same variable for setting and resetting %s50 bit then you can use move block.

You also need adjust years, days and months, on example only seconds and hours and minutes are adjusted ;)
When system words display zeros, is that mean I have to add more function blocks?

Untitled.jpg
 
Last edited:
When system words display zeros, is that mean I have to add more function blocks?

check PLC time first from rack viewer. Sometimes clock have odd time values when PLC is first time booted and clock is not running and you can't change values with system words.

On situations like these you need to give time values first from PLC card animation viewer, because clock is at error state. After you have gived right time to PLC and clock is running, you can start to adjust time via system words.

Anyway, I have noticed that clock is at error state only couple times, when I have started to program brand new PLC.

Also if you give clook time which is wrong, like month value 14, clock is not adjusted and old time is taked back to use.



Also is PLC at run state?
 
check PLC time first from rack viewer. Sometimes clock have odd time values when PLC is first time booted and clock is not running and you can't change values with system words.

On situations like these you need to give time values first from PLC card animation viewer, because clock is at error state. After you have gived right time to PLC and clock is running, you can start to adjust time via system words.

Anyway, I have noticed that clock is at error state only couple times, when I have started to program brand new PLC.

Also if you give clook time which is wrong, like month value 14, clock is not adjusted and old time is taked back to use.



Also is PLC at run state?
Um...how can I find the rack viewer?

Run? Yes.

I've checked the project settings and the Rack Viewer diagnostics information is already checked.

Untitled.jpg
 
Last edited:
I don't mean that.

On project tree, double click configuration folder, then double click PLC card go to animation and navigate to animation sheet. You should now see on left side PLC time, is clock running?


Can you post screen shot of post 32 without animations enabled or whole zipped program. (Unity file at *.sta format)

rack.jpg plc_config.jpg clock_anim.jpg
 
Last edited:
I don't mean that.

On project tree, double click configuration folder, then double click PLC card go to animation and navigate to animation sheet. You should now see on left side PLC time, is clock running?


Can you post screen shot of post 32 without animations enabled or whole zipped program. (Unity file at *.sta format)
Here is the screen shot.

Untitled.jpg
 
Last edited:
Hi,

Today I needed to read and set the M340 rtc. I wrote this code and works fine! I came here to share. I hope to help someone!

Wrote in ST:

(*read*)
IF UNLOCK = 0 THEN
RTC_DAY:=BCD_TO_INT(%SW52 AND 16#00FF);
RTC_MONTH:=BCD_TO_INT(SHR(%SW52,8));
RTC_YEAR:=BCD_TO_INT(%SW53);
RTC_HOUR:=BCD_TO_INT(SHR(%SW51,8));
RTC_MIN:=BCD_TO_INT(%SW51 AND 16#00FF);
RTC_SEC:=BCD_TO_INT(SHR(%SW50,8));
END_IF;

(*write*)
IF UNLOCK = 1 THEN
%SW52:=(SHL(INT_TO_BCD(RTC_MONTH),8))+ INT_TO_BCD(RTC_DAY);
%SW53:=INT_TO_BCD(RTC_YEAR);
%SW51:=(SHL(INT_TO_BCD(RTC_HOUR),8))+ INT_TO_BCD(RTC_MIN);
%SW50:=(SHL(INT_TO_BCD(RTC_SEC),8));
END_IF;

%S50:=UNLOCK;

(*VARIABLES*)
(*RTC_DAY -> INT*)
(*RTC_MONTH -> INT*)
(*RTC_YEAR -> INT*)
(*RTC_HOUR -> INT*)
(*RTC_MIN -> INT*)
(*RTC_SEC -> INT*)
(*UNLOCK -> BOOL*)

(*WHEN UNLOCK = 0 -> READ THE DATA FROM RTC_DAY, RTC_MONTH...*)
(*WHEN UNLOCK = 1 -> VARIABLES (RTC_..) STOPS TO BE UPDATED. WRITE THE NEW DATA IN RTC_DAY, RTC_MONTH...*)
(*WHEN UNLOCK CHANGE TO 0 -> THE PLC GET THE NEW DATA AND CONTINUES TO COUNT*)
 
Last edited:
%S50 not staying updated after it reverts back from 1 to 0...

I am trying to set up time syncing on an M340 and I've followed your excellent comments. The logic seems to work because while it's in runtime I can see the remote time sync values being forced into %SW49-53 while %S50 is set to a 1 but once I set %S50 back to 0 the PLC clock overwrites %SW49-53.

So basically I am only seeing the forced time sync values in %SW49-53 while %S50 is set to a 1. But my understanding (and according to the Modicon Help Section) is that reverting %S50 back to 0 should save the forced values and continue counting from there...

PLEASE HELP...THIS DOESN'T MAKE ANY SENSE!

Thank you!
 
Welcome to forum!


Is the PLC brand new?
Unity clock takes old time to account, if setted clock time is wrong.
This can also happen, if PLC is new and clock isn't at right time from the box. (Clock have wrong value, you set %SW.., clock looks that time is wrong also at beginning... and take original time to account (even that it is wrong)

Double click PLC at online -> animation sheet -> clock / real time clock. Adjust time to right first time with computer. After that you should be able to write new values with system words.
 
hi everyone, in M340 UNITYPRO how to get hours, minutes, seconds with DD/MM/YYYY ... i need some clear clarification about rotate right and rotate left to get hrs,mins,secs seperately...
 
Hi,

Today I needed to read and set the M340 rtc. I wrote this code and works fine! I came here to share. I hope to help someone!

Wrote in ST:

(*read*)
IF UNLOCK = 0 THEN
RTC_DAY:=BCD_TO_INT(%SW52 AND 16#00FF);
RTC_MONTH:=BCD_TO_INT(SHR(%SW52,8));
RTC_YEAR:=BCD_TO_INT(%SW53);
RTC_HOUR:=BCD_TO_INT(SHR(%SW51,8));
RTC_MIN:=BCD_TO_INT(%SW51 AND 16#00FF);
RTC_SEC:=BCD_TO_INT(SHR(%SW50,8));
END_IF;

(*write*)
IF UNLOCK = 1 THEN
%SW52:=(SHL(INT_TO_BCD(RTC_MONTH),8))+ INT_TO_BCD(RTC_DAY);
%SW53:=INT_TO_BCD(RTC_YEAR);
%SW51:=(SHL(INT_TO_BCD(RTC_HOUR),8))+ INT_TO_BCD(RTC_MIN);
%SW50:=(SHL(INT_TO_BCD(RTC_SEC),8));
END_IF;

%S50:=UNLOCK;

(*VARIABLES*)
(*RTC_DAY -> INT*)
(*RTC_MONTH -> INT*)
(*RTC_YEAR -> INT*)
(*RTC_HOUR -> INT*)
(*RTC_MIN -> INT*)
(*RTC_SEC -> INT*)
(*UNLOCK -> BOOL*)

(*WHEN UNLOCK = 0 -> READ THE DATA FROM RTC_DAY, RTC_MONTH...*)
(*WHEN UNLOCK = 1 -> VARIABLES (RTC_..) STOPS TO BE UPDATED. WRITE THE NEW DATA IN RTC_DAY, RTC_MONTH...*)
(*WHEN UNLOCK CHANGE TO 0 -> THE PLC GET THE NEW DATA AND CONTINUES TO COUNT*)

Hi there, I just wanted to say great code! I've pretty much just created the exact same thing in my logic and verified it against your code. Great job and thanks for sharing!🍺
 
Simulation Mode - Writing System Words

Hello,
In simulation mode, I can't write on those system words and the value is correct.

Thanks.
 

Similar Topics

I am using a Studio 5000 with an Allen Bradley CompactLogix 1769-L24ER-QB1B controller. Im wondering how I can use the system clock to be able to...
Replies
10
Views
2,411
HEllo! Where do it setup the clock? Couldn´t find anything useful in General-->Time of day besides daylight saving time. And when i have set the...
Replies
9
Views
1,234
Hello everyone one. I'm using M340 with simulation mode (actually I still don't have the cpu to test the software). I've made a simple counter...
Replies
4
Views
488
I took an online course but don't remember covering this. How do I access the system clock in a compare instruction? I want to turn on an output...
Replies
1
Views
505
hello everyone, I'm trying to set the system clock on my plc for daylight savings time so the operator does not need to adjust himself twice a...
Replies
1
Views
2,410
Back
Top Bottom