System Clock PLC M340 - Unity Pro

%S50 set but %SW50-52 keep changing

You have to use system bit %S50 and words %SW49-%SW53 for this.

When you want change time, set bit %S50 first, then copy new time to system words %SW49-%SW53. (Use integer to BCD conversion before copy) and set bit %S50 to "0" for updating time to RTC.

To get hours and minutes separate, you can use Rotate right and left instructions. Not easiest way, but it is possible ;)

For reading time from system words, use first BCD to integer conversion and then rotate left/right instructions.

Probably misunderstanding something. I set %S50, but the registers %SW50-52 keep changing. Should they not 'disconnect' from the system so I can change them?
- confused
 
I'm late to the party, but this is what I used for the M340.
Disclaimer: I did not write this. It came mostly from Schneider.
Code:
(*
RTC_Compare:= EQUAL_ARINT(Hours_6,Hour_memory_6);*)
(*EQUAL_ARINT(Hours_6,Hour_memory_6) > -1*)
IF  (*(RTC_Compare > -1) or *)hmi_set_clock THEN (*if time/date set words were changed, then set clock*)

SET(%S50);

%SW50 := INT_TO_BCD(Hours_6[2] * 100);(*seconds*)
%SW51 := INT_TO_BCD((Hours_6[0] * 100) + Hours_6[1]);(*hours and minutes*)
%SW52 := INT_TO_BCD((Hours_6[3] * 100) + Hours_6[4]);(*month and day*)
%SW53 := INT_TO_BCD(Hours_6[5]);(*year*)

hmi_set_clock:= 0;

ELSE (*if no change in set words, just update them to the clock values*)
(*display hh mm ss mm dd yyyy MW2161-MW2166 *)
(*
Hours_6[0] := BCD_TO_INT(%SW51 / 256);(*hours*)
Hours_6[1] := BCD_TO_INT(%SW51 MOD 256);(*minutes*)
Hours_6[2] := BCD_TO_INT(%SW50 / 256);(*seconds*)
Hours_6[3] := BCD_TO_INT(%SW52 / 256);(*month*)
Hours_6[4] := BCD_TO_INT(%SW52 MOD 256);(*day*)
Hours_6[5] := BCD_TO_INT(%SW53);(*year*)
*)


	IF (%S50) THEN
		RESET(%S50);
		
	END_IF;

END_IF;

Hour_memory_6 := Hours_6 ;(*set memory words to detect any change next scan*)




(*used in the hmi to see if the plc is in run*)
plc_second2 := BCD_TO_INT(%SW50 / 256);(*seconds*)
 

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,427
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,303
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
502
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
515
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,422
Back
Top Bottom