Display minutes as hours & minutes

Wiresplus
2024-05-25
2024-05-27
  • Wiresplus - 2024-05-25

    Hello,
    I have a counter that increments an INT value once per minute
    I want to display this value in Minutes until 60, then Hours/Minutes thereafter on the HMI

    Codesys V3.5 SP16

    I can divide the minutes by 60 to get hours, but then the minutes is still more than 60.

    Example: a process has run for 350 Minutes. I need to display "5 Hours 50 Minutes"
    But if it's only been 45 Minutes, I don't want "0 Hours 45 Minutes" , just "45 Minutes"

     

    Last edit: Wiresplus 2024-05-25
  • nano - 2024-05-25

    hey

    time := INT_TO_TIME(minutes * 1000 * 60);

    update: forum show the math wrong

     

    Last edit: nano 2024-05-26
  • TimvH

    TimvH - 2024-05-27

    You could use the Modulo function to get the minute part from the total minutes:

    Minutes := TotalMinutes MOD 60;

     
  • wollvieh

    wollvieh - 2024-05-27

    Here a code for an Operation Counter with :
    days,hours,minutes,seconds as an example, maybe it points you the right direction ?

    FUNCTION_BLOCK OperationDayHour
    VAR_INPUT
        IN         : BOOL;      // Betrieb
        Takt       : BOOL;      // 1Hz Systemtakt
    END_VAR
    VAR_OUTPUT
        BetrTag    : UDINT;  // Ausgabe Betriebstage
        Betrstd    : UDINT;  // Ausgabe Betriebsstunden
        Betrmin    : UDINT;  // Ausgabe Betriebsminuten
        Betrsec    : UDINT;  // Ausgabe Betriebsekunden
        BetrString : STRING; // Ausgabe als String
    END_VAR
    VAR
        ///Erkennung Taktflanke
        Flanke: R_TRIG;
    END_VAR
    VAR_IN_OUT
        BetrsecAbsolut: UDINT;  //Ein/Ausgangsvariable Betriebssekunden RETAIN !!!
    END_VAR
    
    Flanke(CLK:= Takt, Q=> );    (*Erkennung Taktflanke*)
    IF (IN AND Flanke.Q) THEN    (*Sekunden hochzΓ€hlen*)
        BetrsecAbsolut  := BetrsecAbsolut + 1;
    END_IF
    
      Betrsec         :=   BetrsecAbsolut               MOD 60;
      Betrmin         := ( BetrsecAbsolut / 60)         MOD 60;
      Betrstd         := ( BetrsecAbsolut / 60 / 60 )   MOD 24;
      BetrTag         := ( BetrsecAbsolut / 60 / 60 /24 );
    
      BetrString      := RIGHT  ( UDINT_TO_STRING( BetrTag + 100000),5);
      BetrString      := CONCAT (BetrString, 'd_');  
      BetrString      := CONCAT (BetrString,RIGHT  ( UDINT_TO_STRING( Betrstd + 100000),5));
      BetrString      := CONCAT (BetrString, 'h_');
      BetrString      := CONCAT (BetrString, RIGHT  ( UDINT_TO_STRING( Betrmin + 100),2));        
      BetrString      := CONCAT (BetrString, 'm_');
      BetrString      := CONCAT (BetrString, RIGHT  ( UDINT_TO_STRING( Betrsec + 100),2));   
      BetrString      := CONCAT (BetrString, 's');
    
     

Log in to post a comment.