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

soME REIL-WOR| D ||OTES   243


                                                                           (Cort  nued)
                 ,tif-6lCi!f  :li:Lilt  Program  lo count marbles with an escapement
                   DISABIJE                      ;  disable   interrupts
                   INT_ROIITINE:                 ;  the  interrupL   rouLine   is  called
                                                 ,  everv  1/60
                     PULSour  PoRTC.1,  POTo     ;  of  a  second  and  pulses  both  servos
                                                 i . a
                     PUT-SOtxr PORTC.o,  POT1    ;  theii   se!  values.   Then  ir
                     Iri|l!coN.2=o               ;  resets  the  interrupt   flag  for  Tinero
                   R.ESUME                       ;  resune  progran
                   ENAaLE                        ;  enable  inLerrupts
                   PAUSER:                       ;  this   routine   is  read  fron  POTo and
                     FOR AIPI{A  =1  TO Pqr2     ;  delernines   how  long  it  is  betveen
                       PAUSE 2                   ;  inslruciions   !o  lhe  servos-
                     NEXT AI-PEA                 ;  adjust   it  uith   POl'o
                   RETURN                        ;  do  no!  nake  it  !o  shor!
                   E N D                           ^ ' l  p . o o , a  s  - - d  -  \ D .

                    The program starts out with both  gates  closed.
                                                       "wallloop"
                    The code  in Program l7-2 wiil  stay  in the   ntil switch I is pressed.
                    That opens the top gate  and the system is ready to count.

                    As  soon as a marble  stops againsl the lower  gate, the marble is detectsd. the top gate
                    closes and the bofton  gate opens.

                    One  is added to the counl3r  (.at  this  point a  dnot  dny soo er or later).
                    The botton  gate  closes.
                    The top gate  opens and the cycle is repeated.
                    When there are no more marbles.  the system stops.

                    Press reset to staft over.



                  Some Real-World Notes


                  If we were designing  for a  real  world situation. we would add some  type of detectors
                  !o makc swe thc  gates  actually went in and out as intendcd. Proximity detectors of some
                  sol  arc rhe detectors of choice in thal they have no moving pa  s. we would probably
                  use  pneumatic  actuato$ and run fte  operation lrom a prcgrammable  logic controller
                  (PLC),  though as we saw in this exercise, aPIC wouldbe much cheaper and would do
                  thejobjust line. The system could also,  ()1-course.
                                                           be designed !o use two solenoids  wilh
                  appropriate IN/OUT detectors.
                    The  preceding  is the simplest way to count the marbies, but it is  pdi,l4rlb  rlorr. Slow
                  enoush to  be  counted with an  exDensive PLC!
   240   241   242   243   244   245   246   247   248   249   250