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

192  COUtltl  G PUISES: A PnOGRA|I|IABLE tACHOfllEtEn



                    So on the one  hand,  high-count encodels are desirable at low speeds; on the other hand
                    they become a  prcblem at high speed. A corcllary to fhis is that it is very difiicult  to run
                    a shaft accuately at low speed wiihout some sol1 of gearing  or belt reductiorl Think
                    about the problems you would encounter tying  to run a shaft  at I revolution per year
                    accurately directly with a moror
                      If our specification calls for a maximum  speed of 3600 rpm our encoder cat?r?ot have
                    more  than 300 counts  pei rcvolution if we want to maintain the counting time. Using a
                    shorter time will  help on the high  rym  end but will  make things harder in the low rpm
                    region, Of coulse, we can also use an encoder with many fewer counts and have a  per-
                    f-ectly  good  tachometer
                      The soflware we are using employs integer math, and the largest variable we can use
                    is a 2-byte word. The largest number 2 bytes can accommodaie is 65535-  This means
                    that in the COIJNT instruction:
                     couNt PoRTA- 2,  250, r,t1

                      The number that ends up in Wl  cannot exceed 65535. We can accommodate this
                    requirement by shotening the 250 millisecond (or less) time frame, but then we will
                    have  problems  with the 60-rpm end of the  specification-  The solution  is to use  the lowest
                    count that will  ser,/e our purposes  on the  shaft encoder at the  lowest speed we are inter-
                    ested in. If we use the  20 counts  per  revolution we discussed earlie!  we will  be  getting
                       *
                    (20  3600 / 60)  =  1200 counts every second and a qua  er of that every 0.25 seconds
                    or 300 counts every second, This indicates that we could use an elcoder with a few hun-
                    dred lines per revolution if accurate slow speed irdication  was an important consider-
                    ation. However, adding a higher count encoder to an existing shaft may not be trivial,
                    and adding a f-ew  (even 1) equally spaced markers  onto the shaft  manually with a little
                    epoxy or paint may be adequate for what we need.
                      There is also the  possibility that we could write software that would use different rcu-
                    tines for different speeds of the signal, but for this projecr let's keep it simple. Such
                    sophi stications can be added after we get proficient at doing the work at hand. The most
                    important thing to keep in mind is that you must understand the problem in a compre-
                    hensive way before you can create a solution.


                    DETECTIOI{

                    Next, we must consider the components and circuitry needed to actually react rdth the
                    signal we are trying to measue (or collect). The simplest way to do this is to react to
                    the changes in the light intensity either as reflected from marke$ on the shaft or as a
                    disturbance of some other kind in the vicinity. Hall effect sensors  are a  popular  way of
                    detecting rotation in a dity  environment because they are rot  afected by  anything
                    other than magnetic fields. The signal must be converted to a  TTUCMOSlevel  signal
                    that  goes  high and low reliably with every  change  in the stimulus. Fjgure  15.5  shows
                    one way to create  such  an instrument  jnterface  for the hall effect device.
                      Since  the input to the PIC are Schmidt triggers, we would not nomally  have to con
                    dition the signal for bounce and  jitter
   191   192   193   194   195   196   197   198   199   200   201