MVP 2023 Flex727 Posted May 4, 2022 MVP 2023 Report Share Posted May 4, 2022 Anyone have a bullet-proof solution to activating a positive transition contact exactly once per week (using VisiLogic)? This needs to be able to deal with undetermined power-off situations. Every solution I come up with has a flaw that can occur if the machine is powered off multiple times during the week or is only powered on the last day of the week. This solution fails if the PLC is powered on at any point during the week after midnight on Sunday. Adding an inverted contact of SB 2 allows the logic to work if the PLC is powered on at any time on Sunday, but will fail if the PLC is power cycled during the day on Sunday and will still fail if the PLC remains off on Sunday. Changing the comparison to >= will cause the logic to fail if the PLC remains powered on continuously. Every solution that is more complicated still requires the PLC to know that a new week has begun (set & reset bits, etc). Anyone have an answer? Link to comment Share on other sites More sharing options...
MVP 2023 kratmel Posted May 4, 2022 MVP 2023 Report Share Posted May 4, 2022 Please clarify the task. Should the event be run during the day (or at a specific time) on a specific day of the week? Does the event have to take place the next day if this programmed day (days) has passed but the PLC has been switched off? Should the event fire once if the PLC was turned off several times during the selected day? Perhaps a few more conditions need to be clarified. I think in the Visilogic Help example V350_Week_of_the_Year_Calculation.vlp it is a good idea to use the even and odd weeks of the year as a reason to change the bit you need at the beginning of the week. Although perhaps my assumption is wrong. There may be a problem with the New Year's transition. Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted May 4, 2022 Author MVP 2023 Report Share Posted May 4, 2022 3 hours ago, kratmel said: Should the event be run during the day (or at a specific time) on a specific day of the week? Nope, once per week at the beginning of the week, or as soon as the PLC is powered on if it was powered off at midnight on Sunday. But only once per week. 3 hours ago, kratmel said: Does the event have to take place the next day if this programmed day (days) has passed but the PLC has been switched off? Yes. 3 hours ago, kratmel said: Should the event fire once if the PLC was turned off several times during the selected day? Yes, exactly once per week. 3 hours ago, kratmel said: I think in the Visilogic Help example V350_Week_of_the_Year_Calculation.vlp it is a good idea to use the even and odd weeks of the year as a reason to change the bit you need at the beginning of the week. Good suggestion - I'll check that out. Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted May 4, 2022 Author MVP 2023 Report Share Posted May 4, 2022 3 hours ago, kratmel said: Please clarify the task. And to further clarify, the customer wants a .csv data file to be saved on the SD card. They want one data file per week stored with the file name itself formatted as YYMMMDD. The file is created on the first day of the week and then data is added to the file periodically during the week. A new file should be created for each new week. One, and only one, file per week. It's not the end of the world if the routine has a flaw, as no data would be actually lost, but I'd just like to get it right. The positive transition contact would create the .csv file along with a header row in the file. Subsequent data during the week will be added to the file. Link to comment Share on other sites More sharing options...
MVP 2023 kratmel Posted May 4, 2022 MVP 2023 Report Share Posted May 4, 2022 1 hour ago, Flex727 said: The positive transition contact would create the .csv file along with a header row in the file. Subsequent data during the week will be added to the file. Accordingly, if you specify the week number in the year, the file will appear when the week number is changed. That is, the week number can be used to identify two or more consecutive weeks, even if the PLC does not turn on for a week, a month or more. Link to comment Share on other sites More sharing options...
MVP 2023 Ausman Posted May 4, 2022 MVP 2023 Report Share Posted May 4, 2022 I might have my interpretation wrong, but what about using a count system? Any time the unit is powered on but the trigger is not wanted, the count does a +1. On any new boot, the count is compared to the desired day for things to happen, and when that rolls around or has been passed, the count resets to 0 which triggers the desired actions, sets a lockout so that it doesn't happen again on that day, and then adds +1 after everything has happened correctly, ready for the next time period to start. I haven't put this into a ladder, this is just the brain's initial train of thought and I wrote it a bit disjointed...but I don't think it would actually be too hard to ladderise. Did you all love my new word? I think I'll trademark it. On second thoughts, I'll donate it to the forum and we can all use it as needed. Ladderise is now official! 🙂 cheers, Aus Link to comment Share on other sites More sharing options...
MVP 2023 kratmel Posted May 5, 2022 MVP 2023 Report Share Posted May 5, 2022 3 hours ago, Ausman said: Ladderise (Ausman TM) An interesting idea of a new word, and as always in mind games, the word means that we visually represent the text of the PLC program from top to bottom. Did I understand correctly what it means - to program in the ladder language or to turn thoughts into a ladder? But I like it. Link to comment Share on other sites More sharing options...
MVP 2023 Ausman Posted May 5, 2022 MVP 2023 Report Share Posted May 5, 2022 I think the context was: translate ideas on how to do something into actual ladder that works as desired. To cover your other meaning, I think I'll make another new word which is: ladderage.....programming in ladder language. The two are probably intertwined, but hey, so are lots of other words. But at least these two DO have a slightly different meaning. cheers, Aus Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted May 5, 2022 Author MVP 2023 Report Share Posted May 5, 2022 15 hours ago, Ausman said: I might have my interpretation wrong, but what about using a count system? Any time the unit is powered on but the trigger is not wanted, the count does a +1. On any new boot, the count is compared to the desired day for things to happen, and when that rolls around or has been passed, the count resets to 0 which triggers the desired actions, sets a lockout so that it doesn't happen again on that day, and then adds +1 after everything has happened correctly, ready for the next time period to start. I'm missing something because I don't see how this would work. You might need to ladderize it for me to understand. 😉 Link to comment Share on other sites More sharing options...
MVP 2023 kratmel Posted May 5, 2022 MVP 2023 Report Share Posted May 5, 2022 Analyzing your proposed new terms, I will try to logically continue the idea and add a new term - Ladderart. Small tree (ladderrise) - should be cared for and watered. Mature tree (ladderage) - self-sufficient and fruitful. A product of art made of wood (ladderart) is something that will not change for a long time and will benefit everyone who looks at it. Probably a little too much philosophy ... But here on the forum I have already met many examples of compact, balanced and self-sufficient code in the Ladder language - Ladderart. Please correct me if I do not understand modern terminology enough. Link to comment Share on other sites More sharing options...
MVP 2023 kratmel Posted May 5, 2022 MVP 2023 Report Share Posted May 5, 2022 3 minutes ago, Flex727 said: I'm missing something because I don't see how this would work. I also think so. The solution of the problem set in the topic does not lie in the plane of programming, but in the plane of error-free recognition the moment of week change in case of random disturbances. Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted May 5, 2022 Author MVP 2023 Report Share Posted May 5, 2022 3 minutes ago, kratmel said: The solution of the problem set in the topic does not lie in the plane of programming, but in the plane of error-free recognition the moment of week change in case of random disturbances. This is exactly right. I assumed there was a known, and perhaps easy, solution to this problem. I wish there was, but I'm somewhat gratified that I wasn't overlooking something obvious. I think I'll add some user input that will allow the user to select day and time for the beginning of the new week so the PLC will most likely be powered on (or that they would know when it definitely should be powered on). Link to comment Share on other sites More sharing options...
MVP 2023 Ausman Posted May 5, 2022 MVP 2023 Report Share Posted May 5, 2022 I'll work on this when I have a little time. Don't add the user input just yet. And just for the record again, is the desired day for the trigger Sunday or Monday? And I'm still assuming the action needs to be done right after power-up, if the trigger day is current or has gone past? So Joe's state machine is Ladderart, eh? Whereas my initial work on this will be ladderise, eventually turn into ladderage, and will perhaps finally become ladderart! Ohhhhh....what have I started! cheers, Aus Link to comment Share on other sites More sharing options...
Gabriel Franco Posted May 5, 2022 Report Share Posted May 5, 2022 ¿have you tried DAY OF WEEK function? Link to comment Share on other sites More sharing options...
MVP 2023 kratmel Posted May 6, 2022 MVP 2023 Report Share Posted May 6, 2022 9 hours ago, Ausman said: So Joe's state machine is Ladderart, eh? State machines were probably known before the invention of the PLC. Thanks to Joe, this work of programming art has become a good tool for solving many typical PLC programming problems. At the same time, I think that an example of LadderArt is a piece of code presented by Joe in this topic It doesn't matter who the author of this code is. Its simplicity, self-sufficiency and usefulness for forum users are important. Flex formulated a good task, it interested me and probably many users of the forum. Apparently, the solution to this problem can also become a work of art, regardless of who finds this solution. Link to comment Share on other sites More sharing options...
MVP 2023 Ausman Posted May 6, 2022 MVP 2023 Report Share Posted May 6, 2022 14 hours ago, Ausman said: is the desired day for the trigger Sunday or Monday? forgot you'd answered Kratmel's questions with this detail. After initial thoughts evolve, I place them in the brain tumble drier and let them roll around a fair bit before ladderising, in the hope that it all comes out a bit better. Unfortunately at the moment there are a million other pieces of "clothing" in with it. But I will try to do an example sometime soon. cheers, Aus Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted May 6, 2022 Author MVP 2023 Report Share Posted May 6, 2022 14 hours ago, Ausman said: And just for the record again, is the desired day for the trigger Sunday or Monday? Customer hasn't specified. I already added an HMI selection for choosing their preferred day. 14 hours ago, Gabriel Franco said: ¿have you tried DAY OF WEEK function? I'm actually using SI 34, which is functionally the same. 4 hours ago, kratmel said: Flex formulated a good task, it interested me and probably many users of the forum. Apparently, the solution to this problem can also become a work of art, regardless of who finds this solution. I think I've said this before, when @Joe Tauser introduced me (us) to the State Machine, it literally changed my life. The utility of that simple procedure is indescribable. 13 minutes ago, Ausman said: After initial thoughts evolve, I place them in the brain tumble drier and let them roll around a fair bit before ladderising, in the hope that it all comes out a bit better. You are definitely one of the best ladderizers I know. 🙃 Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted May 6, 2022 Author MVP 2023 Report Share Posted May 6, 2022 Oh, and since I create a file with that event, I decided to try using the SD Info FB to check for the existence of the file to at least solve half the problem (preventing a second event from occurring during the week). However, there seem to be problems with this function (see my post in the VisiLogic forum). Basically, if the file does NOT exist, there is no way to know when the FB has finished its task (Success Bit never turns on). Link to comment Share on other sites More sharing options...
MVP 2023 Ausman Posted May 6, 2022 MVP 2023 Report Share Posted May 6, 2022 In quickly reviewing the desired parameters again, it has occurred to me that you could have a screen that pops up first on boot, but is only week related and ASKS if they want to do the save as they haven't done so yet. If the save is done via this screen, it doesn't appear until the next week rolls around. Link to comment Share on other sites More sharing options...
MVP 2023 Ausman Posted May 6, 2022 MVP 2023 Report Share Posted May 6, 2022 and a PS to the above, of course my brain has obviously been pondering this overnight, for such a thought to occur. Thank you so much Flex. 🙂 Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted May 7, 2022 Author MVP 2023 Report Share Posted May 7, 2022 1 hour ago, Ausman said: In quickly reviewing the desired parameters again, it has occurred to me that you could have a screen that pops up first on boot, but is only week related and ASKS if they want to do the save as they haven't done so yet. If the save is done via this screen, it doesn't appear until the next week rolls around. This requires the same solution as the original problem. If I could make a screen pop up once and only once per week, then I could do the other thing that I'm trying to do with the same algorithm. Link to comment Share on other sites More sharing options...
MVP 2023 kratmel Posted May 7, 2022 MVP 2023 Report Share Posted May 7, 2022 So I will try to describe in words the algorithm for solving your problem, which in my opinion should work. Therefore, the first power-up of the PLC prompts the user to determine the start date of the weekly reports (it can be started in setup). After selecting the date and time, the user says OK. Further from this date, the PLC builds a Data Table of UTC-generated weekly readings (add 24*7*3600=604800s for the next week start) for the required max operating time. (After this max time log is stopped and user must define new period). After that, we compare >= the RTC to UTC with the next Data Table week start UTC countdown and set START Pulse for the log file create and start update week events if needed. At the same time START Pulse increment a row of the Data Table, rewrite to UTC variable the following consecutive next week countdown and PLC wait for it (Then START Pulse is disabled) . When you turn off and on the PLC, for example, in three weeks later PLC will have generated three empty files and wait for the beginning of the next working week and start append some info to the last created file. It may not be a perfect solution, but it is not afraid to turn off the PLC because it works on the condition that it is between fixed UTC readings compared with RTC. I will try to ladderize it on the weekend.. Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted May 7, 2022 Author MVP 2023 Report Share Posted May 7, 2022 Amazing work, @kratmel! I think that would work. And it's not overly complicated. Link to comment Share on other sites More sharing options...
MVP 2023 Ausman Posted May 7, 2022 MVP 2023 Report Share Posted May 7, 2022 I am a bit grumpy this morning. 🙂 Kratmel is describing close to one of my solutions that I have been working on for quite a few hours since I last wrote, especially last night. It now being Mothers Day here, I am not able to continue, but I will post the solution soon. I'm using the UTC a bit differently, but know it's going to work perfectly. It doesn't use data tables. so Kratmel, and Flex, perhaps don't bother at present as I'm a long way along the path already. If you don't like my version, then you can play with yours! cheers, Aus 1 Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted May 8, 2022 Author MVP 2023 Report Share Posted May 8, 2022 @Ausman 👍 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now