Here's a way to do it using a TIMER and an IND block.  You could do without
the timer and just use the WAIT for the period but then you might run into
problems if your CP goes into overrun.....

This is set for a flow but will work on anything..

INDEPENDENT_SEQUENCE{*******************************
          **                                      **
          **       INDEPENDENT SEQUENCE           **
          **         CONTROL BLOCK                **
          **                                      **
          *****************************************}

CONSTANTS {*****************************************
          * specify any Constants                  *
          *             in the following format:   *
          ******************************************
          * 12_char_name = value ;                 *
          *****************************************}

VARIABLES {*****************************************
          * specify any Block Local Variables      *
          *             in the following format:   *
          ******************************************
          * 12_char_name [ , 12_char_name ] : type;*
          *                                        *
          *where type is one of B, I, R, S, S12, S6*
          *****************************************}

        AVG:R[360];
        ICT:I;

USER_LABELS{****************************************
          * specify any user labeled parameters    *
          *       in one of the following formats: *
          ******************************************
          *   10_char_name : BI00nn; n = 01 -- 24  *
          *   10_char_name : BO00nn; n = 01 -- 16  *
          *   10_char_name : BA000n; n =  1 --  4  *
          *   10_char_name : RI00nn; n = 01 -- 15  *
          *   10_char_name : RO00nn; n = 01 -- 15  *
          *   10_char_name : RA000n; n =  1 --  2  *
          *   10_char_name : II000n; n =  1 --  8  *
          *   10_char_name : IO000n; n =  1 --  5  *
          *   10_char_name : IA0001;               *
          *   10_char_name : SN00nn; n = 01 -- 10  *
          *****************************************}

        FI3050: RI0001; {MEASURED FLOW}
        FA3050: RO0001; {AVERAGE FLOW}
        CNTIDX: IO0001; {AVERAGER INDEX}
        SUM:    RO0002; {TEMPORARY SUM}
        TIM:    RI0002; {10 SECOND TIMER INPUT}
        REMOVE: RO0003; {VALUE TO REMOVE FROM SUM}
        BTU:    RI0003; {ENTERED VALUE FOR BTU}
        BTU_VAL: RO0015; {CALCULATED BTU VALUE FOR CURRENT FLOW}

          {*****************************************
          * Specify any Subroutines                *
          ******************************************
          *                                        *
          * SUBROUTINE name ( formal arguments ) ; *
          *  VARIABLES  subr. local variables ;    *
          *  STATEMENTS                            *
          *      ;                                 *
          * ENDSUBROUTINE                          *
          *****************************************}


          {*****************************************
          * Specify any                            *
          *    Standard Block Exception Handlers   *
          ******************************************
          *                                        *
          * BLOCK_EXCEPTION exc_name [ DISABLE ]   *
          *  STATEMENTS                            *
          *      ;                                 *
          * ENDEXCEPTION                           *
          *****************************************}


STATEMENTS{*****************************************
          *      Specify the statements here       *
          *****************************************}

        CNTIDX := 1;
        AVG := SET_ARRAY(FI3050);
        SUM := FI3050 * 360.0;
        START_TIMER(::10SECONDS.TIMR1,0.0);
<<START>>
        REMOVE := AVG[CNTIDX];
        AVG[CNTIDX] := FI3050;
        SUM := SUM - REMOVE;            {REMOVE THE OLD VALUE}
        SUM := SUM + AVG[CNTIDX];       {ADD IN THE NEW VALUE}
        CNTIDX := CNTIDX + 1;
        IF CNTIDX > 360 THEN
          CNTIDX := 1;
        ENDIF;
        FA3050 := SUM / 360.0;
        {CALCULATE BTU VALUE}
        BTU_VAL := FA3050 * BTU;
        ::10SECONDS.TIMR1V := 0.0;
        WAIT 1;
        WAIT UNTIL TIM >= 10.0;
        GOTO START;

ENDSEQUENCE

-----Original Message-----
From: Steve Rigby [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 06, 2000 8:01 AM
To: 'Foxboro DCS Mail List' (E-mail)
Subject: Rolling average


Hi all,

What I would like is a way to calculate the average position of a valve over
the last hour, updated say every minute.
and then available as an input for a block. Any ideas?

Thanks in advance.

Steve Rigby
Air Liquide Industrie BV
Merseyweg 10
3197 KG Botlek-Rotterdam
The Netherlands
Tel: +31(0)181-271131
Fax:+31(0)181-271100
Email:
[EMAIL PROTECTED]
[EMAIL PROTECTED]





-----------------------------------------------------------------------
This list is neither sponsored nor endorsed by the Foxboro Company. All 
postings from this list are the work of list subscribers and no warranty 
is made or implied as to the accuracy of any information disseminated 
through this medium. By subscribing to this list you agree to hold the 
list sponsor(s) blameless for any and all mishaps which might occur due to 
your application of information received from this mailing list.

To be removed from this list, send mail to 
[EMAIL PROTECTED] 
with "unsubscribe foxboro" in the Subject. Or, send any mail to
[EMAIL PROTECTED]

-----------------------------------------------------------------------
This list is neither sponsored nor endorsed by the Foxboro Company. All 
postings from this list are the work of list subscribers and no warranty 
is made or implied as to the accuracy of any information disseminated 
through this medium. By subscribing to this list you agree to hold the 
list sponsor(s) blameless for any and all mishaps which might occur due to 
your application of information received from this mailing list.

To be removed from this list, send mail to 
[EMAIL PROTECTED] 
with "unsubscribe foxboro" in the Subject. Or, send any mail to
[EMAIL PROTECTED]

Reply via email to