Beauchamp355
Hello everyone!
 
I'm working on a P1AM project for school and need to activate some outputs based on the time of day. I'm having trouble getting the RTC time to show correctly. I've got some experience and schooling for PLC, but very little with programming or Arduino in general.
 
So far I've tried using the RTC block, and noticed that it starts at "1970: 00:00: etc etc" and continues to count while using the simulator (I understand this to be expected based on other posts made). The rest of my program works correctly in the simulator, as I can change the on and off times and see that they work as expected.
 
At the moment I do not have a way to monitor my PLC memory locations, but it appears that the RTC is NOT being updated with my PC's current time during upload. As in it seems the RTC block starts at "1970: 00:00 etc etc" when uploaded to the P1AM. I can see that the RTC block counter and the output are indeed operating, as my output changes to ON after several hours (I haven't caught it in person, but I assume it is turning on after 8 hours as I have my on time set to TOD#8:00:00.00000.
 
I've tried moving the time values from %ML1024 into another %ML location using:
[RTCTime (ULINT @%ML1024)] -[ULINT_to_TOD] - [MOVE] - [Time (TOD)]
 
As well as using the RTC function block:
[RTC Block - CDT] - [DT to TOD] - [Time var]
or
[RTC Block - CDT] - [DT to Time/Real/LReal/Word] -[MOVE] - [Time var @%ML1]
or
[RTC Block - CDT] - [DT to TOD] - [Greater/Equal TOD#8:00......]
 
Is there something in the above examples I can change to make this work with the P1AM, or do I need to create a new driver/function block?
 
I have found that the P1AM utilizes the RTCZero.h Library when using the Arduino IDE software, could someone give me some tips on how to implement that library if OpenPLC does not currently support P1AM RTC? I've struggled to find where to move the .h and .cpp files, as well as what scripts will need to edited so they call out the RTCZero files. I expect to need other drivers/libraries, so I would really appreciate tips on this regardless.
 
I am working on a windows PC fyi, and hope to implement Modbus communication down the road.
 
Thanks in advance!
Reply 0 0
thiagoralves
 
The RTC block that comes with OpenPLC is generic and has no means to read from a hardware RTC device. Reading from the P1AM internal RTC was not implemented and would require some fiddling around with the code. In any case, as stated in the Arduino RTC page: "Every time the board is powered, the RTC is reset and starts from a standard date. To keep the time and the RTC running it is necessary to keep the board powered". ( https://www.arduino.cc/reference/en/libraries/rtczero/ 😉. Even if you find a way to read from the internal RTC, it will always be reset when the device is powered off.
 
Perhaps a good strategy to have an internal RTC running would be to set up current date and time from Modbus registers. You can define, for example:
%QW0 = year
%QW1 = month
%QW2 = day
%QW3 = hour
%QW4 = minute
%QW5 = second
 
All these values are simple integers (INT) that can be defined and stored in Modbus registers (holding registers 0 to 5). Once the board is powered on, you can use a Modbus tool (like the free Radzio Modbus) or an HMI to set the correct values for %QW0 - %QW5 according to the current time. Then, using some programming you can assemble a DT variable composed of all these components and feed that to the input of the RTC block at the press of a button for example. This will synchronize the time with current time coming from an HMI (or any Modbus tool) and your board will keep running with the correct time until it is powered off.
Reply 1 0
Reply