home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PASCAL / TPHRT3.ZIP / DELAY.PAS < prev    next >
Pascal/Delphi Source File  |  1990-07-23  |  5KB  |  150 lines

  1. {----------------------------------------------------------------------------
  2.  |  Program DELAY.PAS                                                       |
  3.  |                                                                          |
  4.  |  This program demonstrates the high resolution delay functionality of    |
  5.  |  TPHRT V3.0.                                                             |
  6.  |                                                                          |
  7.  |  (c) 1989 Ryle Design, P.O. Box 22, Mt. Pleasant, Michigan 48804         |
  8.  |                                                                          |
  9.  |  V3.00  Shareware evaluation version                                     |
  10.  ----------------------------------------------------------------------------}
  11. uses
  12.     tphrt;
  13.  
  14. var
  15.  
  16.     min_delay      : longint;
  17.     step_delay     : longint;
  18.     delay_request  : longint;
  19.     hits           : longint;
  20.     elapsed        : longint;
  21.     resolution     : real;
  22.     delay_error    : real;
  23.     delay_ff       : real;
  24.     dp             : tdelay_type;
  25.  
  26.  
  27. procedure demo_delay(how_long : longint);
  28. {----------------------------------------------------------------------------
  29.  |  This procedure executes the requested high resolution delay, reports    |
  30.  |  the deviation and percent error, calculates an additional delay         |
  31.  |  optimization, and executes the delay again.                             |
  32.  |                                                                          |
  33.  |  Globals referenced: none                                                |
  34.  |                                                                          |
  35.  |  Arguments: (longint) how_long - requested delay duration                |
  36.  |                                                                          |
  37.  |  Returns  : void                                                         |
  38.  ----------------------------------------------------------------------------}
  39. var
  40.  
  41.     hits           : longint;
  42.     elapsed        : longint;
  43.     min_delay      : longint;
  44.     resolution     : real;
  45.  
  46. begin
  47.         t_ask_delay(how_long,dp);
  48.         t_reset(1);
  49.  
  50.         if (delay_request < 54000) then
  51.         begin
  52.             write('Delay with interrupts disabled ... ');
  53.             t_entry(1);
  54.             t_do_delay(dp);
  55.             t_exit(1);
  56.             writeln('complete.');
  57.         end
  58.         else
  59.         begin
  60.             write('Delay with interrupts enabled ... ');
  61.             t_entry(1);
  62.             t_do_delay_wints(dp);
  63.             t_exit(1);
  64.             writeln('complete.');
  65.         end;
  66.  
  67.         t_ask_timer(1,hits,elapsed);
  68.  
  69.         delay_error :=  (abs(elapsed - how_long) / how_long) * 100.0;
  70.  
  71.         writeln('Delay requested: ',how_long,'  Actual: ',elapsed,'  Error: ',delay_error:5:3,'%.');
  72.  
  73.         writeln;
  74.         write('Calculating additional delay optimization with t_calc_delay_ff ... ');
  75.         if (how_long < 54000) then
  76.             delay_ff := t_calc_delay_ff(how_long,NO_INTS_ON)
  77.         else
  78.             delay_ff := t_calc_delay_ff(how_long,INTS_ON);
  79.         writeln(delay_ff:6:4);
  80.  
  81.         t_ask_delay(how_long,dp);
  82.         t_reset(1);
  83.  
  84.         if (how_long < 54000) then
  85.         begin
  86.             write('Delay with interrupts disabled ... ');
  87.             t_entry(1);
  88.             t_do_delay(dp);
  89.             t_exit(1);
  90.             writeln('complete.');
  91.         end
  92.         else
  93.         begin
  94.             write('Delay with interrupts enabled ... ');
  95.             t_entry(1);
  96.             t_do_delay_wints(dp);
  97.             t_exit(1);
  98.             writeln('complete.');
  99.         end;
  100.  
  101.         t_ask_timer(1,hits,elapsed);
  102.  
  103.         delay_error := (abs(elapsed - how_long) / how_long) * 100.0;
  104.  
  105.         writeln('Delay requested: ',how_long,'  Actual: ',elapsed,'  Error: ',delay_error:5:3,'%.');
  106.  
  107.         t_set_delay_ff(1.0);
  108.  
  109. end; { demo_delay }
  110.  
  111.  
  112. begin
  113.  
  114.     writeln('Delay Test - TPHRT V3 Demonstration Series');
  115.     writeln(' ');
  116.  
  117.     t_start;
  118.  
  119.     min_delay  := t_min_delay;
  120.     resolution := t_res_delay / 10.0;
  121.  
  122.     writeln('In this hardware environment, minimum delay possible is ',min_delay,' usec.');
  123.     writeln('Delay resolution is ',resolution:3:1,' usec.');
  124.  
  125.     writeln(' ');
  126.     write('Enter desired delay in microseconds: ',t_min_delay,' - 1000000, 0 to quit >> ');
  127.     readln(delay_request);
  128.  
  129.     while (delay_request <> 0) do
  130.     begin
  131.         if (delay_request < min_delay) then
  132.             delay_request := min_delay
  133.         else if (delay_request > 1000000) then
  134.             delay_request := 1000000;
  135.  
  136.         demo_delay(delay_request);
  137.  
  138.         writeln(' ');
  139.         write('Enter desired delay in microseconds: ',t_min_delay,' - 1000000, 0 to quit >> ');
  140.         readln(delay_request);
  141.  
  142.     end;
  143.  
  144.     t_stop;
  145.  
  146.     writeln(' ');
  147.     writeln('Delay Test complete.');
  148.  
  149. end. { delay }
  150.