Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: PLCwannabe on July 25, 2019, 01:22:12 PM
-
Looking for a way to set up ambient temperature tracking with BRX Plc. Basically, I need to compare a current temperature to what the temp was an hour ago or 2 or 3 hours ago. I need to keep doing this comparison constantly at least once per minute. I know there has to be a simple way to do this, but so far it has escaped my imagination. I would really appreciate any suggestions if anyone has done this before. Thanks.
-
Create an array to store the historical temp records. You can either push them onto the front end, which would require moving all the values every time you add one, or round robin the index. I'd do the second option, which not only doesn't make you move all the values every time, but also gives you some cool indexing options. There are 1440 minutes in one day, so you could make a 1440 element array and you'd have all the values for the last 24 hours, which would require math to translate current or desired time into array index. Or, if you have the memory to blow, you could create a 2359 element array, then the current military time, 1433 or whatever, becomes the array index directly. This method seems cleaner, but wastes memory and the unused array elements would also need to be accounted for if you do bulk math on the array, like take an average over a time period.
-
Create an array to store the historical temp records. You can either push them onto the front end, which would require moving all the values every time you add one, or round robin the index. I'd do the second option, which not only doesn't make you move all the values every time, but also gives you some cool indexing options. There are 1440 minutes in one day, so you could make a 1440 element array and you'd have all the values for the last 24 hours, which would require math to translate current or desired time into array index. Or, if you have the memory to blow, you could create a 2359 element array, then the current military time, 1433 or whatever, becomes the array index directly. This method seems cleaner, but wastes memory and the unused array elements woulds also need to be accounted for if you do bulk math on the array, like take an average over a time period.
:whispers: "And we have a nifty FIFO instruction now."
-
Yeah, that works too, but I think LIFO/FIFO would shine better in a case where you're storing values on a variable demand as opposed to a schedule where you always know the index value. The reasons I'd prefer MATH here are:
- Like I said, index value always at hand, so no advantage for FIFO
- No instruction heap item required
- Implicit type conversion available if needed, plus scaling or other MATH ops
- As far as I know, FIFO will only store the data contiguously, so it wouldn't work with my preferred second option - for a 2359 element array and skip the registers where Index % 100 > 59.
-
Yeah, that works too, but I think LIFO/FIFO would shine better in a case where you're storing values on a variable demand as opposed to a schedule where you always know the index value. The reasons I'd prefer MATH here are:
- Like I said, index value always at hand, so no advantage for FIFO
- No instruction heap item required
- Implicit type conversion available if needed, plus scaling or other MATH ops
- As far as I know, FIFO will only store the data contiguously, so it wouldn't work with my preferred second option - for a 2359 element array and skip the registers where Index % 100 > 59.
That's fair.
-
You could easily log the data to the SD Card
-
Thanks for all the suggestions guys. For a beginner like me, the FIFO instructions are really easy to understand and will work really well for my application.However I would appreciate an example of ladder code for creating an array and how to round-robin the index.
-
Easy-peasy, especially since in this case the index round-robins itself. Assume the current temp is in RX0, you don't need the four digit time elsewhere in the program, and you want the history database temp records as floating point.
// Ver(103) PCU(3) Do-more Designer Clip Source Project: C:\Users\Public\Documents\Do-more\Designer2_6\Projects\Temperature Logging Format: Do-more Designer 2.00+ DO-MORE Ladder
PLC BX-DM1E-10AR3-D
STRDLT SDT0.Minute
MATH DST511 "RX0" "TempHistory[(100 * SDT0.Hour) + SDT0.Minute]"
#BEGIN MEM_CONFIG
TempHistory REAL decimal 2360
#END
#BEGIN ELEMENT_DOC
"RX0","CurrentTemp","","Current","Temperature"
#END
Then if you want to access, say, the temperature at 3:00pm, the syntax is just TempHistory[1500].