Home

Microcomputer Communications Project

image

Contents

1. ld a 0x52 call displ ld a 0 41 call displ ld a 0x44 call displ ld a 0 41 call displ ld a 0x52 call displ ld a 0x20 call displ ld a Ox4D call displ ld a Ox4F call displ ld a 0x44 call displ ld a 0x45 call displ ld a 0x20 call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ character character character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character and go to next line 59 call display_character call display_character call display_character call display_character call display_character call display_character ret display tracker seeking display TRACKER SEEKING and go to next line ld a 0x54 call display character ld a
2. 10 OA 132 84 17 1 179 12 228 E4 09 09 133 85 17 11 180 B4 12 229 09 09 134 86 17 11 181 B5 12 230 E6 09 09 135 87 17 1 182 Be 12 231 E7 09 09 136 88 17 11 183 B7 12 232 E8 09 09 137 89 16 10 184 B8 12 0 233 9 09 09 138 8 16 10 185 B9 12 234 EA 09 09 1399 8B 16 10 186 12 285 EB 09 09 140 8 16 10 187 BB 12 236 EC 09 09 141 80 16 10 188 BC 12 OC 237 ED 09 09 142 8 16 10 189 BD 12 oc 238 EE 09 09 143 8F 16 10 190 BE 12 0C 239 EF 09 09 144 90 16 10 191 BF 12 oc 240 Fo 09 09 145 91 15 OF 192 co 12 OC 241 F1 09 09 146 92 15 OF 198 261 12 OC 242 F2 09 09 147 93 15 OF 194 2 11 243 09 09 148 94 15 OF 195 C3 11 0B 244 F4 09 09 149 95 15 OF 196 C4 11 245 09 09 150 96 15 197 5 11 0B 246 Fe o9 09 151 97 15 OF 198 C6 11 0B 247 F7 64 40 152 98 15 199 C7 11 248 F8 64 40 153 99 15 OF 200 C8 10 249 9 64 40 154 9 14 201 C9 10 0A 250 FA 64 40 155 9B 14 OE 202 CA 10 0A 251 FB 64 40 156 9C 14 203 CB 10 0A 252 FC 64 40
3. 10 display_rotating Displays Rotating Back on LCD display_object Displays Object Detected on LCD Global Variables Since this a low level language all variables used were global They were declared as having specific memory locations at the start of the program in such locations that they did not overlap with any part of the program or loop up tables in memory Variable Name Purpose Modules used in angle Stores the current angle at which the sensor is positioned in all modes or the angle of the point being plotted on the screen radar tracker profiler increase_angle3 decrease_angle3 increase_angle decrease_angle rotate_to_angle get_coords display_angle_distance distance Stores the current distance of the object being get_coords detected in front of the sensor display_angle_distance radar tracker profiler objectdistance Stores the distance between the centre of the radar last object detected and the sensor in radar mode objectangle Stores the angle at which the centre of the last radar object detected was in radar mode middistance Stores the distance at which the object was tracker previously in tracker mode midangle Stores the angle at which the centre of the tracker object being tracked was last detected in tracker mode register d Temporarily holds the value of reload register clock_timer_toggle high for the servo tim
4. 73 129 81 575 023E 02 3E 130 82 578 0241 02 41 131 83 581 0244 02 44 132 84 583 0247 02 47 133 85 586 024 02 4 134 86 589 0240 02 40 135 87 592 0250 02 50 136 88 595 0252 02 52 137 89 598 0255 02 55 138 8A 601 0258 02 58 139 8B 603 025B 02 5B 140 8C 606 025E 02 5E 141 8D 609 0261 02 61 142 8E 612 0263 02 63 143 8F 615 0266 02 66 144 90 618 0269 02 69 145 91 620 026C 02 6C 146 92 623 026F 02 eF 147 93 626 0272 02 72 148 94 629 0274 02 74 149 95 632 0277 02 77 150 96 635 027 02 7 151 97 638 0270 02 7D 152 98 640 0280 02 80 153 99 643 0283 02 83 154 9A 646 0286 02 86 155 9B 649 0288 02 88 156 9C 652 028B 02 8B 157 9D 655 028 02 8E 158 9 657 0291 02 91 159 OF 660 0294 02 94 160 AO 663 0297 02 97 161 1 666 0299 02 99 162 2 669 029 02 9C 163 A3 672 029F 02 9F 164 A4 674 02A2 02 A2 165 A5 677 02A5 02 A5 166 A6 680 02A8 02 A8 167 A7 683 02 02 168 8 686 02AD 02 AD 169 A9 689 02 0 02 BO 170 AA 692 02B3 02 B3 171 AB 694 02B6 02 B6 172 AC 697 02B9 02 B9 173 AD 700 02 02 174 703 02 02 74 175 706 02 1 02 1 176 BO 709 02C4 02 177 711 02C7 02 C7 178 B2 714 02CA 02 CA 179 B3 717 02 CD 180 B4 720 02D0 02 DO Sine and Cosine tables The sine and cosi
5. 6 oureur OSCILLOSCOPE X INPUT v 5 BALANCE 45V Chips Used DAC0832LCN D A Converter amp LF356N Op Amp 69 SBC IOR SBC SBC PC1 SBC PCO e SRC 2 SBC SBC 5 BALANCE 1 N 8 NC 15V OPAMP T 6 pUTPUT OSCILLOSCOPE Y INPUT INPUT 2 V 4 5 BALANCE 15 Chips Used DAC0832LCN D A Converter amp LF356N Amp Servo Motor Speaker and Oscilloscope Z input OSCILLOSCOPE PORT B BIT BIT SBC BOARD PORT C 6 70 APPENDIX C LOOK UP TABLES Reload High and Reload Low tables The following shows the reload high table and reload low table tables which use the angle as offset to retrieve the corresponding reload value for each angle to put into the timer for rotating to that angle angle angle reload value reload value reload high reload low _ offset hex decimal hexadecimal table entry table entry 000 00 208 00DO 00 DO 001 01 211 00D2 00 D2 002 02 214 00D5 00 D5 003 03 217 00D8 00 D8 004 04 219 00DB 00 DB 005 05 222 00DE 00 DE 006 06 225 00E1 00 E1 007 07 228 00E3 00 008 08 231 00 6 00 E6 009 09 234 00 9 00 9 010 236 00 00 011 0B 239 OOEF 00 EF 012 0 242 00F2 00 F2 013 00 245 0024 00 014 0 248 00F7 00 F7 015 251 OOFA 00 FA 016 10 254
6. 0 00 0 01 0 01 0 01 0 01 0 01 0 01 0 02 0 02 0 02 0 02 67 0 00 0 01 0 01 0 01 0 01 0 01 0 01 0 02 0 02 0 02 0 02 0x0 0x01 0x01 0x01 0x01 0x01 0x01 0x0 0x0 0x0 0x0 0 2 2 2 2 0x0 0x01 0x01 0x01 0x01 0x01 0x01 0x0 0x0 0x0 0x0 0 2 2 2 2 0x0 0x01 0x01 0x01 0x01 0x01 0x01 0x0 0x0 0x0 0x0 0 2 2 2 2 0x00 0x01 0x01 0x01 0x01 0x01 0x02 0x02 0x02 0x02 0x02 0x00 0x01 0x01 0x01 0x01 0x01 0 02 0 02 0 02 0 02 0 02 APPENDIX CIRCUIT DIAGRAMS Block Diagram of Complete System SBC BOARD PC6 OSCILLOSCOPE IR SENSOR SERVO MOTOR SPEAKER IR APPARATUS Please note Arrows indicate data flow Shaded lines indicate digital data Black lines indicate analogue data 68 IR Sensor and ADC Connections AtoD Vipit Converter Vner 2 D GND Chips Used ADC0804LCN A D Converter DACs OpAmps and Oscilloscope X amp Y inputs GND ER e 20 SBC GND GND 4 SBC IOR SBC PB2 DI 4 SBC PB1 02 5 EX SBC PB3 SBC PBO Dc SBC PB4 sv GND Dioj gt SBC PB5 VREF 8 SBC PB6 9 BALANCE 1 w 8 NC 15V OPAMP I INPUT 2
7. turn beam off out X a ld a cpl and 0x3F make sure servo and speaker bit unaffected out Y a call beam_on call beam_off inc b ld 0 00 jp nz downline upline draws a line at 135degrees grad 1 from 40 0 to ld 0 80 turn beam off out X a ld a cpl and 0x3F make sure servo and speaker bit unaffected out Y a call beam_on nop 47 call beam_off inc b inc ld a cp Ox3F jp nz upline call beam off pointer draws a line of radius 10 at angle given ld a 0 01 initialise radius at 1 ld radius a linept ld a radius call get coords get oscilloscope co ordinates for angle radius call plot point plot point on oscilloscope ld a radius inc a ld radius a cp OxOB keep plotting points at angle radius until radius gt 10 jp nz linept ret show profile displays profile of object scanned by profiler call plotoutline plots outline showing extreme points and sweep able region ld a 0 2 start with angle at 45 ld angle a nextpoint get x coordinate for point at angle using 00 as start address and angle as offset ld a angle l a h OxFA a hl x coord a get y coordinate for point at angle using F900 as start address and angle as offset ld b a ld a x coord add a b a x coord coord cp 0x00 jp z endplot 4
8. Ox3E 0x41 0x44 0x47 Ox4A Ox4D 0x50 0x52 0x55 0x58 0 5 5 0x63 0x66 0x69 0 6 Ox6F 0x72 0x74 0x77 Ox7A Ox7D 0x80 0x83 0x86 0x88 Ox8B 0x91 0x94 0x97 0x99 0 9 Ox9F 2 5 OxA8 OxAB OxAD OxBO OxB3 OxB6 0 9 OxBE 1 OxC4 OxC7 OxCA OxCD 0 reload_high table table mapping each angle to the required high reload register put into timer0 to rotate the servo to that angle 0x00 value byte 0x00 byte 0x01 byte 0 01 byt 0x01 byte 0 01 byte 0 01 byte 0 02 byte 0x02 byte 0 02 byte 0 02 byte 0 02 byte Or to be 0x00 0x00 0x00 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x02 0x02 0x02 0x02 0x02 0x02 0x02 0x02 0x02 0x02 0x00 0x00 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x02 0x02 0x02 0x02 0x02 0x02 0x02 0x02 0x02 0x02 f 0x0 0x01 0x01 0x01 0x01 0x01 0x01 0x0 0x0 0x0 0x0 0x0 0 2 2 2 2 2 0x01 0x01 0x01 0x01 0x01 0x01 0 02 0 02 0 02 0 02 0 02 0 00 0 01 0 01 0 01 0 01 0 01 0 01 0 02 0 02 0 02 0 02 0 02 0 0 0 01 0 01 0 01 0 01 0 01 0 01 0 0 0 0 0 0 0 0 0 2 2 2 2
9. but unfortunately this would take too much space and be too complicated to be legible at all Procedure Description Modules Called parameters parameters main_menu Displays the main menu options Checks clear value of mode then runs appropriate display_menu subroutine 1 radar 2 tracker radar 3 profiler tracker profiler radar Performs the radar mode init_angle45 enable_servo_timer servo_delay_full disable_servo_timer rotate_to_angle angle get_distance clear display_radar_mode display_angle angle plot_outline mode get_coords angle distance plot_point x_coord y_coord beam_on beam_off display_angle_distance angle distance make_sound tracker Performs the tracker mode init angleO servo delay full rotate to angle angle get distance clear display tracker seeking display tracker locked display angle distance angle distance plot outline mode get coords angle distance plot point x coord y coord beam on beam off make sound show profile profiler Performs the profiler mode init angle45 enable servo timer servo_delay_full disable_servo_timer rotate_to_angle angle get_distance clear display_radar_mode display_angle_distance angle distance plot_outline mode get_coords angle distance plot_point x_coord y_coord beam_on beam_off make_sound show profile show profile Uses data from profiler which enters values into the x coords
10. which mode menu ei mode being changed by keypad int enable interrupt to allow keys on pad being pressed and ld a mode loop around if mode 0 cp 0x00 jp z menu ld a mode run radar mode if mode 1 cp 0x01 jp z radar ld a mode run tracker mode if mode 2 cp 0x02 jp z tracker ld a mode run profiler mode if mode 3 cp 0x03 jp z profiler jp menu radar start of radar mode call init angle45 set servo to start sweep at 45degrees call enable servo timer run servo timer starting rotation call clear clear lcd call display_rotating lcd displays message saying servo rotating call delay_servo_full allow servo enough delay to rotate to 45degrees 1 0x40 initialising last object detected at 0x40 infinty ld objdis radar_loop ld a mode if mode changed return to main menu cp 0 01 jp nz main menu call clear clear lcd call get_distance calculate current distance and put it in distance call display_radar_mode lcd displays message indicating radar mode call display_angle lcd displays angle of servo ld a distance if distance gt 60 then there is no object detected cp 0x3C jp z checkblank ld b b current distance ld objdis previous central distance of current object cp b prev distance current distance jp c checkblank 38 ld distance l
11. 0 11 stores current angle of servo or point being plotted tangle OxFC12 temporarily holds angle for conversion number OxFC17 number in binary to be passed to procedure display_bin_to_dec as parameter x coord 0xFC18 holds x coordinate of point converted from polar to cartesian by get coords coord 0xFC19 holds y coordinate of point converted from polar to cartesian by get coords mode stores current mode 1 Radar 2 Tracker 3 Profiler midangle OxFC35 stores middle angle in tracker mode before checking left or right middistance OxFC80 stores distance at the middle angle in tracker mode objang OxFC26 stores angle at which centre of last object in radar mode was detected objdis OxFC25 stores distance at which centre of last object in radar mode was detected FE AE HE HE HE FE TE HE HE HE HE FE FE FE E HE HE HE FE FE HE HE HE HE HE FE FE HE HE HE HE FE FE FE HE HE HE FE FE FE FE E HE HE HE FE FE HE HE HE HE FE TE FE HE HE HE HE FE FE TE HE HE HE FE TE FE E HE HE FE FE EE E E E E E EEEE H E main call init_port initialise ports such that A input B output C output call init_vector_table initialise vector table for interrupts 1 a 0x00 sets mode to 0 menu initially ld mode main menu 37 11 clear lcd screen call display menu lcd displays message showing which key to press for
12. 1 b 0x00 19 ld hl distance table add hl bc ld a hl ld distance a ret display angle f displays current angle on lcd ld a angle ld number a call display_bin to dec ld OxDF out lcd_out call plotoutline ret display angle distance call display angle displ f displ f displ f displ ays ays ays ays 52 angle in decimal degree sign ang ang le distance cartesian co ordinates Le ld a distance if distance gt 64 then do not display anything else cp 0x40 jp nc endofdisplay ld a 0 14 displays space out lcd out a call plotoutline ld a distance displays distance in decimal ld number a call display bin to dec ld a 0x63 displays cm out lcd out a call delay keypad ld 0 6 out lcd out a call delay_keypad ld a Ox14 out lcd out a call delay_keypad ld a Ox14 out lcd out a call delay_keypad call get_coords ld a cp 0x40 jp c xpos xneg if x coord lt 64 then display 64 x coord negative ld a Ox2D display out lcd out a call delay keypad ld a x coord cpl inc a a x coord 2C add 0x40 a x coord 64 jp showx if x coord gt 64 then display x coord 64 ld a x coord sub 0x40 a x coord 64 showx ld number a display cartesian x coord call display bin to
13. 157 9D 14 OE 204 10 OA 253 64 40 158 9E 14 205 CD 10 0A 254 FE 64 40 159 9F 14 206 CE 10 0A 255 FF 64 40 160 A0 14 OE 207 CF 10 0A 208 00 10 209 D1 10 0A 78 BIBLIOGRAPHY University of York Computer Science Department Microcomputer Communications Project Module Website by Nick Pears http www course cs york ac uk mcp DC Power Supply GPC M Series Analogue Digital Type GW Instek User Manual GOS 6xxG Family Dual Trace Oscilloscope GW Instek User Manual Zilog Z80 Family CPY User Manual UM0080020202 The National Semiconductor Website www national com for chip datasheets Farnell InOne Website www farnell com for chip costing Please note that some of the hardware diagrams in Appendix B are modified versions of those found in the National Semiconductor Website s datasheets for certain chips 19
14. OOFD 00 FD 017 11 256 0100 01 00 018 12 259 0103 01 03 019 13 262 0106 01 06 020 14 265 0108 01 08 021 15 268 010 01 022 16 271 010 01 0 023 17 273 0111 01 11 024 18 276 0114 01 14 025 19 279 0117 01 17 026 1 282 0119 01 19 027 1 285 011 01 1 028 1 288 011 01 1 029 1 290 0122 01 22 030 1 293 0125 01 25 031 1 296 0128 01 28 032 20 299 012 01 2 033 21 302 0120 01 034 22 305 0130 01 30 035 23 308 0133 01 33 036 24 310 0136 01 36 71 037 25 313 0139 01 39 038 26 316 013C 01 3C 039 27 319 013E 01 3E 040 28 322 0141 01 41 041 29 325 0144 01 44 042 2A 327 0147 01 47 043 2B 330 014A 01 4A 044 2C 333 014D 01 4D 045 2D 336 0150 01 50 046 2E 339 0152 01 52 047 2F 342 0155 01 55 048 30 345 0158 01 58 049 31 347 015B 01 5B 050 32 350 015E 01 5E 051 33 353 0161 01 61 052 34 356 0163 01 63 053 35 359 0166 01 66 054 36 362 0169 01 69 055 37 364 016C 01 6 056 38 367 016F 01 6F 057 39 370 0172 01 72 058 373 0174 01 74 059 3B 376 0177 01 77 060 3C 379 017A 01 7A 061 3D 382 017D 01 7D 062 3E 384 0180 01 80 063 3F 387 0183 01 83 064 40 390 0186 01 86 065 41 393 0188 01 88 066 42 396 018B 01 8B 067 43 399 018E 01 8E 068 44 401 0191 01 91 069 45 404 0194 01 94 070 46 407 0197 01 97 071 47 410 0199 01 99 072 48 413 019C 01 9C 073 49
15. Ox2C 0x70 OxAB OxD9 OxEE 1 OxF OxE D 9 OxFC OxFC OxFB OxE8 0 6 OxE4 OxE2 OxCC Ox9A Ox5B Ox16 0x30 0 74 OxDB OxC9 0x96 0x57 0 11 0 35 0 78 1 OxDD 0xC6 0x92 0x53 OxOD 0x39 0 7 OxB5 Oxc4 Ox8 F Ox4F 0x0 0x3 0x8 8 D 0 OxB8 OxC1 Ox8B Ox4A 0x04 0x42 0x83 OxBB OxBI Lu 0x87 0x46 0x00 0x46 0x87 OxBE OxBB 0x83 0x42 0x04 Ox4A Ox8B OxC1 OxB8 Ox7F Ox3D 0x08 Ox4F Ox8F 4 OxDF OxE 2 OxE4 0 6 OxE8 0 9 U byte OxF0 OxF2 OxFE OxFE OxFF OxF4 OxF6 byte OxFF OxFF distance table OxFF table OxFF storing distanc OxF 7 OxF8 OxF9 values for OxFC OxFC OxFD ach ADC reading using ADC reading as offset maps ADC readings to distances in cm byte 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 byte 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x40 0x4
16. dec ld 0 2 display out lcd_out a call delay_keypad showy display y coordinate ld y_coord ld number 32 call display bin to dec call delay keypad endofdisplay ret increase angle3 ld a angle angle angle 3 add a 0x03 ld angle a ret decrease angle3 ld a angle angle angle 3 sub 0x03 ld angle a ret increase angle ld a angle angle angle 1 inc a ld angle a ret decrease angle ld a angle angle angle 1 dec a ld angle a ret delay keypad give enough delay to print character on lcd push bc ld bc 0x00FF delay keypad loop do FFh no ops nop dec bc ld a 0x00 b je nz delay_keypad_loop pop bc ret get coords gets oscilloscope co ordinates for angle radius and puts it in x_coord and y_coord ld a 0x00 ld h ld 1 uses angle as offset to retrieve cosine value from cosine_table ld a angle ld 54 Tel gt ld b 0x00 add hl bc ld a hl radius mlt hl cosine ld a angle radius cp 0x5A 90 jp nc nonneg 1 Ld uses ld a Id h a nonneg ld a add a ld h 0x40 angle a le as offset to retriev cosine_table h cosine angle radius 1 fraction part number part angle chec
17. of angle set object central distance as 64 infinity i e if angle gt 135 re run radar rotate back to 45 and 39 next_angle call increase_angle if angle lt 135 increment angle and then rotate servo to that angle call rotate_to_angle radar_loop tracker main module for tracker mode call clear call beam_off seeker call init angleO set servo to start sweep at Odegrees call enable servo timer run servo timer starting rotation call clear clear lcd call display_rotating lcd displays message saying servo rotating call delay servo full allow servo enough delay to rotate to 45degrees seeker loop ld a mode cp 0x02 jp nz main menu call clear clear lcd screen call get distance calculate current distance and put it in distance call display tracker seeking lcd displays message indicating tracker seeking call display angle distance display current angle and distance read call plot outline call get coords call plot point 4 plot current reading on oscilloscope call beam on ld a distance 4 if object located at distance 30 then go to trackingmode cp 0 1 jp c tracker start change sangle if angle is gt 180 ld a angle cp OxB2 jp c next sangle jp seeker if angle gt 180 then restart seeker from 0 degrees next sangle call increase ang
18. points appeared on the oscilloscope and indeed they did not or at least they appear very lightly The get_coords procedure converted polar co ordinates to cartesian co ordinates rather polar to oscilloscope co ordinates by looking up the sine and cosine tables for each angle and then multiplying them with distances I wrote a simply test program which stored these x and y coordinates in memory and checked whether get_coords works by running the program on the ZIM emulator for the Z80 I then wrote the display_angle_distance which displayed current angle distance x and y coordinates on the LCD displays and this seemed fine for all test values to I later used plot_point to plot some points on the oscilloscope A more comprehensive test was carried out I suppose when I wrote a procedure that starts with a certain distance and plots 26 points for angles to 180 degrees and then increments the distance plot points for angles 0 to 180 degrees and so on This gave images of semicircles of increasing radii on the oscilloscope with the beam moving clockwise which is exactly what we would expect LCD details of some points while plotting semi circles 008 10cm 10 00 608 40cm 20 35 140 45cm 35 29 308 10cm 08 05 758 40cm 10 39 150 45cm 40 22 608 10cm 05 09 908 40cm 00 40 160 45cm 43 15 908 10cm 00 10 105M 40cm 11 39 1708 45cm 45 08 1208 10cm 05 09 1208 40cm 20 35 180 45cm 45 00 150 10cm 09 05 135M 40cm 29 28 180 10cm 10 00 150M 40c
19. rightdis gt middis then object has not moved to if rightdis lt middis then object moved to right set check to the right again T T T T T T checking if object moved to left if angle lt 3 do not check left angle midangle 3 enable timer allow servo time to rotate to read current distance into distance b middistance a leftdistance a b leftdis middis if leftdis gt middis then object has not moved to if leftdis lt leftdis then object moved to right set check to the right again T display_tracker_locked display_angle_distance T T if mode changed via keypad then return to main clears lcd display message saying tracker locked display angle distance cartesian show sweep able region on oscilloscope get oscilloscope co ordinates for plot point showing current angle distance on make sound indicating distance from sensor show sweep able region on oscilloscope get oscilloscope co ordinates for plot point showing current angle distance on set servo to start sweep at 45degrees run servo timer starting rotation 42 call clear clear lcd call display_rotating lcd displays message saying servo rotating call delay_servo_full allow servo enough delay to rotate to 45degrees ld a 0x40 initialising last object detected at 0x40 infinty ld objdis profiler loop ld a mode if mode cha
20. tried several angles and then later sweeps slowly increasing the angle after a short period of time to check whether the motor worked properly and whether in fact the lookup tables generated using linear regression was right and as expected everything was fine Finally after each sweep between certain angles I made it rotate back to its start angle and repeat the sweep Speaker Testing The speaker was initially tested by feeding its timer different reload values just to check whether it made a sound and later a speaker test was added to the IR sensor test program such that the speaker made a sound depending on the distance read this was done by putting the ADC value read into the speaker timer s reload register This made a very distinct sound at different distances however the program seemed to crash when the object was too far away this was because when the ADC value was too small the frequency was too high and the speaker timer generated too many interrupts thus stopping the rest of the program from executing This problem was fixed by doing an OR 0x10 on the ADC value before putting it into the speaker timer Oscilloscope Cartesian Coordinates Testing I started off by first writing a procedure that made simple shapes such as boxes or lines appear on the oscilloscope using preset x and y co ordinates using the plot_point procedure The z input was checked by switching the beam off for certain points and later seeing whether these
21. unused int keypad int interrupt 1 generated by keypad key press int servo timer toggle interrupt 2 generated by timer0 servo timer int speaker timer toggle interrupt 3 generated by timerl speaker timer 5 5 6 MEMORY LOCATIONS DECLARED FOR VARIABLES CONTROL REGISTERS ETC aaa HH EE HH stores current distance read radius in polar co ordinates to be passed to procedure distance OxFC10 radius OxFC15 get_coords as parameter lcd out 0xB9 output for lcd screen in ASCII keypad in 0 4 input from keypad ADC OxBO port A connected to ADC X 0 1 port B connected to Z and X inputs Y 0 2 port C connected to servo speaker and Y inputs CSR OxB3 command status register rr_high0 high reload register for timer 0 controlling servo rr_low0 OxOE low reload register for timer 0 controlling servo rr_highl 0x17 high reload register for timer 1 controlling speaker rr_lowl 0x16 low reload register for timer 1 controlling speaker TCR 0x10 timer control register used to enable timers 0 amp 1 TDRO 0x0C lower byte of timer data register for timer 0 TDR1 0x14 lower byte of timer data register for timer 1 IVLR 0x33 interrupt vector low register ITCR 0x34 interrupt trap control register angle
22. used to calculate the x and y inputs of the oscilloscope 20 IR Reading Motor Setting radius angle 0 lt lt 90 Calculated Oscilloscope Inputs x input 64 y input 64 r cos a vY RCTV r cos 180 a IR Reading Motor Setting r cos a radius r angle Ky 90 lt a lt 180 rsin 180 a Calculated r sin a Oscilloscope Inputs 90 lt a lt 180 x input 64 r cos a y input n i The only alternative to storing the sine and cosine values in tables would be to actually have a function that calculates sine and cosine values using Taylor expansions for sine and cosine which like almost everything else are simply too difficult and time consuming to program in assembly There was also the incredibly insane idea of using two dimensional tables one each for sine and cosine which mapped distances and sine cosine values to their multiplicands or the Cartesian co ordinates however we were not given that much memory to work with Radar I faced one particular problem when detecting objects in radar mode The cylindrical tubes we were provided with gave proper readings of distances only the sensor detected the centre of the tubes E g an object at 20cm and 90 degrees would be read so only at 90 degrees however at 92 or 88 degrees which are the circular edges of the tube a distance r
23. y co ordinates polar co ordinates angle of sensor and distance read had to be converted into cartesian co ordinates For this please see details on the get_coords module in the software modules section as well as the section on Design Implementation The Speaker The speaker is controlled in a very similar way as the servo motor is The processor has another timer which can generate interrupts at a regular interval depending on the value put into its high and low reload registers At each interval the speaker bit bit6 on portC is flipped giving a sound of a frequency dependent on the reload registers In all cases we are supposed to make a sound depending on the distance between the sensor and the object This can be done by simply putting the ADC data read from the sensor from portA into the reload low register of timerl I found that the sound is very different for objects at different distances which is exactly what was required Soflware Overview I decided to do a sweep of about 90 degrees starting at 45 degrees and ending at 135 degrees at every one degree for the profiler and radar modes However for the tracker mode I decided to leave the range of angles between 0 and 180 since tracking something in a smaller range of angles just seems pointless The following shows a list of all modules in the program along with brief descriptions of what they do I would have preferred to draw a diagram showing the relationships between modules
24. 0 OxOB 0 0 f table mapping each angl 9 0x0B Ox0A Ox0A 0x09 Ox0B 0 09 0 09 0x0 B 0x0A 0x0 0x0 9 9 OxOB Ox0A 0x09 0x09 OxOB 0 09 0 40 Ox0A Ox0A Ox0 Ox4 9 0 0 0 0 0 0 4 9 0 0 0 0 0 0 0 0 4 9 0 Ox0A 0x09 0x40 0 09 0 40 le to the required low reload register to be put into timer0 to rotate the servo to that angle OxDO OxD2 0 05 OxD8 OxDB OxDE OxE1 OxE3 OxE6 OxE9 OxEC OxEF OxF2 OxF7 OxFA OxFD 0x00 0x03 0x06 0x08 OxOB OxOE 0x11 0x14 0x17 0x19 0 1 0x25 0x28 Ox2B Ox2D 0x30 0x33 0x36 0x39 Ox3C Ox3E 0x41 0x44 0x47 Ox4A Ox4D 0x52 0x55 0x58 Ox5B Ox5E 0x61 0x63 0x66 0x69 Ox6C Ox6F 0x72 0x74 0x77 Ox7A 0x80 0x83 0x86 0x88 Ox8B Ox8E 0x91 0x94 0x97 0x99 0x9C Ox9F OxA2 5 OxA8 OxAD OxBO OxB3 OxB6 OxB9 OxBC OxBE OxC1 4 0 7 OxCA OxCD 0 00 OxD2 OxD5 OxDB OxDE 0 1 OxE3 OxE6 OxE9 OxEC OxEF OxF2 0 4 OxF7 OxFA OxFD 0x00 0x03 0x08 OxOB OxOE 0x11 0x14 0x17 0x19 Ox1C 0x1F 0x22 0x25 0x28 0 2 Ox2D 0x30 0x36 0x39
25. 0 b turns timer0 which is the servo motor input off turns timerl which is the speaker input on turns timerl which is the speaker output on gives servo enough delay for a full 180 or 90 degree do FFFFh nop s jp nz full delay loop pop bc EEE get_distance ld 1 0x00 ld h 0x00 ld b 0x00 in a ADC ldc a cp 0x28 detected jp c nothingthere add hl bc reads ADC value converts it to distance reads ADC data adds it to hl if ADC value lt 0x28 distance gt 64 it means nothing was in a ADC reads ADC data adds it to hl ld cp 0x28 jp c nothingthere add hl bc 51 ADC reads ADC data ld 0 28 if ADC value lt 0x28 detected jp nothingthere add hl bc in a ADC reads ADC data 19 0 28 if ADC value lt 0x28 detected jp nothingthere add hl bc hl contains sum of four ADC readings using shifts such that a average ADC value G b o ld 1 or h jp endget 1 4 1 adds it to hl distance gt 64 it means nothing was adds it to hl distance gt 64 it means nothing was a 2 LSB of h and 6 MSB of 1 nothingthere if nothing detected once set average ADC value to 0x00 1 0x00 endget use distance_table and average ADC value as offset to get distance and put it in distance
26. 0 byte 0x40 0x40 0x40 0x40 0x40 0x40 Ox3F Ox3E 0x3D 0 3 0 3 Ox3A 0x39 0x38 0x37 0x36 byte 0x35 0x34 0x33 0x32 0x31 0x30 Ox2F Ox2E Ox2E 0x2D 0 2 0 2 0x2B Ox2A Ox2A 0x28 byte 0x27 0x26 0x25 0x25 0x24 0x24 0x23 0x23 0x22 0x22 0x21 0x21 0x20 0x20 1 0 1 byte OxlF Ox1E Ox1E 0 1 0 1 Ox1D 0 1 Ox1C Ox1C 0 0 Ox1B Ox1A 0 19 0 19 byte 0x19 0x18 0x18 0x18 0x18 0 17 0 17 0 17 0 17 0 16 0 16 0 16 0 16 0x15 0x15 0 15 byte 0x15 0x14 0x14 0x14 0x14 0x14 0x13 0x13 0x13 0x13 0x13 0x13 0x13 0x12 0x12 0x12 byte 0x12 0x12 0x12 0x11 0x11 0x11 0x11 0x11 0x11 0x10 0x10 0x10 0x10 0x10 0x10 0x10 byte 0x10 OxOF OxOF OxOF OxOF OxOF OxOF OxOF OxOF OxOF OxOE OxOE OxOE OxOE OxOE OxOE byte OxOE OxOE OxOE OxOE OxOE 0 00 0 00 OxOD OxOD OxOD OxOD OxOD OxOD OxOD OxOD OxOD byte OxOD 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0x0C 0 0 0 0 OxOC 66 byte byte byte 0x09 byte 0x40 reload_low_table value byte OxF4 byte 0x22 byte 0x50 byte Ox7D byte OxAB byte OxD8 byte 0 06 byte 0x33 byte Ox6l byte Ox8E byte OxBC byte Ox0C 0x0A 0x0A 0x0A 0x09 0x09 0x40 Ox0C Ox0A Ox0A Ox0A Ox0A 0x09 0x09 0x4
27. 00 ld hl a 43 change_pangle ld a angle f if angle lt 135 then increment angle and keep sweeping cp 0x87 jp c next_pangle imager f if angle gt 135 show profile ei allow mode to be changed via keypad interrupt call show profile display profile of object swept di ld a mode if mode changed go to main menu cp 0x03 jp nz main menu jp imager next_pangle call increase angle if angle lt 135 increment angle and then rotate servo to that angle call rotate_to angle jp profiler loop keypad int interrupt routine if key on keypad pressed changes mode according to key pressed in a keypad in ld a 0x00 initially set mode as 0 menu mode ld mode a in a keypad in read data from keypad indicating which key pressed converts keypad data into integers 1 for 1 pressed 2 for 2 pressed 3 for 3 pressed sub OxOF cp 0x00 if key pressed is between 1 and 3 set mode to key otherwise leave mode as 1 jp z end keypad int cp 0x04 jp nc end keypad int ld mode a end keypad int 44 reti clear clears LCD ld a 0 01 out 0xB8 a sends command to LCD control to clear LCD call delay servo short allows enough delay to clear screen ret make sound uses speaker to make sound indicating current distance reading puts in ADC data or 0x10 into reload registers so that frequency is indic
28. 047 0 73 BB 0 68 AE 048 0 74 BE 0 67 AB 049 0 75 C1 0 66 AT 050 0 77 C4 0 64 A4 051 0 78 C6 0 63 A1 052 0 79 C9 0 62 9D 053 0 80 CC 0 60 9A 054 0 81 CF 0 59 96 055 0 82 D1 0 57 92 056 0 83 D4 0 56 8F 057 0 84 D6 0 54 8B 058 0 85 D9 0 53 87 059 0 86 DB 0 51 83 060 0 87 DD 0 50 7 061 0 87 DF 0 48 7 062 0 88 2 0 47 78 063 0 89 4 0 45 74 064 0 90 E6 0 44 70 065 0 91 E8 0 42 6C 066 0 91 9 0 41 68 067 0 92 0 39 63 068 0 93 ED 0 37 5F 069 0 93 EF 0 36 5B 070 0 94 FO 0 34 57 071 0 95 F2 0 33 53 072 0 95 0 31 4 073 0 96 0 29 4 074 0 96 F6 0 28 46 075 0 97 F7 0 26 42 076 0 97 F8 0 24 3D 077 0 97 F9 0 22 39 078 0 98 FA 0 21 35 079 0 98 FB 0 19 30 080 0 98 FC 0 17 2C 081 0 99 FC 0 16 28 082 0 99 FD 0 14 23 083 0 99 FE 0 12 1F 084 0 99 FE 0 10 1A 085 1 00 FF 0 09 16 086 1 00 FF 0 07 11 087 1 00 FF 0 05 00 088 1 00 0 03 08 089 1 00 0 02 04 090 1 00 0 00 00 091 1 00 0 02 04 092 1 00 0 04 08 093 1 00 0 05 00 094 1 00 0 07 11 095 1 00 0 09 16 096 0 99 0 10 1 097 0 99 0 12 1 098 0 99 0 14 23 099 0 99 0 16 28 100 0 98 0 17 2 101 0 98 0 19 30 102 0 98 0 21 35 103 0 97 F9 0 23 39 104 0 97 F8 0 24 3D 105 0 97 F7 0 26 42 106 0 96 F6 0 28 46 107 0 96 F4 0 29 4
29. 0x52 call display character ld a 0 41 call display character ld a 0x43 call display character ld a Ox4B call display character ld a 0x45 call display character ld a 0x52 call display character ld a Ox2D call display character ld a 0x53 call display character ld a 0x45 call display character ld a 0x45 call display character ld a Ox4B call display character ld a 0x49 call display character ld a 0 4 call display character 1 0 47 call display_character ld a 0x20 call display_character call display_character call display_character call display_character 60 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 ret disp disp disp disp disp disp disp disp disp disp disp disp disp disp disp disp disp disp disp disp disp ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character display tracker locked ff display TRACKER LOCR
30. 1 00 0 0 000 32 32 32 32 32 32 32 00 0 0 000 33 33 33 34 33 33 33 20 1 0 400 34 34 35 34 33 34 34 00 1 0 632 35 35 34 34 34 35 34 40 1 0 490 36 36 36 36 36 36 36 00 0 0 000 37 37 37 38 37 38 37 40 1 0 490 38 38 38 38 37 39 38 00 1 0 632 39 39 39 40 40 38 39 20 1 0 748 40 41 40 41 39 40 40 20 1 0 748 41 41 41 42 42 42 41 60 1 0 490 42 42 41 43 42 41 41 80 1 0 748 43 43 45 42 42 44 43 20 2 1 166 44 44 44 43 46 45 44 40 2 1 020 45 46 45 45 45 45 45 20 1 0 400 46 46 47 46 45 47 46 20 1 0 748 47 45 47 48 47 47 46 80 2 0 980 48 49 48 48 48 50 48 60 2 0 800 49 49 49 50 49 50 49 40 1 0 490 50 50 50 50 50 51 50 20 1 0 400 51 51 51 52 51 51 51 20 1 0 400 52 52 5 50 52 5 52 00 2 1 095 5 5 53 55 52 50 52 60 3 1 625 25 54 54 55 54 52 55 54 00 2 1 095 55 56 55 57 54 57 55 80 2 1 166 56 57 53 58 56 57 56 20 3 1 720 57 58 60 56 56 59 57 80 3 1 600 58 59 58 60 57 59 58 60 2 1 020 99 60 61 57 62 59 59 80 3 1 720 60 62 59 63 60 59 60 60 3 1 625 61 64 58 58 62 57 59 80 4 2 713 62 62 59 60 63 63 64 62 64 60 62 N Nothing detected Servo Motor Testing The increase decrease angle procedures along with the rotate_to_angle procedures were used to rotate the sensor to different angles The rotate_to_angle procedure uses the reload lookup tables to put an appropriate value into the timer such that the required pulse is produced I
31. 2 OxDF OxDD OxDB 0 09 OxD6 OxD4 OxD1 OxCF OxCC 65 byte 0xC9 1 Ox9D 0x99 byte 0x96 0x92 0x63 Ox5F Ox5B byte 0x57 0x53 OxlF Ox1A 0x16 byte 0 11 0 00 cosine table offset maps angles to cosine values before MSB 4 Ox8F Ox4F 0x08 OxC1 Ox8B Ox4A 0x04 OxBE 0x87 0x46 0x00 table storing OxBB OxB8 0x83 0x42 cosine val Ox7F Ox3D OxB4 0 7 0x39 1 0 78 0x3 5 OxAE 0x74 0x30 OxAB 0x70 Ox2C OxA7 Ox6C 0x27 OxA4 0x68 0x23 ues for each angle using angle as in fixed point binary fractions binary point byte OxFF OxF9 OxF8 OxF7 OxFF OxFF OxFF OxF F OxFE OxFE byte OxF6 OxF4 OxDF OxDD OxDB byte OxD9 OxD6 OxB5 OxBl OxAE byte OxAB OxA7 0 7 0x78 0x74 byte 0x70 Ox6C 0x39 0x35 0x30 byte 0 2 0x28 OxOD 0x11 0x16 byte Ox1A 0x53 0x57 Ox5B byte Ox5F 0x64 0x92 0x96 9 byte Ox9D 1 OxC7 9 OxCC byte OxCF OxD1 OxEB OxED OxD4 OxA4 0x68 0x23 0x23 0x68 OxA4 OxD4 OxF2 OxD1 1 0x63 Ox1F 0x28 Ox6C 8 OxD6 OxFO OxCF Ox9D Ox5F Ox1A
32. 40 049 81 52 84 087 57 28 1C 012 oc 64 40 050 32 51 33 088 58 28 1C 013 0D 64 40 051 33 50 32 089 59 27 1B 014 64 40 052 34 49 31 090 5 27 1B 015 oF 64 40 053 35 48 30 091 58 27 1B 016 10 64 40 054 36 47 2F 092 5 26 1 017 11 64 40 055 37 46 2E 093 5D 26 1A 018 12 64 40 056 38 46 2E 094 25 19 019 13 64 40 057 39 45 20 095 5F 25 19 020 14 64 40 058 44 2C 096 60 25 19 021 15 64 40 059 3B 44 2C 097 61 24 18 022 16 64 40 060 3C 43 2B 098 62 24 18 023 17 64 40 061 30 42 2 099 63 24 18 024 18 64 40 062 42 2 100 64 24 18 025 19 64 40 063 40 28 101 65 23 17 026 1A 64 40 064 40 39 27 102 66 23 17 027 1B 64 40 065 41 38 26 103 67 23 17 028 1c 64 40 066 42 37 25 104 68 23 17 029 1D 64 40 067 43 37 25 105 69 22 16 030 64 40 068 44 36 24 106 6A 22 16 031 1 64 40 069 45 36 24 107 6B 22 16 032 20 64 40 070 46 35 23 108 6c 22 16 083 21 64 40 071 47 85 23 109 6D 21 15 034 22 64 40 072 48 34 22 110 6E 21 15 035 23 64 40 073 49 34 22 111 6F 21 15 036 24 64 40 074 4A 33 21 112 70 21 15 037 25 64 40 0
33. 416 019F 01 9F 074 4A 418 01A2 01 A2 075 4B 421 01A5 01 A5 076 4C 424 01A8 01 A8 077 4D 427 01AB 01 AB 078 4E 430 01AD 01 AD 079 4F 433 01 0 01 BO 080 50 436 01B3 01 B3 081 51 438 01 6 01 6 082 52 441 01 9 01 B9 12 083 53 444 01 01 084 54 447 01 01 085 55 450 01C1 01 1 086 56 453 01 4 01 087 57 455 01 7 01 7 088 58 458 01 01 089 59 461 01CD 01 CD 090 5A 464 01DO 01 DO 091 5B 467 01D2 01 D2 092 5C 470 01D5 01 D5 093 5D 473 0108 01 08 094 475 01DB 01 DB 095 5F 478 01DE 01 DE 096 60 481 01 1 01 1 097 61 484 01E3 01 E3 098 62 487 01 6 01 E6 099 63 490 01E9 01 E9 100 64 492 01EC 01 EC 101 65 495 01 EF 102 66 498 01F2 01 F2 103 67 501 01 4 01 F4 104 68 504 01F7 01 F7 105 69 507 01 01 106 6 510 01FD 01 FD 107 eB 512 0200 02 00 108 6 515 0203 02 03 109 6D 518 0206 02 06 110 6E 521 0208 02 08 111 6F 524 020 02 112 70 527 020 02 0 113 71 529 0211 02 11 114 72 532 0214 02 14 115 73 535 0217 02 17 116 74 538 0219 02 19 117 75 541 021C 02 1C 118 76 544 021F 02 1F 119 77 546 0222 02 22 120 78 549 0225 02 25 121 79 552 0228 02 28 122 555 022 02 2B 123 7B 558 022D 02 2D 124 7 561 0230 02 30 125 7D 564 0233 02 33 126 566 0236 02 36 127 7F 569 0239 02 39 128 80 572 023C 02 3C
34. 75 48 33 21 113 71 20 14 77 ADC Table ADC Distance Table ADC Table Reading Hex Distance entry Reading Hex om entry Reading Hex Distance entry decima Reading cm hex decima Reading hex decima Reading hex 1144 72 20 14 161 Al 14 210 D2 10 oA 115 73 20 14 162 A2 14 211 D3 10 oA 116 74 20 14 163 14 222 10 0 117 75 20 14 164 4 14 213 05 10 OA 118 76 19 13 165 A5 13 OD 214 De 10 OA 119 77 19 13 166 A6 13 OD 215 D7 10 OA 120 78 19 13 167 A7 13 OD 216 08 10 OA 121 79 19 13 168 A8 13 OD 217 D9 10 OA 122 7A 19 13 169 A9 13 OD 218 DA 10 OA 123 7B 19 13 170 AA 13 OD 219 DB 10 OA 124 7 19 13 171 AB 13 00 220 DC to oA 125 7D 18 12 172 13 OD 221 DD 10 OA 126 7E 18 12 173 AD 13 OD 222 DE 10 OA 127 18 12 174 AE 13 OD 223 DF 10 OA 128 80 18 12 175 AF 13 OD 224 EO 10 OA 129 81 18 12 176 Bo 13 OD 225 E1 10 OA 130 82 18 12 177 B1 13 OD 226 2 10 OA 131 83 17 1 178 B2 12 227
35. 8 if x coord y coord are both not 0 i e x coord y coord not 0 then plot the point on oscilloscope otherwise simply go to next angle call plot point endplot ld a angle angle angle 1 inc ld angle ld a angle if angle lt 136 then show point for next angle otherwis ntir profile shown so exit sub 0x88 nextpoint rotate_to_angle loads timer0 with appropriate values for angle given and runs it for long enough for a 1 3 degree rotation ld hl reload high table f load high register value into timer for angle from the reload high table using angle as offset ld b 0x00 ld a angle ld add hl bc 1 1 ld out0 rr high0 ld hl reload_low_table load low register value into timer for angle from the reload_low_table using angle as offset 1 b 0x00 ld angle ldc a add hl bc ld a hl ld e a out0 rr_low0 call enable_servo_timer enables timer0 call delay_servo_short gives servo enough delay for 1 3 degree rotation call disable_servo_timer disables timer0 ret init_vector_table ld hl vector table lda h ld i setting up higher order vector byte a 1 and OxEO mask out the unused data out0 IVLR a enables interrupts that were previously disabled by default 49 0 ITCR 0 04 out0 ITCR 0 IVLR 0 04 out0 IVL
36. A 108 0 95 F3 0 31 4F 109 0 95 F2 0 33 53 110 0 94 FO 0 34 57 111 0 93 EE 0 36 5B 112 0 93 ED 0 37 5F 113 0 92 EB 0 39 64 114 0 91 E9 0 41 68 115 0 91 0 42 6 116 0 90 0 44 70 117 0 89 4 0 45 74 118 0 88 2 0 47 78 119 0 87 0 49 7 120 0 87 DU 0 50 80 121 0 86 DB 0 52 83 122 0 85 09 0 53 87 76 123 0 84 06 0 54 8 124 0 83 04 0 56 8 125 0 82 01 0 57 92 126 0 81 0 59 96 127 0 80 CC 0 60 9 128 0 79 9 0 62 9D 129 0 78 C6 0 63 A1 130 0 77 C4 0 64 A4 131 0 75 C1 0 66 A8 132 0 74 BE 0 67 AB 133 0 73 BB 0 68 AE 134 0 72 B8 0 69 1 135 0 71 4 0 71 5 136 0 69 1 0 72 B8 137 0 68 AE 0 73 BB 138 0 67 AB 0 74 BE 139 0 66 AT 0 75 C1 140 0 64 A4 0 77 C4 141 0 63 A1 0 78 C7 142 0 62 9D 0 79 9 143 0 60 99 0 80 144 0 59 96 0 81 145 0 57 92 0 82 01 146 0 56 8 0 83 04 147 0 54 8 0 84 06 148 0 53 87 0 85 09 149 0 51 83 0 86 150 0 50 0 87 DU 151 0 48 7 0 87 152 0 47 78 0 88 2 153 0 45 74 0 89 4 154 0 44 70 0 90 155 0 42 6 0 91 E8 156 0 41 68 0 91 E9 157 0 39 63 0 92 EB 158 0 37 0 93 ED 159 0 36 5B 0 93 EF 160 0 34 57 0 94 FO 161 0 33 53 0 95 F2 162 0 31 4F 0 95 F3 163 0 29 4A 0 96 F4 164 0 28 46 0 96 F6 165 0 26 42 0 97 F7 166 0 24 3D 0 97 F8 167 0 22 39 0 97 F9 168 0 21 35 0 98 F
37. A 169 0 19 30 0 98 FB 170 0 17 2C 0 98 FC 171 0 16 27 0 99 FC 172 0 14 23 0 99 FD 173 0 12 1F 0 99 FE 174 0 10 1 0 99 175 0 09 16 1 00 176 0 07 11 1 00 177 0 05 00 1 00 178 0 03 08 1 00 Distance Table Maps ADC readings from IR sensor to distances of object from sensor uses hex reading as offset 179 0 02 04 FF 180 0 00 00 1 00 1 00 FF ADC Table ADC Table ADC Table Reading Hex Distance entry Reading Hex Distance entry Reading Hex Distance entry decima Reading cm hex decima Reading cm hex decimal Reading cm hex 000 00 64 40 038 26 63 076 4C 32 20 001 01 64 40 039 27 62 077 40 32 20 002 02 64 40 040 28 61 078 4 31 1 03 64 40 041 29 60 3C 079 4F 81 1F 004 04 64 40 042 2A 59 3B 080 50 31 1 005 05 64 40 043 2B 58 081 51 30 1E 006 06 64 40 044 2 57 99 082 52 30 007 07 64 40 045 2D 56 38 083 53 30 08 08 64 40 046 2E 55 37 084 54 29 1D 009 09 64 40 047 2F 54 36 085 55 29 1D 010 oA 64 40 048 30 53 35 086 56 28 1C 011 0B 64
38. I 1 1 ld 0x54 call disp call a 0x5 2 call a disp 0x41 displ a 0 4 3 disp 0 4 disp B a 0 4 disp 5 0 5 disp 2 0 2 disp D 0 4 disp 0 4 disp E a 0 4 3 disp 0 4 disp B ED and go to next line ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character 61 1 1 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 1 0 45 disp call a 0x44 displ a 0x20 displ displ displ displ displ displ displ displ displ displ displ displ displ displ displ displ displ displ displ displ displ displ displ displ displ displ ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay
39. I had no idea why until later I found out that the ports were not responding at all 22 TESTING AND EVALUATION As you can see a more or less bottom up approach was used to put the system together Each component was first tested separately using separate test programs and then the entire program i e each of the operation modes was tested later Testing separate components Sensor Testing As explained earlier the sensor was calibrated by putting an object at distances between 10 and 60cm at every and then taking reading the value given by the ADC I had initially used LEDs to display these values but later I wrote a program which displayed the value in hex on the LCD display Three readings were taken at each distance and the average was taken forming a ADC reading to distance table please see tables in appendix A test procedure was written to check whether this works by simply incorporating the table into this test program and then using the get_distance module see Software modules to convert the ADC readings into distances which were displayed on the LCD I placed objects at different distances and took down values the LCD showed and checked whether the distance displayed was the same as the actual distance from the sensor the object was placed at I was very happy to see these readings were nearly perfect between 10 and 30cm had an error of 1 from 30 40cm 2 from 40 50 cm and about 4 from 50 60cm Th
40. Microcomputer Communications Project Assessment 2003 2004 Syedur Rahman TABLE CONTENTS Introduction 2 Overview of Hardware Software 3 Infra red sensor 4 Servo Motor 5 The Oscilloscope 6 The Speaker 6 Software Overview 6 Basic Overview of Each Mode of Operation 12 12 Profiler Mode 13 Tracker Mode PseudoCode for Other Important Modules 16 Design Implementation Details and Alternatives 19 Input Output 19 LookUp Tables and Arrays 19 Conversion of Polar to Cartesian Co ordinates 20 Radar 21 Speaker 22 Testing and Evaluation 23 Testing separate components 23 I R Sensor Testing 23 Servo Motor Testing 26 Speaker Testing 26 Oscilloscope Cartesian Coordinates Testing 26 System Testing 27 27 Tracker Mode 30 Profiler Mode 31 Full System Testing 33 Technical Specification 34 Costing 35 Limitations and Future Improvements 36 Appendix The Code 37 Appendix Circuit Diagrams 68 Block Diagram of Complete System 68 IR Sensor and ADC Connections 69 DACs OpAmps and Oscilloscope X amp Y inputs 69 Servo Motor Speaker and Oscilloscope Z input 70 Appendix Lookup Tables 71 Reload High and Reload Low tables 71 Sine and Cosine tables 15 Distance Table 77 Bibliography 79 INTRODUCTION After going to the introductory MCP lecture I have to admit I was bit intimidated which is usually very hard for me to admit by this
41. R ret init_port initalise ports A input B output C output ld 0x90 out0 CSR initialising portC such that all bits are zero i e timer bits are 0 and oscilloscope Y input is 000000 ld a 0x00 out Y a finitialising portB such that all bits except bit7 are zero i e oscilloscope x input is 0000000 and z input 1 i e beam turned off ld a 0x80 out X a ret init angle45 sets angle to 45degrees and loads in appropriate reload values into timer 0 ld a 0 2 ld angle a 1 d 0x01 angle 45 ld e 0x50 out0 rr high0 out0 rr lowO ret init angleO sets angle to Odegrees and loads in appropriate reload values into timer 0 ld a 0x00 ld angle a ld d 0x00 angle 0 ld e OxDO out0 rr high0 out0 rr lowO ret enable servo timer turns timer0 which is the servo motor input ei make sure pulse starts on a low or else we would have an inverted wave to what we desire in a Y and 0x7F 50 out Y turn timer0 0 a TCR or 0 11 out0 TCR ret disable_servo_timer di turn timer0 off in0 TCR OxEE TCR ret enable_speaker_timer 0 a TCR or 0x22 out0 TCR ret disable speaker timer 0 a TCR and OxDD TCR ret delay servo full rotation push bc ld bc OxFFFF full delay_loop nop dec bc ld a 0x0
42. Testing All this required was to test whether all the modes worked when put in the same program file and whether the menu itself worked One major problem I faced was the overlapping of labels which often meant that even after I got rid of all duplicate label names I had forgotten to change the jump instructions accordingly so often the tracker looped into the radar and vice versa until I fixed all this The system seemed to respond fine to all keypad entries taking it to the appropriate mode for keys 1 3 or back to the main menu for other keys Obviously really proud of the simplest hardware design in the lab 33 TECHNICAL SPECIFICATIONS InfraRed Sensor Operational Range 10 60cm Distance Accuracy 10 30cm Max Error Ocm Standard Deviation 0 00 30 40cm Max Error 1cm Standard Deviation 0 41 40 50cm Max Error 2cm Standard Deviation 0 81 50 60cm Max Error 4cm Standard Deviation 1 19 Servo Motor Angle of sweep 0 180 degrees Speed of rotation 0 20 seconds degree Radar Mode Angle of sweep 45 to 135 degrees every 1 degree Maximum Objects Detectable 20 Average Time for Full Sweep 25 seconds Radar Range 10 60cm Tracker Mode Angle of sweep 0 to 180 degrees every 3 degrees Tracker Accuracy 3 degrees Seeker Range 10 30cm Tracker Range 10 30cm Maximum Speed Track able 2cm s Profiler Mode Angle of sweep 45 t
43. acter ay character ay character ay character ay character 57 0 is at 30 So e g 1 is displays ASCII character put in reg a onto lcd screen call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ call displ display 1 a 0x31 call displ ld 0x52 call displ ld a 0x41 call displ ld a 0x44 call displ ld a 0x20 call displ ld 0x32 call displ ld 0x54 call displ ld 0x52 call displ ld a 0x4B call displ ld a 0x20 call displ ld a 0x33 call displ ld a 0x50 call displ ld a 0x52 call displ ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character IRAD 2TRK 3PRE ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character 58 1 0 46 call display_character ret display radar mode display RADAR MODI
44. ad enough memory to incorporate these lookup tables without having to worry about any of the instructions or the stack overlapping with them please see the appendix for these tables Lookup tables were also used to store ADC values that directly mapped to distances stored in hex since the function relating them seemed to be exponential and it would be very difficult to do this conversion in assembly The values for high and low reload registers to be put into timer0 for each angle were also put in two separate lookup tables Even though the desired function reload 2 844 angle 208 could be easily performed by the Z80 multiple instruction it seemed like a waste of time doing this so often when looking up a table is so much less time consuming In the profiler mode two arrays are used to store x and y coordinates of IR readings converted into oscilloscope co ordinates by the get coords module The x and y arrays start at memory locations 00 and F900 respectively and use the angle as an offset 00 and F900 were 19 chosen since they large enough to not overlap with any part of the program memory small enough not to overlap with the stack which starts at FFFF Please see next topic on the use of lookup tables for finding cartesian co ordinates from polar ones For a full list of lookup tables please see the appendices Conversion of Polar to Cartesian Co ordinates The procedure get_coords converted the polar co ordin
45. ance distance Call display_angle_distance If distance lt 30 then Call make_sound Call plot_outline call get coords angle distance call plot point x coord y coord Else angle MidAngle reset angle rotate_to_angle End if Until distance gt MidDistance keep checking left until object no longer in left End if End if Until middistance gt 60 or mode lt gt 2 Until mode lt gt 2 End tracker PseudoCode for Other Important Modules Module rotate to angle angle sets appropriate reload values into timer 0 for angle and then enables timer 0 for long enough for a short rotation 1 3 degrees timer0 reload high reload high table angle timer0 reload low reload low table angle call enable timerO call servo delay call disable timerO End rotate to angle Module make sound outputs a wave to speaker to make a sound with frequency dependent on distance ADC value Temp ADC Data Temp Temp OR 0 10 Or with Ox10 otherwise too small a period would cause too frequent interrupts and cause the program to behave abnormally timerl reload high 0 timerl reload low Temp call enable speaker timer call delay sound call disable speaker timer End make sound Module display bin to dec number 16 displays a binary number put into number as 3 digit decimal number the 1 H 0 to fin
46. and coords table to plot points displaying the profile of the object scanned earlier plot outline mode plot point x coord y coord enable servo timer Enables timer of the processor disable servo timer Disables 0 of the processor servo timer toggle When timer0 generates an interrupt the output to the servo motor PortC B7 is toggled and it is set such that the next interrupt occurs at 5ms previous time i e giving a wave of period 5ms enable speaker timer Enables of the processor disable speaker timer Disables timerl of the processor speaker timer toggle When timer generates an interrupt the output to the speaker PortC B6 is toggled giving a square wave rotate_to_angle Sets timerO s reload registers using appropriate values from the reload high and reload low tables corresponding to the angle given Runs timer0 for a short time enough for a maximum 5 degree rotation allowing the servo to rotate to that angle and then disables enable_servo_timer disable_servo_timer get_coords angle radius Gets polar co ordinates from angle and distance and converts them into cartesian co ordinates and stores the results in global variables x_coord and y_coord to be plotted on the oscilloscope later Note x_coord is actually the oscilloscope x coordinate with 64 as the center of our 128bit x axis display plo
47. assignment which seemed rather complicated and tedious All the talk about infra red sensors servo motors and other things I haven t really handled in computer science courses before just made it seem that way Later I realised all I had to do was stick to the basic principles taught in the previous hardware courses and not be that concerned with the other aspects of the system especially those that brought back horrid memories of A level physics The aim of this project was to integrate a Z80 processor system with a infra red sensor attached to a rotating servo motor to build some kind of radar I realise it is not really a radar since that would require radio and not infra red waves Fortunately this design would not be so low level since this Z80 processor already came with its own data and address buses RAM chips external ports and an LCD display with a keypad There are three modes of function the completed system was supposed to be able to perform First in radar mode the system is supposed to sweep through a predefined angle and then display objects in the vicinity by showing their positions on the LCD display as polar cartesian co ordinates and also on the oscilloscope There would also be a speaker to produce sound effects indicating whether an object is there when the sensor is at any particular angle In the tracker mode the sensor is supposed to follow an object that is slowly being moved around and once again a sound effect i
48. ates stored in global variables angle and radius to Cartesian co ordinates and stored them in global variables x_coord and y_coord These were not really the orthodox polar or Cartesian co ordinates since the angle 0 started on the x axis and went clockwise The Cartesian co ordinates were actually oscilloscope co ordinates so real 0 0 would be returned as 64 0 since with a range of 0 128 on the x axis 64 is the centre The lookup tables stored sine and cosine for each angle in 8 bits in a fixed point format assuming the point is right before the first bit e g Sine 90 1 is stored as FFh meaning 0 11111111 or Sin 30 0 5 is stored as 80h meaning 0 10000000 Only absolute cosine values were put into the table these were later taken into account when calculating oscilloscope co ordinates The y coordinate would simply be radius sine angle This is done by putting the value for the corresponding angle from the sine table in one register h and then multiplying it with another register that contains the radius 1 The result is stored in hl if we just ignore the last 8 bits of the results ignore register and only take into account h we have the result of the multiplication without the fraction bit The x coordinate is calculated similarly by multiplication only afterwards the multiplication result is added to 64 for angles gt 90 or subtracted from 64 for angles lt 90 The diagram below explains the geometrical calculations methods
49. ative of distance Or 0x10 is done such that a too small ADC reading does not give a very high frequency which may cause the program to behave abnormally due to too many clock interrupts being generated ld a 0x00 out0 rr highl in a ADC or 0x10 out0 rr low1 ei call enable speaker timer T speaker enabled call delay speaker give speaker enough time to make an audible sound di call disable speaker timeri speaker disabled ret delay speaker delay procedure to give speaker enough time to make an audible sound push bc ld bc 0 0600 do 600h nops delay speaker loop nop dec bc ld a 0x00 cp b jp nz delay speaker loop pop bc ret servo timer toggle when servo clock interrupt occurs this toggles the servo input to produce required wav 0 a TCR required to be read to put down interrupt 0 a TDRO toggle servo bit to create pulse in a Y xor 0x80 out Y a ld d e hold rr_high0 and lowO 1 1 ld a 45 ld a de found in 1 s complement form push hl ld h 0x06 ld 1 0 01 add hl de next pulse should have period 600h de since de is in 1C form 1 is added so 601h de performed d h lde 1 out0 rr_low0 new reload values put in to generate wave out0 rr high0 reti speaker timer toggle when speaker clock interrupt occurs this toggles th
50. call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character ret sine_table table storing sine values for each angle using angle as offset maps angles to sine values in fixed point binary fractions binary point before MSB byte 0x00 0x04 0x08 OxOD 0x11 0x16 0 1 OxlF 0x23 0x28 0 2 0x30 0x35 0x39 Ox3D 0x42 byte 0x46 Ox4A Ox4F 0x53 0x57 0x5B 0 5 0x64 0x68 0x6C 0x70 0x74 0x78 Ox7C 0x80 0x83 byte 0x87 0x8B 0x8F 0x92 0x96 Ox9A 9 OxA1 OxA4 OxA7 OxAB OxAE OxB1 OxB5 OxB8 OxBB byte OxBE 1 0xC4 0xC6 0xC9 OxCC OxCF OxD1 OxD4 0xD6 0 09 OxDB OxDD OxDF OxE2 4 byte OxE6 OxE8 OxE9 OxEB OxED OxEF 0 0 OxF2 OxF3 OxF4 OxF6 OxF7 OxF8 OxF9 OxFA OxFB byte OxFC OxFC OxFD OxFE OxFE OxFF OxFF OxFF OxFF OxFF OxFF OxFF OxFF OxFF OxFF OxFF byte OxFE OxFE OxFD OxFC OxFC OxFB OxFA OxF9 OxF8 OxF7 OxF6 OxF4 OxF3 OxF2 OxFO OxEE byte OxED OxEB OxE9 OxE7 OxE6 0 4 OxE
51. character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character display profiler mode display PROFILER MOD ca 1 1 1 0 50 disp call a 0x52 displ a Ox4F disp a 0x46 displ a 0x49 displ a 4 disp 0 45 disp 0x52 displ E and go to next line ay character ay character ay character ay character ay character ay character ay character ay character 62 ld 0x20 call display character ld a Ox4D call display character ld a Ox4F call display character ld a 0x44 call display character ld a 0x45 call display character ld a 0x20 call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display character call display c
52. coordinates out of the two arrays starting the offset at 45 and plots each point each time increasing the offset by 1 until it reaches 135 and then it starts again from 45 and keeps looping around effectively showing the profile of the object on the oscilloscope screen Module Profiler Call init_angle45 set servo to start sweep at 45degrees Call enable servo timer Call servo delay full Call disable servo timer Repeat Call rotate to angle Call get distance calculate distance and put it in variable distance Call display angle distance Call plot outline 13 if distance lt 60 then stores oscilloscope co ordinates in arrays if distance is valid Call get_coords angle distance Call plot_point x_coord y_coord Call make_sound x_coords angle x_coord y_coords angle y_coord else x_coords angle 0 y_coords angle 0 End if Call increase_angle angle angle 1 Until angle gt 135 or mode gt lt 3 Repeat keep showing profile until mode changed via keypress Call show_profile Until mode gt lt 3 End Radar Module show_profile Call plot outline display sweep able region on scope angle 45 start showing points from that at 45d Repeat show all points stored in x_coords and y_coords unless they re blanks x_coord x_coords angle y_coord y_coords angle If x_coord gt 0 and y_coord gt 0 then Call plot poi
53. d objdis values ld a angle ld objang a jp next angle checkblank ld objdis 60 then rotate to next angle cp 0x3C jp nc next_angle ld a angle affect it push af ld a objang ld angle a ld a objdis ld radius a call get_coords call clear if current distance lt previous distance set new object distance and angle as current if there is a blank space means end of object if there was no previous object object distance gt temporarily stores angle in stack since calculations get cartesian coordinates for objang objdis call display object lcd displays message saying objected detected call display angle distance coordinates on LCD call plotoutline region call plot point detected call beam on call make sound object call plotoutline region call plot point detected call beam on pop af ld angle a ld a 0x40 no object being detected ld objdis a ld a angle sweep again cp 0x87 jp nc radar display objang objdis cartesian plot outline on oscilloscope showing sweep able plots point using cartesian co ordinates of object leave oscilloscope beam on use speaker to make sound indicating detection of plot outline on oscilloscope showing sweep able plots point using cartesian co ordinates of object leave oscilloscope beam on restore value
54. d hundreds digit keeps subtracting hundred from number until number lt 100 Repeat number number 100 H H 1 Until number lt 100 H H 1 If H gt 0 then 0x30 0x30 is 0 in ASCII 1 is 0x31 and so on Output to LCD A Call delay lcd End if H 0 to find tens digit keeps subtracting ten from number until number lt 10 Repeat number number 10 H H 1 Until number lt 10 H H 1 0x30 Output to LCD A Call delay lcd whatever is left is the units digit number H 0x30 Output to LCD A Call delay lcd End display hex to decimal Module display angle distance angle distance Displays current angle distance x coordinate and y coordinate on LCD screen uses display bin to dec to convert these numbers Call display hex to decimal angle Output to LCD o If distance lt 60 then Call display hex to decimal distance Output to LCD cm Call get coords x coord and y coord hold oscilloscope co ordinates the x coord needs to be subtracted added from 64 to give cartesian co ordinates If x coord lt 64 then Output to LCD x_coord 64 x coord else x coord x coord 64 end if Call display hex to number x coord 17 Output to LCD Call display hex to number y End if End display angle distance Module get coords angle radius converts polar co ordinates to oscilloscope co ordinate
55. dinates call plotoutline call get_coords midangle middistance call plot_point oscilloscope call make_sound call plotoutline call get_coords midangle middistance call plot_point oscilloscope right ld a midangle 0 0 jp left add a 0x03 ld angle call rotate to angle midangle 3 call get_distance 1 middistance 1 b 41 ld distance cp b jp ne left right so check left ld a angle midangle to current angle and so ld midangle a jp right_check left ld a midangle cp 0x03 jp c right_check sub ld call 0x03 angle a rotate_to_angle midangle 3 call get distance ld a ld b ld a middistance distance cp b jp nc right check left so c midangle t ld ld a heck right angle o current angle and so midangle a left check menu ld a mode cp 0x02 jp nz main menu call clear call call coordinate call S call plotoutline get coords midangle middistance ca plot point oscillosco call pe make sound call plotoutline call get coords midangle middistance ca plot point oscillosco pe jp left profiler call call init angle45 enable servo timer T T T T rightdistance a b rightdis middis if
56. does not store the locations of the objects It does however give a nice effect of an object popping up on the oscilloscope and then fading away as the next object is detected But I suppose if I stored the positions of all objects in memory and then displayed the previously scanned objects in the same sweep while scanning it would look much more sophisticated and give more information Among other things I would have also preferred to have a faster servo motor which would mean faster sweeps for the radar and profiler modes and the tracker mode would also be able to track faster moving objects I would also have liked to allow the user to manually enter angle of sweeps acceptable distances ranges etc for each of the modes using the keypad Using some fancy vector graphics it would have been nice to show the angle distance etc on the oscilloscope display itself as graphics All this would require is to have bitmap images of numbers and then showing them on the screen starting at a particular points of it Most of these suggested improvements are base on what I saw done by other teams doing the MCP course Despite all the limitations of our system I think I can safely say that ours is probably the simplest and cheapest hardware solution and I do feel rather smug about what I have put together 36 APPENDIX A THE CODE jp main Space 29 vector_table setting up vector table for servicing interrupts int 0x0000 interrupt 0
57. e Speaker input to produce required 0 a TCR required to be read to put down interrupt 0 TDR1 Y toggle speaker input to produce square wave xor 0x40 out Y a reti beam_off turns oscilloscope beam off by setting portB bit7 to 1 leaving other bits unchanged 0 80 out X ret beam_on turns oscilloscope beam on by setting portB bit7 to 0 leaving other bits unchanged in X and Ox7F out X a ret plotoutline plots outline indicating extreme x amp y co ordinates and sweep able region ld a 0x00 plot bottom leftmost point 1 x_coord 1 call plot_point ld a Ox7F plot top rightmost point ld a ld a 0x3F ld y coord call plot point 46 ld 0x00 plots top leftmost point ld x coord a ld a Ox3F ld y coord a call plot point ld a 0x7F plot bottom rightmost point ld x coord a ld a 0x00 ld y coord a call plot point ld a angle temporarily stores current angle in tangle since angle is used by procedures ld tangle a ld a mode two lines at 45d and 135d are drawn to indicate sweep able areas for profiler and radar mode but these are skipped for the tracker 40 0 0 02 jp 2 pointer 1 b 0x00 ld c 0x40 downline draws a line at 45degrees grad 1 from 0 3F to ld a b 1 0 80
58. e following table shows the calibration readings for the IR sensor Distance cm Reading1 Reading2 Reading3 Average Adjusted 9 F6 FQ F6 10 EO E4 E5 11 D1 DO CC CF CF 12 C2 CU 1 C1 C1 13 BO B3 BO 1 B1 14 A2 A5 A5 4 4 15 9B 97 99 99 99 16 91 92 8D 90 90 17 86 89 89 88 88 18 80 81 85 82 82 19 7C 7E 7A 7C 7C 20 77 74 74 75 75 21 73 71 6 70 70 22 6A 6D 6D 6C 6C 23 69 67 6B 69 69 24 61 65 66 64 64 25 61 60 60 60 26 5D 5F 5B 5D 5D 27 5A 5D 5A 5B 5B 28 58 57 59 58 58 29 54 57 54 55 55 30 52 53 54 53 53 23 31 51 50 4F 50 50 32 4E 4E 4B 4D 4D 33 4A 4 4 4 4 34 49 4 47 49 49 35 47 49 45 47 47 36 48 44 43 45 45 37 43 44 42 43 43 38 42 42 41 41 39 42 40 40 40 40 3D 41 3F 3F 41 3E 3F 3D 42 3C 3D 3D 3D 43 3A 3D 3D 3C 3C 44 3D 3A 3A 3B 3B 45 3A 3C 38 3A 3A 46 36 37 3B 38 38 47 35 38 38 37 37 48 37 34 34 35 35 49 33 33 36 34 34 50 31 36 31 32 33 51 32 32 35 33 32 52 32 33 33 32 31 53 31 2 30 30 30 54 2 2 33 30 2 55 2 2 2 2 2 56 2 2 32 2 2D 57 2A 2B 2D 2B 2C 58 2 2 2 2 2B 59 2 29 28 29 2 60 28 2B 2B 2A 29 61 26 28 2A 28 28 62 29 27 26 27 27 63 28 26 27 27 26 64 25 25 26 25 25 The average readings were later adj
59. eading of 50 cm might be returned So for two objects picked up during a sweep when points were plotted on the oscilloscope they ended up like when you would expect 21 The ideal situation would be to show dot each for each object detected This obviously was a software flaw I had to rewrite the radar module such that once something is detected lt 60cm it is treated as the beginning of the object and its angle and distance are stored in variables ObjectAngle and ObjectDistance respectively which were initialised to 0 and 60 at the start of a sweep As subsequent points of the object are detected ObjectAngle and ObjectDistance are updated if the current distance reading is less than ObjectDistance such that ObjectDistance finally stores the nearest distance and ObjectAngle thus holds the angle at which the centre of the object is located When a reading gt 60cm is detected again we know that is the end of the object and thus the co ordinates of the object are plotted on the scope and displayed on the LCD using ObjectDistance and ObjectAngle which are then reset to 64 0 respectively allowing the detection of a new object So in the end the oscilloscope display looked like this Speaker We also had a major problem getting the speaker working The speaker was set such that a square wave of frequency dependent on the ADC value was being outputted to bit6 of PortC However this did not make any sound when the speaker was conn
60. ected I checked the output of the bit6 using a probe on the oscilloscope to discover that the waveform was well within the audible frequency range Strangely enough when I wrote a separate procedure to test the speaker it worked perfectly My partner was having similar problems and his test procedures worked perfectly too but the speaker stopped working when it was integrated into the main program for the radar tracker or profiler It later occurred to us that it may be because only one chip is used to drive all the ports all of which are used in the main program but not in our test speaker programs Since the speaker had a high impedance and other bits of all the ports were being set to 5Vs at the same time the output was simply not powerful enough to drive the speaker But then we had absolutely no idea how to solve this problem This is when we had a stroke of genius I don t remember which one of us had this brilliant idea I would like to think it was my idea though which was to ask the lab technician Ron what could be done about this He suggested putting in a capacitor in series with the speaker and that worked perfectly we were finally getting a nice smooth sound quite distinct over different distance readings We really owed Ron for this one and we also owe him for being very understanding when we somehow managed to blow up the CMOS chip that drives the ports in a completely unrelated incident when simply everything stopped working and
61. er timer 0 rotate_to_angle register Temporarily holds the value of reload register clock_timer_toggle low for the servo timer timer 0 rotate_to_angle radius While converting polar to cartesian co radar ordinates through the get_coord procedure tracker radius is used the parameter profiler get_coords x_coord Stores the x coordinated of last point whose get_coords co ordinates were converted from polar to radar cartesian using get_coords tracker profiler display_angle_distance plot_point 11 coord Stores the x coordinated of last point whose get_coords co ordinates were converted from polar to radar cartesian using get_coords tracker profiler display_angle_distance plot_point mode Stores the mode that the program is now menu running 1 2 or 3 When any key is pressed tracker on the keypad the value of mode is changed profiler accordingly radar Basic Overview of Each Mode of Operation Radar Mode The radar module works by first setting the angle to 45 degrees and allowing the motor enough time to rotate to that angle From then on it takes distance readings at each angle incrementing and rotating to the next angle and then uses them to find out whether there is an object in the vicinity An object is often detected at two or more angles however the actually angular position of the object is one where the distance reading is the lowest but in radar mode we d like an object to s
62. er making a few measurements I discovered that there was a very linear relationship between angle and reload value I took a few readings and plotted a graph and then using linear regression techniques I found a simple equation involving reload values and angle Reload 2 84444 angle 208 Once again a table was constructed that mapped angles to reload values so that the program would put in the suitable reload value for each angle when it requires to move the sensor to that angle The Oscilloscope The X input of the oscilloscope was connected to the lower 7 bits of port B via an digital to analogue converter and opamp and the Y input of the oscilloscope was connected to the lower 6 bits of port C via an digital to analogue converter and opamp I set the range of the system to be between 10 and 60cm For a full sweep this would require a semi circle of radius 60 cm and let us assume we used one pixel per cm Therefore the y axis would need 60 divisions and the x axis would need 120 division so 6 bits 64 divisions and 7 bits 128 divisions were appropriate for x and y respectively The Z input was controlled by bit7 of port B If the bit was set to a high SV this turns the beam off This was very useful since if we left the beam on while plotting between two points there would be quite a few unwanted dots plotted on the screen in the mean time So this bit was set to 0 to turn the beam or set to 1 to turn it off For the x and
63. f the system however if it were to be mass produced then the costs per unit would be slightly less 35 LIMITATIONS AND FUTURE IMPROVEMENTS As far as limitations go the most apparent one would probably be the resolution of our oscilloscope display 1 128 64 The most obvious reason for doing that was to save time and a chip so that we could only use the ports for I O Most other teams were using a 256 256 resolution However I believe this is unnecessary because of the inaccuracy of the IR sensor An improvement I would suggest is the use of a more accurate sensitive IR sensor such that distances would be calculated with greater accuracy and then a higher resolution could be used to give more near to exact positions of objects on the oscilloscope On top of that if a 16 bit ADC were used to encode the IR sensor data the distance measurements would have greater detail perhaps in millimetres One problem with sharing the same ports for timers and the y axis meant that while the timers were running it was not possible to change the position of points on the oscilloscope screen This meant that our screen was slightly more flickering than that of other teams This is one reason why we really should have implemented a discrete I O scheme leaving the timer bits separate from anything else A better IR sensor would also increase the operational range of all our modes At the moment the radar mode only shows objects as it sweeps but
64. gle by 2 decrease angle2 Decrements global variable angle by 2 make sound Using the ADC value as the frequency it enables the speaker for a short period indicating distance of the object since it determines the frequency of the sound produced enable speaker timer delay sound disable speaker timer keypad int When the keypad is pressed global variable mode is updated according to key pressed if invalid mode i e not between 1 and 3 then mode is set to 0 which causes all mode modules to return to the main menu clear Sends command to LCD to clear the scren beam on Turns oscilloscope beam on by setting the Z input to the oscilloscope Port B Bit7 to a logic U 0V beam off Turns oscilloscope beam on by setting the Z input to the oscilloscope Port Bit7 to a logic 1 SV plot_outline Plots an outline on the oscilloscope It shows all the extreme points plot able by the system on the oscilloscope and it shows a small line of radius 10 pixels at an angle corresponding to global variable angle indicating the direction the sensor is pointing For radar and profiler modes it displays two lines of radius 64 one at 44 degrees and one at 136 degrees indicating the sweep able region beam_on beam_off get_coords angle radius plot_point init_vector_table Initialises the vector table which the processor uses to call interrupt servicing routines
65. haracter ret display rotating display ROTATING BACK and go to next line ld a 0x52 call display character ld a Ox4F call display character ld a 0x54 call display character ld a 0 41 call display character ld a 0x54 call display character 63 1 1 1 11 0 49 disp call tr a 0 4 disp call a 0x47 displ a 0x20 displ a 0x42 displ a 0 41 displ a 0x43 displ a Ox4B displ display object display OBJECT DETECT 1 1 1 11 d TOT 11 disp disp 12 disp disp disp ay_character ay_character ay_character ay_character ay_character ay_character ay_character ay_character ED and go to next line ay_character ay_character ay_character lay_character ay_character ay_character ay_character lay_character lay_character ay_character lay_character 64 call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character call display_character
66. he infra red sensor generates an analogue voltage depending on the distance between any obstacle and the sensor This analogue reading is fed in to the input of the ADC with the appropriate reference voltage to produce a digital output which is later converted by software into distances using a reading to distance look up table stored in memory A graph of voltage against distance looks like this Voltage V 0 10 20 30 40 50 60 70 80 90 100 Distance cm Had this been a simple straight line we would have been able to use a simple equation for calculating distances from voltages converted to digital values from the ADC We had decided that our system would have a range between 10 and 60cm As you can see at 10cm the voltage reading is about 2 1V So the reference voltage we put in to the ADC was about 2 2V using a potential divider please see circuit diagrams for details Sensor Calibration A simple program was written which took readings off the ADC and then displayed the digital reading received in hex on the LCD monitor Several readings of ADC values were taken at different points between 10 and 60cm which is the operational range of this system at every These values needed to be averaged since the ADC values were inconsistent at times and then a reading to distance table was constructed which mapped each binary value from the ADC to a distance value Please see Testing Evaluation for calibratio
67. hose position since then the new reload values were no longer on the reload tables so a very strange input would be put into the servo motor I made it so that there were checks at 0 and 180 degrees such that in those instances the tracker would not check to the left or right respectively The sound effects produced were quite satisfactory as well 30 Target placed in front of sensor in tracker mode Oscilloscope showing position of target LCD displaying co ordinates of target Profiler Mode The profiler was tested with differently shaped objects placed in front of the sensor and then checking what kind of image was formed on the oscilloscope The distances on the LCD display also came out more or less right Many different shapes were used to check the image formed on the screen and the shapes more or less coincided as well as can be expected from our particular resolution and our sensor The speaker makes distinct sounds at distinct distances so the sound gave the listener a rough idea of the shape of the object For example a concave object would 31 give more less same sound through out but a straight object would start off with a high frequency then get lower and then get higher again The following are some pictures of objects placed on the sensor and the profile shown on the oscilloscope after a sweep Object Placed Profile Displayed 32 Full System
68. how up only once on the scope So when something is detected i e distance 60 cm it is treated as the start of the object ObjectAngle and ObjectDistance are set to current angle and distance and for the next subsequent angles the object s angle and distance are updated in case the distance is less than what it was at the earlier angle i e if distance ObjectDistance reset ObjectDistance and ObjectAngle to current ones After nothing is detected once again the distance and angle of the object are displayed on the LCD and oscilloscope using ObjectAngle and ObjectDistance which are subsequently set to 0 and 64 respectively to allow the detection of a new object and a sound is made on the speaker After reaching 135 degrees the radar procedure simply starts again at 45 degrees and does the sweep again However it keeps checking if the mode has been changed by the keypad int procedure which services interrupts from the keypad updating the mode in which case it returns to the main menu Module Radar Repeat Call init angle45 set servo to start sweep at 45degrees Call enable servo timer Call servo delay full Call disable servo timer ObjectDistance 64 initialising last object detected at infinity Repeat Call enable servo timer Call delay servo Call get distance get distance and put it in distance Call display angle distance 4 lcd displays angle distance etc Call plot outli
69. k if angle gt 90 if angle lt 90 x coord 64 h if angle gt 90 x coord 64 h a cosine value from sine table sine table fracti ret plot po y coord x coord ld h ld a ld 1 mlt hl h sine angle radius ld a _ 1 ld b 0x00 add hl bc lch ay 1 radius a on part h int and 0 7 id Ty in a a X and 0x80 or out y_coord ld a h X and 0x3F ld a x_coord y_coord number part 1 sine angle radius a plots point on oscilloscope given by co ordinates x_coord and sets lower 7 bits of portB oscilloscope x input as set bit7 Z input to 1 turn beam off sets lower 6 bits of portC oscilloscope y input as make sure bit6 and bit 7 set to 0 55 OxCO unaffected ret OxBF out Y call beam_on nop nop nop nop nop call beam_off make sure bit6 and bit7 speaker and servo input turn beam on for short time and then turn it off display bin to dec display binary number in decimal on lcd ld h 0x00 ld a number start100 0 sub 0x64 end100 ld number jp start100 end100 at 31 lda h cp 0x00 jp z initl0 lda h on lcd add a 0x30 out lcd out a call plotoutline initlO ld a number ld h 0x00 start10 0 sub 0x0A jp c e
70. le3 increase angle by 3 40 call rotate_to_angle jp seeker loop tracker start a angle store current angle and distance as middle angle and ld distance ld midangle a 1 1 call get_distance a distance middistance a right_check run timer for enough time to allow rotation check if mode has been changed via keypad rotate to current angle set current distance as mid distance if mid distance gt 64 it means object has moved clears lcd display message saying tracker locked display angle distance cartesian show sweep able region on oscilloscope get oscilloscope co ordinates for plot point showing current angle distance on make sound indicating distance from sensor show sweep able region on oscilloscope get oscilloscope co ordinates for plot point showing current angle distance on if angle gt 178 do not check right angle midangle 3 enable timer and allow servo time to rotate to read current distance into distance b middistance ld mode cp 0x02 jp nz main_menu ld a midangle ld angle call rotate to angle call get distance ld a distance ld middistance a ld a distance out of range so start seeking again cp Ox3F jp tracker call clear call display_tracker_locked call display_angle_distance coor
71. m 35 20 165M 40cm 39 10 00 60cm 60 00 180 40cm 40 00 45 60cm 42 42 008 25cm 25 00 90 60cm 00 60 208 25cm 23 08 135 60cm 43 42 408 25cm 19 16 008 45cm 45 00 180 60cm 60 00 608 25cm 12 22 108 45cm 44 08 80M 25cm 04 25 208 45cm 42 15 100 25cm 05 25 30 45cm 38 22 00 55cm 55 00 120 25 13 22 40 45cm 34 29 188 55cm 52 17 140 25cm 20 16 50 45cm 28 34 368 55cm 44 32 160 25cm 24 08 608 45cm 22 39 54M 55cm 32 44 180M 25cm 25 00 708 45cm 15 42 728 55cm 16 52 80M 45cm 07 44 90 55cm 00 55 908 45cm 00 45 108M 55cm 18 52 00 40cm 40 00 100 45cm 08 44 1268 55cm 33 44 15 40cm 38 10 110 45cm 16 42 144 55cm 45 32 30 40cm 34 20 120 45cm 23 39 1628 55cm 53 17 458 40cm 28 28 130 45cm 30 34 180 55cm 55 00 Degree Sign in LCD font System Testing Each of the modes were put together first and test individually Radar Mode This was a very simple test Some tubes were placed in front of the sensor and the program was run to see if the oscilloscope gave the proper positions of the objects and whether it gave just one dot on the scope for one object I realise the specifications required the radar mode to pick up at least 16 targets in the sweep able angular range but unfortunately we were provided with just one tube to test our programs on I used my highly persuasive skills to borrow some others from other benches and improvised by using some smarties tubes At a far enough distance the radar
72. n before tracking it It makes a sound if the object is within 30cm or else it just keeps quiet Module tracker Repeat THHHHHF Seeker Part locates an object first within 30cm Repeat Call init angleO angle 0 Call servo delay full Repeat Call rotate to angle Call get distance Call display angle distance Call plot outline call get coords angle distance call plot point x coord y coord Call increase angle3 angle angle 3 Until angle 180 or mode 2 or distance 30 Until mode lt gt 2 or distance 30 THHHHHF Seeker ends when an object is located at less than 30cm Call decrease angle3 angle angle 3 MidAngle angle set current angle distance as mid values MidDistance distance Repeat call get distance angle MidAngle Middistance distance Call display angle distance If distance 30 then Call make sound Call plot outline call get coords angle distance call plot point x coord y coord If angle 178 then call increase angle3 checking right call rotate to angle angle call get distance End if If distance MidDistance then MidAngle angle object moved right Else If angle 2 then Repeat angle MidAngle checking left decrease_angle3 call rotate_to_angle 15 call get_distance If distance lt MidDistance then MidAngle angle moved left Middist
73. n tables In between binary values which were not read for any specific distances at each interval simply mapped to the closest 1cm discrete value on the table Servo Motor The servo motor is controlled by giving it a pulse of period 5ms i e a frequency of 200Hz and the peak time of this pulse determines the angle it will rotate to The Z80 has two internal clocks timers which came in very handy for this purpose The timers can be initialised with reload values and then the timer starts counting down beginning from the reload value Once it has counted down to zero it generates an interrupt distinct for each timer and then it starts counting down from the reload value again The interrupt routine was made such that it flips a bit on Port B every time the timer counts down to zero After much experimentation while monitoring the output of the port using the oscilloscope we found that the timer takes 5ms to countdown with a reload value of 0600h Controlling the motor was simple from then on we could start with a certain peak time value with the reload register with the clock output on the port set to a 1 and then after its counted down to 0 this representing a high on the output we would flip the bit and at the same time set the reload value to 0600h peak this representing low the output So we would have wave of period 5ms and the peak period is controlled by the initial value put into the reload registers Aft
74. nd10 inc h ld number a jp start10 end10 lda h add a 0x30 out lcd out a at 31 on lcd call delay keypad ld a number keep subtracting 100 from a and incrementing h until a lt h stores hundreds digit display h as number in ASCII 0 is at 30 so e g 1 is keep subtracting 10 from and incrementing h until a lt h stores tens digit display h as number in ASCII 0 is at 30 so e g 1 is 56 h a ld h 0x3 at 31 on lcd out lcd out a call delay keypad ret display character h stores units digit 0 display h as number in ASCII out lcd out a call delay keypad ld a ret display menu display SELECT and go to next line 0x20 ld a 0x53 call displ ld a 0x45 call displ ld a 0 4 call displ ld a 0x45 call displ ld a 0x43 call displ ld a 0x54 call displ ld a 0x20 call displ ld a Ox4D call displ ld a Ox4F call displ ld a 0 44 call displ ld a 0x45 call displ ld a 0x20 call displ call displ call displ call displ call displ call displ call displ call displ call displ ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay character ay char
75. ndicates whether the object is still in the sensor s line of sight Once again the object s position would have to be shown on the LCD display and oscilloscope In the profiler mode it sweeps through the predefined angle as in the radar mode only after its done sweeping it displays some kind of image on the oscilloscope which would show the shape of the object placed near the sensor While the object is being scanned the speaker would make some kind of sound indicative of the shape of the object My partner and I decided to stick to a very simple design as we did for CTS even though that did not get us too many marks Our main objective for this project was making a system that meets the minimum requirements with particular emphasis on simplicity cost effectiveness and of course minimum effort OVERVIEW HARDWARE SOFTWARE Fortunately we were given the SBC board this time to construct our hardware around This made this assignment quite ridiculously easy to design at least the implementation however was a nightmare as in any project First of all the board the RAM chips the LCD display and the keypad are already wired into the Z80 so there was not much time spent in cutting out little bits of wire sticking them to pins and later spending hours trying to figure out why our system was not working before discovering it was because of two wires switched around or a faulty breadboard I was obviously very frustrated with that thr
76. ne show sweep able region 12 If distance lt ObjectDistance then new centre of object found ObjectDistance distance ObjectAngle angle End if If distance gt 60 and ObjectDistance lt 60 then if there is a blank space means end of object show details on object detected Tempangle angle distance ObjectDistance angle ObjectAngle call display_angle_distance call get_coords angle distance call plot_point x_coord y_coord call beam_on call make_sound reset object details to infinity ObjectAngle 0 ObjectDistance 64 Angle Tempangle End if Call increase_angle angle angle 1 Until angle gt 135 or mode lt gt 1 Until mode lt gt 1 End Radar Profiler Mode The profiler mode works very similarly to the radar mode starting a sweep by rotating first to 45 degrees and then incrementing the angle by two while taking distance measurements on each angle However at each angle it also shows the angle distance x and y coordinates on the LCD display and plots these co ordinates on the oscilloscope It stores the x coordinate and y coordinate at each particular angle in two separate arrays using the angle as the offset It also makes a sound at each angle at a frequency dependent on the distance reading After its done sweeping to 135 degrees it then shows the profile of the object scanned This is done by the module show_profile which simply takes out x and y
77. ne tables map angles to sine and absolute cosines values respectively angle sine sine cosine cosine angle table angle table entry entry 000 0 00 00 1 00 FF 001 0 02 04 1 00 FF 002 0 03 08 1 00 FF 003 0 05 0D 1 00 FF 004 0 07 11 1 00 FF 005 0 09 16 1 00 FF 006 0 10 1 0 99 007 0 12 1F 0 99 FE 008 0 14 23 0 99 FD 009 0 16 28 0 99 FC 010 0 17 2 0 98 011 0 19 30 0 98 012 0 21 35 0 98 013 0 22 39 0 97 F9 014 0 24 3D 0 97 F8 015 0 26 42 0 97 F7 016 0 28 46 0 96 F6 017 0 29 4A 0 96 F4 018 0 31 4F 0 95 F3 019 0 33 53 0 95 F2 020 0 34 57 0 94 FO 021 0 36 5B 0 93 EE 022 0 37 5F 0 93 ED 023 0 39 64 0 92 EB 024 0 41 68 0 91 E9 025 0 42 6C 0 91 E8 026 0 44 70 0 90 E6 027 0 45 74 0 89 E4 028 0 47 78 0 88 E2 029 0 48 7C 0 87 DF 030 0 50 80 0 87 DD 031 0 52 83 0 86 DB 032 0 53 87 0 85 D9 033 0 54 8B 0 84 D6 034 0 56 8F 0 83 D4 035 0 57 92 0 82 D1 75 angle sine sine cosine cosine angle table angle table 036 0 59 96 0 81 037 0 60 9 0 80 CC 038 0 62 9D 0 79 9 039 0 63 1 0 78 C6 040 0 64 A4 0 77 C4 041 0 66 AT 0 75 C1 042 0 67 AB 0 74 BE 043 0 68 AE 0 73 BB 044 0 69 B1 0 72 B8 045 0 71 B5 0 71 B5 046 0 72 B8 0 69 B1
78. nged return to main menu cp 0x03 jp nz main menu clear lcd calculate current distance and put it in call clear call get distance distance call display profiler lcd displays message indicating profiler mode ld a distance ld radius a call get coords get cartesian coordinates for angle distance call display angle distance display angle distance cartesian coordinates on LCD T T Storing Profile Stores points in cartesian co ordinates for each angle if something is detected X coordinates for each angle stored in 0xFA00rangle and Y coordinates in OxF900 angle ld distance a if nothing detected distance gt 60 no point stored cp 0x3C nc noppoint ld a angle Starting at location FA00 and using angle as offset Store x coordinate for current angle ld 1 a ld h OxFA ld a x coord ld hl ld a angle Starting at location F900 and using angle as offset Store y coordinate for current angle Jd ss ld h OxF9 ld ld hl call plot outline plot outline indicating sweep able region call plot point plot current point on screen call make sound make sound indicating the distance read jp change angle noppoint if distance gt 64 store the point as 0 0 which is not plotted by show profile ld a angle ld 1 a ld h OxFA ld a 0x
79. nt x coord y coord End if Call increase angle angle angle 1 Until angle 135 Call plot outline End show profile Tracker Mode The tracker mode first uses a similar code as the radar which I prefer to call a seeker to sweep starting at 0 degrees and stops when it finds an object at 30cm that is the operational range I set for the tracker Then it sets MidDistance and MidAngle as current distance and angle respectively It then adds three degrees to the angle rotates to the right and takes a new distance reading if this distance is less than MidDistance indicating the object has moved to the right it updates MidDistance and MidAngle with current values Otherwise it subtracts three degrees from MidAngle rotates to the left and takes a new distance reading and then updates MidDistance and MidAngle if this distance reading is less than MidDistance i e object has moved to the left Another little enhancement to the tracker is that once it sees that the object is moved to the left the next time it first checks to the left and the same thing when the object has moved to the right This is very 14 sensible since we assume the object would move in the same direction more often than change direction It keeps looping around like this until it sees that the object is no longer anywhere in that 6 degree vicinity i e MidDistance gt 60 In this case it loops back to the seeker part and finds the object agai
80. o 135 degrees every 1 degree Average Time for Full Sweep 30 seconds Profiler Range 10 60cm Oscilloscope Display Resolution 128 64 X coordinates 128 discrete values 1 pixel per cm Y coordinates 64 discrete values 1 pixel per cm LCD Display Display size 16 characters per line 2 lines Accuracy of numbers displayed Dependent on IR sensor reading Values correct to whole numbers 0 decimal places 34 COSTING Component Qty Purpose Unit Price Total Price Z80 CPU SBC 1 The SBC Board with 780 Processor 100 00 100 00 Board RAM chips LCD Keypad etc Servo Motor 1 Rotates IR sensor 7 50 7 50 IR Sensor 1 Infra red sensor to detect objects 9 00 9 00 8 ohm Speaker 1 To produce required sound effects 3 38 3 38 DAC0832LCN 2 1 Perform D A conversion for X axis 2 74 5 48 D A Converter 2 Perform D A conversion for Y axis LF356N 2 To amplify analogue signals for each axis 0 63 1 26 Op Amp on each D A converter ADCOSO4LCN 1 To convert analogue voltage read by the IR 2 70 5 40 A D Converter sensor to be read Capacitors 5 For speaker ADC Z input smoothing 0 11 0 55 opamps outputs Resistors 6 For providing reference voltages to ADC 0 05 0 30 and DACs Wires misc For connecting components 1 00 1 00 TOTAL 133 87 Please note these costs are for putting together one unit o
81. ough out the CTS project The fact that the Z80 address and data pins are in absolutely no meaningful order did not make things any easier in the previous assignment The SBC board also comes with three 8 bit ports which make it very convenient to do I O operations since these also act as latches A program can also be downloaded from a linux terminal directly into the RAM which makes testing a lot simpler than having to burn a ROM chip for every little change in code The basic external hardware required were 1 Two digital to analogue converters DACs and opamps to plot points on the oscilloscope using digital data from the SBC board 2 An analogue to digital converter to convert the analogue reading from the infra red sensor into digital data that can be understood and manipulated by the processor The ports on the SBC made it very easy to do I O operations without involving the data bus or any address lines at all This made the hardware construction very simple however it also meant software required to run the system ended up being very complicated since we were using the three serial ports to drive six I O devices the two DACs the ADC the servo motor the speaker and the oscilloscope Z input Block Diagram of Overall System SBC BOARD PC6 OSCILLOSCOPE IR SENSOR SERVO MOTOR SPEAKER IR APPARATUS The block diagram above describes how the system works with arrows indicating data flow Infra red sensor T
82. picked up ten distinct objects Since the detection of an object requires there to be a black space between them and a sweep able area of 90 degrees at 60cm this gives us a circumference of 94cm The side of the tube visible to the sensor is roughly 3cm i e half is circumference This would allow the detection of at least 20 objects provided there is enough blank space between two objects placed next to each other The sounds made by the speaker were quite decent and it corresponded to the distance between the object and the sensor 27 i Improvising using Smarties tubes This would no doubt make a very good Smarties commercial The pictures below show the positioning of three objects in radar mode and how they appeared on the oscilloscope and LCD display during a sweep 28 29 Tracker Mode The first part of the tracker test was simply to check whether the motor properly swept until it locked on to an object Once that proved successful the actual tracker bit was tested and it seemed to follow the object around quite well provided it moved slow enough at around 2cm s I then moved the object out of range several times and checked whether it made the tracker loop back to the zero degree position and start seeking for the object again I had one problem though I had initially forgot to put in checks for the extreme angles 0 and 180 degrees so everything just went haywire when the object was around t
83. red an entire port since a port can only work as either an input or output device but not both at the same time We knew we needed a bit each for the speaker the timer and the oscilloscope s Z input This left us with 13 bits to be shared between the X and Y inputs This actually made perfect sense The X input would require twice the number of bits as the Y inputs consider a semicircle with a certain radius it would be twice as long horizontally than vertically We decided to keep 7 bits 128 values for X and 6 bits 64 values for Y I realise this might seem like a pretty low resolution but once again everything fell in place perfectly I had decided to keep the operational range of the system between 10 and 60cm since beyond that the voltages returned by the sensor via the ADC were highly inconsistent e g 70cm often would return the same voltage as 75cm Even between 10 and 60cm distances returned were not very accurate I would say the accuracy was at its best at lcm division between 10 and 30cm and about 2cm from then on So having one pixel to represent on the oscilloscope seemed like a very good idea which is exactly what we had with 128 bits for X 64cm or pixels on each side and 64 bits for Y 64 bits or pixels Look Up Tables and Arrays Look up tables for were used for almost all conversions simply because some functions were simply too difficult to implement in assembly or would take up too many clock cycles Also we h
84. s cosine_table angle x radius if angle lt 90 then x_coord 64 x_coord else x_coord 64 x_coord end if y_coord sine_table angle x radius End get_coords Module get_distance reads in IR sensor from ADC and converts it to distance Takes 4 readings and does average for greater accuracy ADCSum 0 For I 1 to 4 ADCSum ADCSum Input_from_ADC Next distance distance_table ADCSum 4 End get_distance 18 DESIGN IMPLEMENTATION DETAILS AND ALTERNATIVES As I previously discussed briefly in the introduction our main objective was to keep the hardware as simple as possible not only because it is simply easier for us to put together but it also meant that the entire system would not break because of a simple mistake in wiring Input Output We decided to use the ports to perform all I O operations The good thing was that all these ports have dedicated data buses or so to speak which would mean they could be directly connected to each of the devices they are driving So there would be no need of lots of wires coming out of the data bus going into each of the devices If we had used a discrete I O scheme we would also need a decoder to enable each particular device at a time so that s one chip saved although I realise that hardly matters One major disadvantage of using just the three ports is that we only had 24 bits to share among all the devices The ADC definitely requi
85. t point x coord y coord Puts x coord into the lower 7 bits of PortB oscilloscope x input and y coord into the lower 6 bits of PortC oscilloscope y input Turns the oscilloscope beam on for a short while to plot the point on the oscilloscope and then tunrs the beam off beam on beam off get distance Reads value from ADC and using the distance table converts the ADC value into distance from sensor and stores this value in the global variable distance Four readings of distances are taken and only the average is returned display angle distanc e angle distance Displays current angle distance x coordinate and y coordinate on LCD screen uses display bin to dec to convert these numbers display bin to dec angle display bin to dec distance display bin to dec x coord display bin to dec y coord delay keypad display bin to dec number Converts the variable number which is in binary into a 3 digit decimal number and displays each of these digits on the LCD display character digit delay keypad display character register a Uses the ASCII code stored in register A to display the character on the LCD and then waits for a very short time to allow the character to appear on it delay keypad increase angle3 Increments global variable angle by 3 decrease angle3 Decrements global variable angle by 3 increase angle2 Increments global variable an
86. usted to form an ADC to Distance table since at some distances e g 53 and 54 the average ADC reading seemed to be the same at 30h so I had adjusted 54 to be 2Fh instead Please see Appendix C for the final lookup table made from this data Please note that my partner and I calibrated the sensor together so we are very likely to have almost the same distance look up table 24 Tests run with different distances to check if sensor calibrated properly Actual Distance Distance Distance Distance Distance Average MaxError Standard Distance Reading1 Reading2 Reading3 Reading4 Reading5 Distance Deviation 10 10 10 10 10 10 10 00 0 0 000 11 11 11 11 11 11 11 00 0 0 000 12 12 12 12 12 12 12 00 0 0 000 13 13 13 13 13 13 13 00 0 0 000 14 14 14 14 14 14 14 00 0 0 000 15 15 15 15 15 15 15 00 0 0 000 16 16 16 16 16 16 16 00 0 0 000 17 17 17 17 17 17 17 00 0 0 000 18 18 18 18 18 18 18 00 0 0 000 19 19 19 19 19 19 19 00 0 0 000 20 20 20 20 20 20 20 00 0 0 000 21 21 21 21 21 21 21 00 0 0 000 22 22 22 22 22 22 22 00 0 0 000 23 23 23 23 23 23 23 00 0 0 000 24 24 24 24 24 24 24 00 0 0 000 25 25 25 25 25 25 25 00 0 0 000 26 26 26 26 26 26 26 00 0 0 000 27 27 27 27 27 27 27 00 0 0 000 28 28 28 28 28 28 28 00 0 0 000 29 29 29 29 29 29 29 00 0 0 000 30 30 30 30 30 30 30 00 0 0 000 31 31 31 31 31 31 3
87. when the keypad or the clocks generate an interrupt init_ports Sets it such that PortA is used for input ADC PortB is used for output Z and X inputs for the oscilloscope and PortC is used for output speaker servo motor and oscilloscope Y inputs init angleO Sets angle to 0 degrees loads appropriate reload values into timer enables it gives the servo ample time using delay servo full to rotate to 0 degrees and then disables timer0 enable_servo_timer servo_delay_full disable_servo_timer init_angle44 Sets angle to 44 degrees loads appropriate reload values into timer0 enables it gives the servo ample time using delay servo full to rotate to 44 degrees and then disables timer0 enable servo timer servo delay full disable servo timer delay servo full Produces a just about long enough delay for the servo to rotate a large angle gt 90 degrees delay servo short Produces a just about long enough delay for the servo to rotate a large angle 5 degrees delay keypad Produces a just about long enough delay required for a character to appear on the LCD display menu Displays the main menu options on LCD display radar mode Displays Radar Mode on LCD display profiler mode Displays Profiler Mode on LCD display tracker seekin g Displays Tracker Seeking on LCD display_tracker_locke d Displays Tracker Locked on LCD

Download Pdf Manuals

image

Related Search

Related Contents

取 扱 説 明 書  Add-on Application Guide  Ergotron Worksurface for WorkFit-S  23.6“ LED Monitor mit HD-SDI (TVAC10050)  HP Color LaserJet Pro MFP M176n  L offensive russe  MT Propeller  Revista da Procuradoria  Genesis 1000  Osram LIGHTIFY CLASSIC A TW  

Copyright © All rights reserved.
Failed to retrieve file