home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / amiga / programm / 15761 < prev    next >
Encoding:
Internet Message Format  |  1992-11-12  |  4.7 KB

  1. Path: sparky!uunet!gossip.pyramid.com!olivea!spool.mu.edu!news.cs.indiana.edu!sgiblab!swrinde!cs.utexas.edu!gateway
  2. From: s3007048@mackay.mpce.mq.edu.au
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: timer/parallel interaction vi CIA and real time routines
  5. Message-ID: <9211122252.AA07931@mackay.mpce.mq.edu.au>
  6. Date: 12 Nov 92 23:09:16 GMT
  7. Sender: daemon@cs.utexas.edu
  8. Organization: UTexas Mail-to-News Gateway
  9. Lines: 169
  10. NNTP-Posting-Host: cs.utexas.edu
  11.  
  12.  
  13. I am writing an application to control at stepper motor dependant on a
  14. frequency between 250Hz and 1088Hz.  The sample routine shown below had
  15. overhead, and I wanted to reduce that overhead by compensation.  I would
  16. time the contents of the loop, adjust the waiting times for that pulse,
  17. and run the loop using this value.  I presumed it could be done as shown
  18. below, but I presume that the DoIO() that waits the time, does not
  19. interact well with the direct use of the parallel port.  Has anyone
  20. done anything like this before?  Has anyone written a real time (rather
  21. than process driven) timer routine?  I would appreciate any help you
  22. could give me.  Please email me at s3007048@mackay.mpce.mq.edu.au
  23.  
  24. Thanx in advance...
  25.  
  26. Regards,
  27.  
  28.     Mike.
  29.  -----------------------------------------------------------------------------
  30.  Internet:    s3007048@mackay.mpce.mq.edu.au
  31.     Phone:    +61 43 841525
  32.  
  33.                      "I have a cunning plan..."    - Baldrick (Black Adder)
  34.  -----------------------------------------------------------------------------
  35.      Michael Glew - School of Math Phys Comp & Elec - Macquarie University
  36.  -----------------------------------------------------------------------------
  37.  
  38. ----cut-here---------8<-----------------------------------
  39. {
  40. ***************************************************************************
  41. **  Section:  sample                                                     **
  42. ***************************************************************************
  43.  
  44. This samples a section at a certain frequency for a certain amount of time
  45.  
  46. NB:    time will be a multiple of 0.4
  47. }
  48.  
  49. procedure sample(freq:integer;time:real);
  50.  
  51. var
  52.     counter        : integer;
  53.  
  54.     start,
  55.     finish        : TimeVal;
  56.  
  57.     iterations    : integer;
  58.  
  59. begin
  60.     if (freq = 0) or (time = 0.0) then    { no divisions-by-zero please }
  61.         return;
  62.     waitmic := round(500000/freq);
  63.     iterations := round(float(freq)*time)-2;
  64.  
  65.     GetSysTime(TimerMsg,Start);            {*START*}
  66.     msg := GetMsg(winptr^.UserPort);
  67. {$A
  68.     jsr    -132(a6)
  69.     move.w    #$7fff,$dff09c
  70.     move.w    #$0008,$dff09a
  71.     move.b    #$7f,$bfed01
  72.     move.b    #%10010000,$bfed01
  73.     move.b    #$ff,$bfe301
  74.     move.b    #%10000000,$bfe101
  75.     move.w    #$7fff,$dff09c
  76.     move.w    #$8008,$dff09a
  77.     move.b    #$7f,$bfed01
  78.     move.b    #%10001111,$bfed01
  79.     jsr    -138(a6)
  80. }
  81.     if waitmic>0 then begin
  82.         with timermsg^ do begin
  83.             tr_time.tv_secs        := 0;
  84.             tr_time.tv_micro    := waitmic;
  85.             tr_node.io_Command    := TR_ADDREQUEST
  86.         end;
  87.  
  88.         if DoIO(timerMsg)<>0 then
  89.             errormsg("a problem occurred with the CIA timer")
  90.     end;
  91.     if msg<>Nil then begin
  92.         control_routine;
  93.         stop_sample:=true;
  94.         return
  95.     end;
  96. {$A
  97.     jsr    -132(a6)
  98.     move.w    #$7fff,$dff09c
  99.     move.w    #$0008,$dff09a
  100.     move.b    #$7f,$bfed01
  101.     move.b    #%10010000,$bfed01
  102.     move.b    #$ff,$bfe301
  103.     move.b    #0,$bfe101
  104.     move.w    #$7fff,$dff09c
  105.     move.w    #$8008,$dff09a
  106.     move.b    #$7f,$bfed01
  107.     move.b    #%10001111,$bfed01
  108.     jsr    -138(a6)
  109. }
  110.     if waitmic>0 then begin
  111.         with timermsg^ do begin
  112.             tr_time.tv_secs        := 0;
  113.             tr_time.tv_micro    := waitmic;
  114.             tr_node.io_Command    := TR_ADDREQUEST
  115.         end;
  116.  
  117.         if DoIO(timerMsg)<>0 then
  118.             errormsg("a problem occurred with the CIA timer")
  119.     end;
  120.     GetSysTime(TimerMsg,Finish);            {*FINISH*}
  121.     SubTime(Finish,Start);
  122.     waitmic := 2*waitmic-round(Finish.tv_micro/2);
  123.     for counter:=0 to iterations do begin
  124.         msg := GetMsg(winptr^.UserPort);
  125. {$A
  126.     jsr    -132(a6)
  127.     move.w    #$7fff,$dff09c
  128.     move.w    #$0008,$dff09a
  129.     move.b    #$7f,$bfed01
  130.     move.b    #%10010000,$bfed01
  131.     move.b    #$ff,$bfe301
  132.     move.b    #%10000000,$bfe101
  133.     move.w    #$7fff,$dff09c
  134.     move.w    #$8008,$dff09a
  135.     move.b    #$7f,$bfed01
  136.     move.b    #%10001111,$bfed01
  137.     jsr    -138(a6)
  138. }
  139.         if waitmic>0 then begin
  140.             with timermsg^ do begin
  141.                 tr_time.tv_secs        := 0;
  142.                 tr_time.tv_micro    := waitmic;
  143.                 tr_node.io_Command    := TR_ADDREQUEST
  144.             end;
  145.  
  146.             if DoIO(timerMsg)<>0 then
  147.                 errormsg("a problem occurred with the CIA timer")
  148.         end;
  149.         if msg<>Nil then begin
  150.             control_routine;
  151.             stop_sample:=true;
  152.             return
  153.         end;
  154.  
  155. {$A
  156.     jsr    -132(a6)
  157.     move.w    #$7fff,$dff09c
  158.     move.w    #$0008,$dff09a
  159.     move.b    #$7f,$bfed01
  160.     move.b    #%10010000,$bfed01
  161.     move.b    #$ff,$bfe301
  162.     move.b    #0,$bfe101
  163.     move.w    #$7fff,$dff09c
  164.     move.w    #$8008,$dff09a
  165.     move.b    #$7f,$bfed01
  166.     move.b    #%10001111,$bfed01
  167.     jsr    -138(a6)
  168. }
  169.         if waitmic>0 then begin
  170.             with timermsg^ do begin
  171.                 tr_time.tv_secs        := 0;
  172.                 tr_time.tv_micro    := waitmic;
  173.                 tr_node.io_Command    := TR_ADDREQUEST
  174.             end;
  175.  
  176.             if DoIO(timerMsg)<>0 then
  177.                 errormsg("a problem occurred with the CIA timer")
  178.         end
  179.     end
  180. end;
  181.