Reading and writing Minutes and seconds in TIA Portal?

asteroide

Member
Join Date
Jul 2010
Location
der
Posts
158
Hello Friends

My experience with Siemens is limited.

From HMI I would like introduce Minutes and Seconds to a timer.

Also, in HMI I would like to show the time of the timer in minutes and seconds.

I have achieved only to show in accumulated seconds.

How can I do what I want?

Thanks in advance.

TDR_36_ET.jpg
 
To extract h/m/s from TIME You could do something like this.

Code:
FUNCTION "fcTimerRemainM" : Void
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_OUTPUT 
      udiHours : UDInt;   // Hours left
      usMins : USInt;   // Minutes left
      usSecs : USInt;   // Seconds left
   END_VAR

   VAR_IN_OUT 
      tTimer {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;   // Timer data
   END_VAR

   VAR_TEMP 
      udiDiffSec : UDInt;   // Time difference in seconds
   END_VAR


BEGIN
	(*
	    fcTimerRemainM
	    	    
	    This function is used to display remaining time of running timer.
	    Function provides cumulative hours, minutes and seconds.
	          
	*)
	
	
	#udiDiffSec := TIME_TO_UDINT(#tTimer.PT - #tTimer.ET) / 1000;   // -- Get difference between Set - Passed time in seconds
	#udiHours := #udiDiffSec / 3600;                                // -- Get hours left
	#usMins := UDINT_TO_USINT(#udiDiffSec / 60 - 60 * #udiHours);   // -- Get minutes left
	#usSecs := UDINT_TO_USINT(#udiDiffSec MOD 60);                  // -- Get seconds
	
	
END_FUNCTION
 
Is it possible that initial divide by 3600, to calculate #udiHours, will round (e.g. 1801s becomes 1h)? If so, the following will work:
Code:
// -- Get total seconds, place in hours variable for now
// -- N.B. we don't care if the divide-by-1000 rounds to nearest second
#udiHours := TIME_TO_UDINT(#tTimer.PT - #tTimer.ET) / 1000;

#usSecs := UDINT_TO_USINT(#udiHours MOD 60);   // -- Extract seconds of minute
#udiHours := (#udiHours - #usSecs) / 60;       // -- Convert balance to Minutes
#usMins := UDINT_TO_USINT(#udiHours MOD 60);   // -- Extract minute of hour
#udiHours := (#udiHours - #usMins) / 60;       // -- Convert balance to hours
 
Thanks for your help.

My main experience is with ladder, so I have done in ladder and it s working for showing time.

In my program I need to use around 30 timers and show in minutes and seconds in hmi, so I need several tags to convert to minutes and seconds.

How do you recommend to assign the timers and auxiliar registers?

1 DB for timer and its auxiliar registers o how can I do that?

Thanks again

TDR_36_Min_Sec.jpg
 
You just need to make a function, for example the one which is included in this thread.
If You don't know how to import a source in tia look here:

https://support.industry.siemens.com/cs/document/79168964/how-do-you-import-blocks-in-a-step-7-(tia-portal)-project-that-were-created-in-other-projects-or-with-earlier-versions-of-step-7-?dti=0&lc=en-US

Because of Your question it seems, that You are not familiar with Siemens Plcs, I would recommend reading this manual, especially chapter Code reusability, which will be good introduction on functions.

https://cache.industry.siemens.com/dl/files/084/109478084/att_900353/v1/81318674_Programming_Styleguide_DOC_v12_en.pdf
 
Last edited:

Similar Topics

Summary: How to remotely toggle BOOL values on a vendor-supplied system having a L24ER PLC? (RSLogix Studio 5000 version 33.01.00) I have a...
Replies
5
Views
1,710
I am reading and writing to I/O tags in Logix5571 using python. While dissecting using Wireshark, I could see that the Symbol Class(0x6b) is being...
Replies
0
Views
1,332
Hi again guys, This forum has been great for all the questions ive asked these last few days. Another one now.. haha I am currently working...
Replies
3
Views
4,207
Hey guys, i'm controlling altivar 71 drive from modicon m340 cpu 2020 plc through modbus communication, when I read and write at the same time...
Replies
5
Views
2,208
I am new to this. I have a customer wanting to use a MicroLogix 1400 to control a Mitsubishi A8NEIP-2P. All I can find on the Mitsubishi site is...
Replies
2
Views
2,237
Back
Top Bottom