TP (pulse)

This test case it part of the test suite proposed for new devices.

Test case ID: R1022
Language: ST

Code:
tests2/t1022.st
(* TP pulse test - this should be called several 13 times with deltaTime=100msecs  *)
(*
           +---------+  
tp1        |         |  
         --+         +------------
           0        600     
                     +-----+
tp2                  |     |     
         ------------+     +------    
           0        600   1000   
*)

PROGRAM T1022
   VAR 
    cont : INT; // count iters
    tp1: TP;   // 580msecs pulse, start at t=100
    tp2: TP;   // 380msecs pulse, starts when tp1 ends
    dt1,dt2 : DATE_AND_TIME; // timestamps
    tp1done,tp2done : BOOL; // true if both pulses have been up at least once
    iter : INT := -1; // iterations are counted started from 0
  END_VAR

  VAR_TEMP
   tp1_in,tp1_q,tp2_in,tp2_q : BOOL;
   t1,t2 : TIME;
   msecs : DINT := 0 ; // msecs since tp1 started
  END_VAR 
  
  VAR_EXTERNAL 
        _T_PARAMS : TEST_PARAMS;
  END_VAR
  

  iter := iter+1;
  IF iter = 1 THEN // at iter 1  we produce a rising edge at TP1 input
    tp1_in := 1; 
    dt1:= _GEB_NOW_TIMESTAMP(1); // record start of pulse
  END_IF;

  tp1( IN := tp1_in , PT := T#580ms);

  tp2_in := iter > 2 AND NOT(tp1.Q); // tp2_in  will have a rising edge when tp1 ends

  tp2( IN := tp2_in , PT := T#380ms);

  IF tp1.Q THEN tp1done := TRUE; END_IF;
  IF tp2.Q THEN tp2done := TRUE; END_IF;

  IF iter > 1 THEN 
    msecs := TIME_TO_DINT(_GEB_ELAPSED_TIME(dt1));
  END_IF; 

  IF msecs > 10  AND msecs < 570 THEN  // inside pulse 1
         _GEB_ASSERT_( tp1.Q);
         _GEB_ASSERT_(NOT( tp2.Q));
  END_IF;

  IF msecs > 630  AND msecs < 970 THEN  // inside pulse 2
         _GEB_ASSERT_( tp2.Q);
         _GEB_ASSERT_(NOT( tp1.Q));
  END_IF;

  IF _T_PARAMS.cycle = _T_PARAMS.timestorun THEN  // last iter
      _GEB_ASSERT_( tp1done AND tp2done);
      _GEB_ASSERT_( NOT tp1.Q);
      _GEB_ASSERT_( NOT tp2.Q);
      _GEB_ASSERT_( iter=12);
     //    _GEB_MSG_('last iter');      
  END_IF;

END_PROGRAM