7/10/2017 5:19 PM | |
Joined: 7/7/2010 Last visit: 6/19/2024 Posts: 14822 Rating:
|
There are many ways to perform this count function. You can access the DB using the PEEK command and loop through the DB a word at a time (since even optimized DBs are set up on word boundaries). I sketched it up if you want to see. It is not perfect nor tested, but it does compile against a S7-1517-3 v1.8 using Portal V13 SP1. It uses BITSUM() after PEEK_WORD is called, then sums up a word at a time until the peek goes beyond the DB's bounds. Local error handling is required to do this.
AttachmentDB_Bit_Counting.zip (279 Downloads) |
science guy |
|
This contribution was helpful to
1 thankful Users |
7/10/2017 8:39 PM | |
Joined: 3/14/2016 Last visit: 8/11/2023 Posts: 162 Rating:
|
I believe the best option is to use a FB with your Booleans Struct and use AT overlay to do the BITSUM. I don't have a 1x00 CPU here, only a ET200S 151-8, so I tested on a 1511 with the PLCSIM. The scan time stayed around 1~5ms. If using a FB to create your DB area fits your application, then the AT will be a good idea, since you can use the FB to simple calculate the BITSUM and deliver it on an Output or get the variable on the static area.Just remember to use in the "Retain" column "Set in IDB" as it's recommended on the User Guide Code for simple FB attached. PS: I never use optimized DB, the lack of a proper pointing to the variables is just unacceptable. AttachmentFB_128Bools.zip (130 Downloads) |
"Engineers like to solve problems. If there are no problems handily available, they will create their own problems." (Scott Adams) |
|
This contribution was helpful to
2 thankful Users |