Greetings to all forum users! I'm a newcomer here, seeking guidance on using Unity Pro software alongside PLC M340 modules. I've discovered that %SW values are in hexadecimal format, such as %SW51 representing the system clock time of 7:30AM or 16#730. Can BCD_TO_INT be used to convert hexadecimal to decimal in this scenario? If not, I'm open to exploring other solutions. Your prompt response would be greatly appreciated. Many thanks, Nemic.
Nemic inquired about converting hexadecimal to decimal in Unity Pro software using PLC M340 modules. %SW variables in Unity Pro are in hexadecimal, such as %SW51 representing the system clock at 7:30 AM or 16#730. Nemic was curious if BCD_TO_INT conversion can be used to convert hexadecimal to decimal. If not, what other options are available for conversion? Lare advised setting bit %S50 before updating the system time in %SW49-%SW53 using INT_TO_BCD conversion. To read the time from system words, it was suggested to first perform BCD to integer conversion with BCD_TO_INT. Your thoughts on this matter would be greatly appreciated. Thank you, Nemic.
Lare asked if you have read the second post on a specific topic. Hi Lare, I understand that %sw51 is in hexadecimal format, but I want to confirm. Can you point me towards a function block that can help me convert hex to decimal? Thanks, Nemic.
Take another look at post #2 for information on converting BCD to integer values.
V0N_hydro recommended re-reading post #2 for converting BCD to integer. Because I don't have Unity Pro software available, I would appreciate a visual confirmation. Please review the attached file and confirm if my logic is accurate. Your assistance is greatly appreciated. Thank you, Nemic.
The BCD to INT block will not produce that particular outcome.
V0N_hydro pointed out that the BCD to INT block may not provide the desired result. This is a challenge I am currently addressing - finding a way to efficiently convert hexadecimal numbers to decimal numbers sourced from %SW51 in PLC programming.
Hello Nemic, could you provide some details on the issues you're facing with the BCD to INT block? I recommend researching BCD and gaining a clear understanding of its functionality. Feel free to share your program and explain the desired outcome as well as any observed discrepancies.
In response to V0N_hydro's question about the BCD to INT block not functioning correctly, Nemic suggests familiarizing oneself with BCD and its operational principles. If possible, sharing the program for review and expressing what is expected versus what is happening can also be helpful. While Nemic does not currently have access to Unity Pro to troubleshoot, alternative solutions are being explored. The attached files are theoretical in nature and not indicative of actual results. SW, which stands for "System Word", poses uncertainty regarding its data type.
The hexadecimal representation of the time 7:30 AM is 16#0730 or 1840 as an integer. When converted using BCD_to_INT, it becomes 730. It is important to note that SW51 should only read values from 0000 to 2359 in hex or 0 to 9049 as an integer, not 2DA.
The user V0N_hydro pointed out that at 7:30 AM, the %SW51 value would be 0000 0111 0011 0000, which translates to 16#0730 or 1840 as an integer. When this is passed through the BCD_to_INT function, the result is 730 in an integer format. It seems there may have been confusion about the value 2DA, but SW51 should only be reading values from 0000 to 2359 in hexadecimal or 0 to 9049 as an integer. This indicates that the BCD_to_INT block is functioning correctly, and the issue may lie with the hexadecimal value in the initial attachment file.
Please find below a screenshot extracted from the user manual.
Greetings once again! I want to express my gratitude for the assistance you offered me in addressing a previous issue a few months ago. Now, I am facing a new challenge involving synchronizing the clocks on two M340 devices connected via Ethernet. The dilemma lies in the lack of internet access, rendering the R_NTPC function ineffective. Is there a method to designate one of the PLCs as an NTP server to facilitate the use of the block? While I am skeptical about its feasibility, another alternative would involve utilizing READ_VAR/WRITE_VAR and developing the code from scratch, although this approach would be time-consuming. Do you have any suggestions or creative solutions for this predicament? Your insights are greatly appreciated.
Is it possible to transfer computer time to %MW-area using SCADA or another method? Afterwards, can this time be periodically transferred to system words on the PLC? For data exchange between two PLCs, IO scanning or Global Data setup can be utilized. Additionally, a system registry tweak for NTP may be available, although personal experience with it is limited. Visit the Siemens website for more information on this topic: http://support.automation.siemens.c...lib.csinfo&lang=en&objid=22144502&caller=view.
Are there any computers on your network that can function as an NTP server? If so, you can utilize the NTP service on the Ethernet port. In Unity 8, you have the option to configure the PLC as an NTP server, although it may only be compatible with the new M580 model.
Do you happen to have a NOE ethernet card or an M340 with an embedded ethernet port on a rack? The M340 with built-in ethernet lacks NTP functionality, but NOE cards typically offer this feature, if my memory serves me correctly.
I currently have an M340 with integrated Ethernet capabilities, but it seems that I cannot utilize the NTP function or IO scanning for simplicity. As a workaround, I will need to periodically retrieve data using the READ_VAR function. While I could potentially use SCADA software like Vijeo Citect to facilitate data transfer, I am unsure of its reliability. I prefer relying on the PLC for timekeeping over the computer due to its greater trustworthiness. (the PLC communicates the time to the SCADA system)
One useful feature in Citect is the ability to synchronize time with an NTP server, providing an alternative time sync option. This feature typically operates as a service on your computer. If you are interested in setting this up, you can refer to the Citect help documentation. If you are unable to locate the information, feel free to reach out to us for assistance.
In the comment by V0N_hydro, it was mentioned that at 7:30 AM, the value of %SW51 should be 16#0730 or 1840 as an integer. When this value is passed through BCD_to_INT, it will result in 730 as an integer. It is unclear where the value of 2DA is coming from, as SW51 should only read values ranging from 0000 to 2359 in hex or 0 to 9049 as an integer.
I have a quick question - how can I reset the bit %S50 to 0? Currently, %SW51 is displaying as 0. I would appreciate a prompt response to this inquiry. Thank you, Nemic.
Nemic asked for assistance: "How can I reset bit %S50 to 0 when %SW51 is currently displaying 0?" Please offer your response promptly. Thank you, Nemic.
To achieve this, follow these steps:
1. Adjust bit %S50 to 1 using a block with an enable pin.
2. Input a BCD value of 0 to %SW50 (remember, both integer 0 and BCD 0 are the same), using either a move block or an int_to_bcd block.
3. Reset bit %S50 using a reset block with an enable pin.
Apply the same process for all other clock words, ensuring to convert integer values to BCD format before moving to %SW50-54 in the system word.
In order to properly set up the clock, follow these steps as instructed by Lare:
1. Activate bit %S50 to 1 using either the show enable pin block or by moving a block with a specific bit variable.
2. Input a BCD value of 0 into %SW50. (Note that both integer 0 and BCD 0 are equivalent, allowing you to utilize either the move or int_to_bcd block).
3. Deactivate bit %S50 using the reset block with the show enable pin.
Ensure the same process is followed for all other clock settings, but remember to convert integer values to BCD format before transferring them to %SW50-54 system word. What type of block is needed for this process, Lare?
Does it resemble something similar to this?
To reset or set the %S50 bit in Unity PLC, it must be on the output side with a connection to something else on the input pin. The PLC clock operates when the %S50 bit is zero, allowing for adjusting the time. When the %S50 bit is set to "1," the new time is used at the transition from "1" to "0." Use set and reset blocks if you want to use different buttons or bits to set the %S50 bit. If the same variable is used for setting and resetting the %S50 bit, a move block can be utilized. It is also necessary to adjust the years, days, and months, not just the seconds, hours, and minutes as shown in the example.
In setting up the clock in Unity PLC, it is essential to reset or set the %S50 bit accordingly. The %S50 bit needs to be on the output side, with something else connected to the input pin. The clock in Unity PLC operates when the %S50 bit is at zero, allowing for adjustments to the time. When the %S50 bit is at "1," the new time is utilized during the transition from "1" to "0." To adjust the %S50 bit using different buttons or bits, utilize set and reset blocks. Alternatively, if the same variable is used for both setting and resetting the %S50 bit, the move block can be employed. It is also necessary to adjust the years, days, and months in addition to seconds, hours, and minutes. When considering the set_clock function in Unity PLC, its capabilities and functions are truly remarkable.
The variable type can be either bit, bool, or ebool. It is recommended to use ebool variables for easier manipulation of bits through panel or SCADA systems, in addition to programming devices. To set the clock, you can conveniently use a programming computer online through the PLC rack viewer, PLC card, and animation feature. However, if you prefer changing it without a programming device, a bit of code must be written. When reading/writing bit examples from panel variables, %M addresses are typically used and can only be assigned to ebool type variables. For integers, %MW addresses and int type variables are required.
In the Unity PLC system, the clock runs based on the %S50 bit being either reset or set. When the %S50 bit is zero, the clock runs and the time can be adjusted. The new time is activated when the %S50 bit transitions from "1" to "0". To set the %S50 bit with different buttons or bits, use set and reset blocks. If the same variable is used for setting and resetting the %S50 bit, a move block can be utilized. Additionally, adjustments should be made for years, days, and months, not just seconds, hours, and minutes. If the system displays zeros in the system words, it may be necessary to add more function blocks.
When system words display zeros, does that mean more function blocks need to be added? To troubleshoot this issue, check the PLC time first from the rack viewer. It's common for the clock to have odd time values on initial boot-up when the clock isn't running. In situations like this, initial time values need to be inputted from the PLC card animation viewer to correct the clock's error state. Once the correct time is set and the clock is running, adjustments can be made via system words. It's worth noting that the clock may only be in error state a few times when programming a new PLC. If incorrect time values, like a month value of 14, are inputted, the clock won't be adjusted and the previous time will remain in use. Don't forget to check if the PLC is in run state.
To ensure proper functionality of the PLC, it is important to first check the time in the rack viewer. Sometimes, the clock may display incorrect values when the PLC is initially booted up and the clock is not running. In such cases, you may not be able to modify these values using system words. In this scenario, it is recommended to input the correct time values from the PLC card animation viewer to rectify the error state of the clock. Once the correct time is set and the clock is running, adjustments can then be made using system words. It has been observed that the clock only encounters errors a few times when programming a new PLC. Additionally, if an incorrect time value, such as a month value of 14, is entered, the clock will not be adjusted and the previous time will still be in use. It is also important to ensure that the PLC is in a run state. If you are unsure where to find the rack viewer, you can locate it within the project settings where the diagnostics information is already enabled.
I'm not saying that. Follow these steps: double-click on the configuration folder in the project tree, then double-click on the PLC card to access the animation and proceed to the animation sheet. Look for the PLC time on the left side - is the clock running? Can you share a screenshot of post 32 without animations activated or the entire zipped program in *.sta format (Unity file)?
During a project in Unity, locate the configuration folder in the project tree and double click on the PLC card. Navigate to the animation sheet where you will find the PLC time on the left side. Check to see if the clock is running and take a screenshot of post 32 without animations enabled or provide the whole zipped program in Unity file format (*.sta). Ensure to include this in your response. View the provided screenshot below. Click to expand and learn more.
Today, I had the task of reading and setting the M340 real-time clock (RTC). I successfully wrote and executed this code and wanted to share it here in hopes of assisting others. In the ST code snippet below, I have included instructions for both reading and writing the RTC data.
To read the RTC data, use the following code:
```
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;
```
To write new RTC data, use the following code:
```
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;
```
Additionally, I have included comments in the code to explain the purpose of each variable and the conditions for reading and writing the RTC data. Remember, when UNLOCK is set to 1, the RTC variables stop updating and new data can be written. When UNLOCK changes back to 0, the PLC will receive the new data and continue counting. Let me know if you find this helpful!
I am experiencing an issue with %S50 not staying updated after it reverts back from 1 to 0. I am in the process of setting up time syncing on an M340 and have carefully followed your insightful guidance. During runtime, I can observe the remote time sync values being successfully inserted into %SW49-53 while %S50 is set to 1. However, once %S50 is changed back to 0, the PLC clock overrides %SW49-53. This means that I am only able to view the manually inputted time sync values in %SW49-53 when %S50 is set to 1. According to my knowledge and the resources provided in the Modicon Help Section, resetting %S50 back to 0 should retain the inputted values and continue counting from that point. The current situation is perplexing and I am seeking assistance to resolve this issue. Any help would be greatly appreciated as this situation is quite puzzling to me. Thank you for your support.
- 09-11-2024
- MementoMorified
Welcome to the forum! Are you using a new PLC brand? The Unity clock may initially display the wrong time, which can happen if the clock is not set correctly when the PLC is new. To fix this issue, double click on the PLC online, go to the animation sheet, and find the clock or real-time clock settings. Adjust the time using your computer to ensure accuracy. Once the time is correct, you should be able to input new values using system words.
Hello everyone! I'm looking for guidance on how to extract hours, minutes, and seconds in the format of DD/MM/YYYY using M340 UNITYPRO. I would appreciate some detailed explanation on how to use rotate right and rotate left functions to separate hours, minutes, and seconds.
Hello Mr. Ferj Rodrigues, I want to express my gratitude for your help. Your advice has been extremely beneficial to me, and I found it to be straightforward and easy to implement. Instead of using traditional methods, I followed your logic and opted for a Facebook group (fbd) approach. Thank you for your valuable assistance.
In response to Mr. Ferjrodrigues, KAYANTHIRI expressed gratitude for the helpful advice provided. Utilizing the convenient method of sending files via email, KAYANTHIRI found it simple and effective. Using the abbreviation "ST" makes it easy to share files quickly and effortlessly.
ferjrodrigues noted the convenience of using ST for sharing information, as it can be easily copied and pasted into an email. This simplicity makes ST a valuable tool for communication.
Hello, Today I had the task of reading and setting the M340 real-time clock (RTC). I successfully wrote this code and it's working perfectly. I wanted to share it here in case it can help someone else. In ST language, the code is as follows:
(*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;
In summary, when UNLOCK is set to 0, the data is read from the RTC. When UNLOCK is set to 1, the variables are stopped from being updated, and the new data is written to the RTC. When UNLOCK changes back to 0, the PLC receives the new data and continues to count. Thank you for sharing this helpful code!
In "Simulation Mode," I am unable to input any changes to system words while ensuring the accurate value is maintained. Thank you for your understanding.
Having trouble with %S50 being set while %SW50-52 keep fluctuating? Lare suggests utilizing system bit %S50 and words %SW49-%SW53 for this task. To update the time, first set %S50 and then copy the new time to system words %SW49-%SW53 after converting it from integer to BCD. Remember to set bit %S50 to "0" to update the time to RTC. To isolate hours and minutes, consider using Rotate right and left instructions. While it may not be the simplest method, it is achievable. For retrieving the time from system words, perform BCD to integer conversion first, followed by rotate left/right instructions. Still puzzled? You set %S50, but %SW50-52 are constantly changing. Shouldn't they be 'disconnected' from the system to allow changes?
I may be a little behind, but here is the code snippet I utilized for the M340 model. Please note that this code snippet was not authored by me; it is primarily sourced from Schneider.
Code snippet:
(* 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 there were changes in time/date set words, then set the 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 there are no changes in set words, update them to the clock values *)
(IF %S50 THEN RESET(%S50);
END_IF;
END_IF;
Hour_memory_6 := Hours_6; (* set memory words to detect any changes in the next scan *)
(* used in the HMI to check if the PLC is in run mode *)
plc_second2 := BCD_TO_INT(%SW50 / 256); (* seconds *)
ferjrodrigues shared a code snippet for reading and setting the M340 RTC. By using the code provided in Structured Text (ST), the RTC values can be efficiently managed. This solution can be beneficial for those seeking assistance with RTC manipulation. The code includes sections for reading and writing RTC data based on the value of the UNLOCK variable. When UNLOCK is set to 0, the code reads the RTC values, while setting UNLOCK to 1 stops the updating of RTC variables and writes new data. This ensures precise control over the RTC values. Additionally, the code snippet includes comments for clarity and ease of understanding. Thank you, ferjrodrigues, for sharing this valuable code snippet!