home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / sci / electron / 23189 < prev    next >
Encoding:
Internet Message Format  |  1993-01-22  |  7.3 KB

  1. Path: sparky!uunet!munnari.oz.au!comp.vuw.ac.nz!newshost.wcc.govt.nz!kosmos.wcc.govt.nz!PROVO_B
  2. From: provo_b@kosmos.wcc.govt.nz (Bart)
  3. Newsgroups: sci.electronics
  4. Subject: RE: 68HC11 input capture code wanted?
  5. Date: 22 Jan 1993 06:36:19 GMT
  6. Organization: Wellington City Council (Public Access), Wgtn, Nz
  7. Lines: 144
  8. Message-ID: <1jo4l3INNd4i@golem.wcc.govt.nz>
  9. Reply-To: provo_b@kosmos.wcc.govt.nz
  10. NNTP-Posting-Host: kosmos.wcc.govt.nz
  11.  
  12. >From: geoffrey@cosc.canterbury.ac.nz (Geoff Thomas)
  13. >Date: Tue, 19 Jan 1993 04:05:27 GMT
  14. > I'm wanting to write some code for the HC11 Input Capture system, and
  15. > I'd like to get hold of some examples.
  16.  
  17. Following are some *extracts* from my HC11 code to sense wall distances
  18. on my ultrasonic wall sensing micromouse.  The circuit diagrams can be
  19. found in my NELCON'92 paper:
  20.  "Robotic Control and Sensing, an HC16 application."
  21.  NELCON'92 Proceedings, August 1992, pp 81-88.  
  22. There will be copies at the Dept. of EEE at Canterbury Uni.
  23.  
  24. Refer 68HC11 data book or Reference Manual M68HC11RM/AD for meaning
  25. of undefined labels  or bit mask values, (standard HC11 acronyms have
  26. been used).
  27.  
  28. The code uses the HC11 TOC (Timer Output Compares) 1,2,3,4,5 to generate
  29. the 4 orthogonal sonic sense pulse gates, which are synchronised to an HD6340
  30. generated ultrasonic drive signal.  TOC1 is used to turn ON the selected
  31. pulse gates, whilst TOCs 2,3,4,5 turn them off after the desired burst time.
  32. TOC 2,3,4,5 interrupts are enabled, and their service routine enables return
  33. pulse capture and prepares TOC1 for the next pulse, if any.
  34.  
  35. * Task specific equates: Note: S_Gn = Sonic Gate north - front looking pulse.
  36.  
  37. SGn .equ   OC1D6 ; Assert S_Gn to 1 on TOC1| Data bits to assert outputs
  38. SGs .equ   OC1D5 ; Assert S_Gs to 1 on TOC1| OC2 thru OC5.
  39. SGe .equ   OC1D4 ; Assert S_Ge to 1 on TOC1| Register: OC1D
  40. SGw .equ   OC1D3 ; Assert S_Gw to 1 on TOC1| Clear immediately after Pulse(s)
  41.  
  42. --- relevant RAM locations ----
  43.          ...
  44. N_time  .rmb 2 ; Pulse return time, ex TIC2, front wall.
  45. S_time  .rmb 2 ; Pulse return time, ex TIC1, back wall.
  46. Son_Act .rmb 1 ; TOC action bits.  Set to action sonic pulses.
  47. Son_Rpt .rmb 1 ; Sonic pulse repetition period, to nearest ms <= 63.
  48.          ...
  49.  
  50. --- Interrupt initialization:
  51.            ...
  52. Front_Back LDX   #REG_CON    ; point to HC11 control bit & register bank.
  53.            BSET  TCTL2-REG_CON,X,EDG1A+EDG2A ; capture on rising edges
  54.            BCLR  TCTL2-REG_CON,X,EDG1B+EDG2B ; ensure other bits zero.
  55.            BCLR  TMSK1-REG_CON,X,IC2I+IC3I   ; ensure interrups off.
  56.  
  57.            LDX   #TIC_IRQ    ; Redirect PROVON interrupts for TICs 2,3.
  58.            STX   TIC1VC      ; [PROVON = Provo's Monitor for 6800 series]
  59.            STX   TIC2VC      ; for front/back pulse interrupts
  60.            ...
  61.  
  62. --- After pulse(s) have been sent - Turn on TIC interrupts in HC11.
  63. --- THIS SECTION IS part of SUBROUTINE Pls_End which is accessed by the
  64. --- TOC interrupt service routine which runs at the end of the usonic pulses.
  65.           ...
  66. back_on   BRCLR Son_Act,SGs,front_on
  67.           BSET  TMSK1-REG_CON,X,IC1I ; enable back, south, sense interrupt
  68. front_on  BRCLR Son_Act,SGn,walls_on
  69.           BSET  TMSK1-REG_CON,X,IC2I ; enable front, north, sense interrupt
  70.  
  71. walls_on  BSR  Rpt_Calc ;Check update TOC repeat time? Ret: Z=1 if no repeats.
  72.           CLC           ;IF Z=1, indicate no repeating ie Return with Z,C=1,0.
  73.           BEQ  PE_Quit  ;Exit if Rpt_Tim is zero
  74.           LDD  Rpt_Tim  ;Else get TOC update interval and go update TOC1 etc.
  75. *                       ;& Fall into Son_repit.
  76. *********
  77. *   Son_Repit is Subroutine to fire up next sonic burst after time interval
  78. *   in D
  79. [ultrasonic burst has pulse period and burst length tuned to suit either 
  80.  wall follow or long distance scan] 
  81.  
  82. --- TIC interrupt routines:
  83.  
  84. TIC_IRQ:   LDX  #REG_CON ; point to HC11 device register bank.
  85.                          ; Timer Input Capture interrupt service routines
  86. *--------------------------------------------
  87. * TIC_IRQ checks flags on return pulse inputs.
  88. *   If Son_Act flags set, then check return flags.
  89. *       IF ( flag set and capture time <= Max ) Dir_Time = capture time
  90. *        ELSE Dir_time = $0000
  91. *   Else capture time not updated.
  92.  
  93.            LDY  #$0000
  94. Tst_SGn    BRCLR Son_Act,SGn,Tst_SGs ; North wall-sense enabled?
  95.            STY   N_time              ; Yes, default it incase!
  96.            BRCLR TFLG1-REG_CON,X,IC1F,Tst_SGs  ; If flag clear, check South!
  97.            INY                       ; - indicate valid TIC IRQ
  98. nth_off    LDAA  #IC1F               ; clear North flag!
  99.            STAA  TFLG1-REG_CON,X
  100.            BCLR  TMSK1-REG_CON,X,IC1I ; and disable North interrupt
  101.  
  102.            LDD   TIC1-REG_CON,X   ; flag was set, get bounce time
  103.            SUBD  Son_BEG0         ; subtract pulse start time
  104.            CPD   #Maxscan         ; If too long,
  105.            BGT   Tst_SGs          ;   default it!
  106.            STD   N_time           ; store value - represents front distance.
  107.  
  108. Tst_SGs    BRCLR Son_Act,SGs,TIC_Fin ; South wall-sense enabled?
  109.            STY   S_time
  110.            BRCLR TFLG1-REG_CON,X,IC2F,TIC_Fin ; Problem if flag clear!!
  111.            INY                       ; indicate a valid IRQ.
  112. sth_off    LDAA  #IC2F               ; clear South flag!
  113.            STAA  TFLG1-REG_CON,X
  114.            BCLR  TMSK1-REG_CON,X,IC2I ; and disable south interrupt
  115.  
  116.            LDD   TIC2-REG_CON,X
  117.            SUBD  Son_BEG0         ; subtract pulse start time
  118.            CPD   #Maxscan         ; is time value excessively large?
  119.            BGT   TIC_Fin
  120.            STD   S_time           ; save 'distance' to rear wall.
  121.  
  122. TIC_Fin    CPY  #0                ; if zero then no IRQs found, spurious.
  123.            BNE   TIC_end
  124.            LDX  #bad_TIC          ; point to error message "TIC?"
  125.            LDAB  TFLG1            ; get Timer flags, see if Input capture??
  126.            JSR   Print_it         ; print flags and message
  127.            JSR   CRLF
  128. TIC_end    RTI
  129.  
  130. TOC_IRQ:                    ; Accessed AFTER pulses, NOT by TOC1 !.
  131.            JSR   Print_Son  ; development assist in tuning sonic pulses
  132.            JSR   Pls_End    ; Pls_End will fix all!
  133.            RTI              ; Pls_End a subroutine to assist debugging.
  134.  
  135. As it is always useful to have 'online' chats with experienced practitioners
  136. of the art, I suggest you may like to contact Peter Kell, Senior Lecturer
  137. at the Dept. of Electrotechnology, Christchurch Polytechnic.  He teaches 
  138. microprocessor hardware and Software Engineering and has designed and
  139. developed an HC11 training unit for teaching, (refer his paper in NELCON'92
  140. Proceedings, "Microcontroller Training towards 2000", pp 139p-145. I am most
  141. impressed with his work and hope to obtain a class set of his units to
  142. support our teaching.
  143. ------------------------------------------------------------
  144. > Also, how can I get in contact with the HC11 mailing list?
  145.  
  146. I have *NOT* had anything from the HC11 list for some time now, since about
  147. the time Bob Wier moved to another site.  Does it still exist somewhere in
  148. net-land?? 
  149.  
  150. Regards, Bart.
  151. Bart Provo    |provo_b@kosmos.wcc.govt.nz |School of Electronic Engineering
  152. PO Box 47-105 |access via: PC/AT+modem on |Central Institute of Technology
  153. TRENTHAM      |home phone, (answer phone) |Private Bag 39-807
  154. Wellington    |     in NZ: (04)-5277-054  |Wellington Mail Centre,  NZ.
  155. NEW ZEALAND.  |     to NZ:+64-4-5277-054  |Phn:(04)5277-089 Fax:(04)5276-374
  156.