News:

  • October 02, 2026, 06:12:11 AM

Login with username, password and session length

Author Topic: Recording Max and Minimum Temp values.  (Read 19544 times)

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Recording Max and Minimum Temp values.
« on: August 27, 2019, 04:53:51 PM »
I need to record the minimum and maximum values of temperature for 50 different rooms for each day, and also record the time when this took place. Attached are a couple rungs of code that I am using for room 1 which seems to work well. However, to do this for all 50 rooms makes for a long task and a lot of find and replace. Any ideas for a simpler way to do this?

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3847
    • Host Engineering
Re: Recording Max and Minimum Temp values.
« Reply #1 on: August 27, 2019, 05:46:16 PM »
Utilizing arrays would make this easy.

Basically, set up 4 blocks of:
50 signed 16bit WORD values called MinTemp (instead of N)
50 signed 32bit DWORD values called MinTimeStamp (these will hold 1970 Epoch values)
50 signed 16bit WORD values called MaxTemp (instead of N)
50 signed 32bit DWORD values called MaxTimeStamp (these will hold 1970 Epoch values)

If your 50 temperatures are NOT in contiguous WX memory, e.g. WX1..WX50, then you will want to create another block
50 signed 16bit WORD values called CurrTemp, then in $tTopOfScan, create a COPY instruction that copies all of the 50 various WX values into the contiguous CurrTemp (say WX1 and WX5 are your first two temperature values):
COPY WX1 to CurrTemp0, WX5 to CurrTemp1, . . . WX123 to CurrTemp49
so now you have CurrTemp block of 50 values containing ALL of the current temperature values.

Create a subroutine called CalcMinMaxTemp that you CALL from $Main called every second on EDGE
STR ST4
CALL CalcMinMaxTemp

Then in CalcMinMaxTemp, set up a FOR/NEXT loop as follows:
FOR V0 0 to 49
STRLT CurrTemp[V0] < MinTemp[V0]
MOVE CurrTemp[V0] MinTemp[V0]
MOVE DST22 MinTimeStamp[V0]  // DST22 contains the local time as a 32 bit 1970 epoch value, the number of seconds since January 1, 1970

STRGT CurrTemp[V0] > MaxTemp[V0]
MOVE CurrTemp[V0] MaxTemp[V0]
MOVE DST22 MaxTimeStamp[V0]

NEXT



ATU

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 2126
  • YKPAIHA
    • ATU, Inc.
Re: Recording Max and Minimum Temp values.
« Reply #2 on: August 27, 2019, 06:56:54 PM »
You could also create a UDT with all those parameters in one  array. That would read really well.
Room[V0].MinTemp
Room[V0].MaxTemp
Room[V0].MinTimeStamp
Room[V0].MaxTimeStamp



franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3847
    • Host Engineering
Re: Recording Max and Minimum Temp values.
« Reply #3 on: August 27, 2019, 07:05:34 PM »
You could also create a UDT with all those parameters in one  array. That would read really well.
Room[V0].MinTemp
Room[V0].MaxTemp
Room[V0].MinTimeStamp
Room[V0].MaxTimeStamp

YES!

RoomStruct type
.MinTemp signed WORD
.MinTimeStamp signed DWORD
.MaxTemp signed WORD
.MaxTimeStamp signed DWORD

Room is a block of 50 RoomStruct User Data Types
You could even stick in the CurrTemp as a structure member if the WX's aren't contiguous, and do the COPY thing in $tTopOfScan or even $t1Second
COPY WX1 to Room0.CurrTemp, WX5 to Room1.CurrTemp, . . . WX123 Room49.CurrTemp  // 50 of these in the COPY instruction, copying the various WX registers to the corresponding RoomN.CurrTemp member, where N is 0..49

ATU

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 2126
  • YKPAIHA
    • ATU, Inc.
Re: Recording Max and Minimum Temp values.
« Reply #4 on: August 27, 2019, 08:26:13 PM »
UDT's are great. Make the array size 51 so the index can be 1-50.

