Page 242 - Making PIC Microcontroller Instruments and Controllers
P. 242

GIHECOU TERS!  COU TI  G  ITARBLES
             240   UNDEBSTANDI

                    Counting  with an  Escapement


                                   "escapemenfbased"
                                                     counling  program  step  by s!ep, segmenl  by  seg
                    LeCs  develop  the
                    mcnt,  as we werejust  aliscussing.At  staft oftbe  program' we need to wait  for a signal
                                                  the
                    to slart  the colrnling  process. At this  point,  the top  gale  must bl}  open and the  lower  gate
                    muslbe  closeal. When  the lirst  maible amves  on top of  the boltom  gate.  wcwill be ready
                    to stai counting.  We assume  lhc other  na$les are in  position,  but this-as we  will see
                    may not necessarily be lhe case,  meaning that  our software  must  accommodate  all
                    possibili!ies.
                       The hardware  we will respond to and conlrol  consisls of the follov"rng  ilems connected
                     as  indicatedl

                       Infrared LED power  on  PORTD.I
                       Infrared  LED ground  to gr,ound

                                    power  on  PORTB
                       Phototransistor              l
                       Photolransi  stor  ground to ground

                                    signal  to POmB.0
                       Phototransistor
                       Top seNo  on  PORTC.I to the servo  pins
                       Bottom servo  on PORTC.2  to the servo  pins
                       We  will u se switch  I connected  between  line PORTB.4  and  ground  to start the  count_
                       irg process.  PORTB.4  will be  pulled  up  internally  with OPIION-REC 7=0

                       The  rviring schematic  for thc  preceding  description  is shown in Figure 17  4'






                                5 VOLTS                                  5 VOLTS


                                       -4











              rl:FiiU.-iiSilt],4li  The  two ways of  doing schematic  wiring  diagrams  lor lR'LED  phototransislor
   237   238   239   240   241   242   243   244   245   246   247