b_carlton

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 606
    • thePLCguy
Re: Recording Max and Minimum Temp values.
« Reply #5 on: August 28, 2019, 12:29:04 AM »
Remember to initialize the Min temperatures to the highest possible reading and the Max temperatures to the lowest possible reading. Maybe set an 'initialize' bit before the first execution of the 50 pass for/next loop then clear it after the first foll pass. Edit - or just record the current room temp as both min and Max on that first pass.
« Last Edit: August 28, 2019, 12:41:41 AM by b_carlton »
An output is a PLC's way of getting its inputs to change.

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Recording Max and Minimum Temp values.
« Reply #6 on: August 28, 2019, 11:38:54 AM »
Thanks for the info everybody. I realize now that my whole program could be a lot smaller with the For instruction as i have already duplicated a lot of rungs 50 times for the individual rooms.
   Is there some way to convert this 1970 epoch time value to a normal time value (just hours and minutes) with a c-more HMI? Or do i have to do the math with the do-more and then display with C-more?

ADC Product Engineer

  • Hero Member
  • *****
  • Posts: 270
Re: Recording Max and Minimum Temp values.
« Reply #7 on: August 28, 2019, 01:15:11 PM »
The PLC will have to do the conversion.  EPOCH2DT will do the job for you.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3847
    • Host Engineering
Re: Recording Max and Minimum Temp values.
« Reply #8 on: August 28, 2019, 01:38:51 PM »
If you truly do not care about the actual date/time stamp (year/month/day/hour/minute/second), just the current .Hour and .Minute, you can replace the TimeStamp DWORD structure members with 2 members called .Hour and .Minute and copy them from $Now.Hour and $Now.Minute to those members (instead of the MOVE of DST22)

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Recording Max and Minimum Temp values.
« Reply #9 on: September 02, 2019, 01:27:36 PM »
   Is there a C-More expert on this site? I made the UDTs and memory blocks as suggested in the above replies and the FOR instruction seems to work really well. Now I realize that I can't export UDT and memory block names to the C-More, where all this info has to be accessed. It seems like only the built-in memory blocks can get exported. How can I get around this issue?

Andrew S

  • Hero Member
  • *****
  • Posts: 144
Re: Recording Max and Minimum Temp values.
« Reply #10 on: September 02, 2019, 02:09:51 PM »
I don't see myself as a C-More expert but I've come up against this issue and the way I worked around it was to give each element a nickname in the PLC (use the documentation editor for this to make it a little easier). Then you can address the elements in the C-More. It can be a fair amount of work but once it's done you can access the tags very easily.

Andrew.

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Recording Max and Minimum Temp values.
« Reply #11 on: September 02, 2019, 04:34:59 PM »
I had already assigned nicknames to all the individual elements in the memory blocks I created. However, the C-more still won't let me import those nicknames. When i try to add the tags in the c_more add menu, it only lets me add built in memory types, like n or c or d. Not the user created elements that i need.Attached is a screenshot of what comes up when I try to import the tags.

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Recording Max and Minimum Temp values.
« Reply #12 on: September 02, 2019, 05:29:22 PM »
Ok, I found the problem.  On the very first page when starting this project, I had selected "Do-More Ethernet (built-in memory only) protocol", instead of "Do-more ethernet(symbolic addressing full memory)". Now I need to figure out how to change this setting without redoing the whole project. Any advice would be appreciated.

Andrew S

  • Hero Member
  • *****
  • Posts: 144
Re: Recording Max and Minimum Temp values.
« Reply #13 on: September 02, 2019, 06:45:48 PM »
Save your existing project. Create a new project with the appropriate settings and then Import/Project-Data. I'm not sure whether or not that imports the tag DB but if it doesn't you can export/import that separately.

mhw

  • Hero Member
  • *****
  • Posts: 250
Re: Recording Max and Minimum Temp values.
« Reply #14 on: September 06, 2019, 01:08:38 PM »
You could also send them to a SS or SL using the STRPRINT command in DoMore.