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

sElTtt{c uP THE HARDWAnE
                                                                         CO |{ECT|O|{S  271

                     If we mount  the sensor on rhe  base that will be tilring, we  will gel  euor signals thar
                  we will  interpret, and then output the corecrions ro rhe target table. We lnay have ro
                                                                jn
                  create  a lookup table if there is any nonlircarity  e:ther  lhc respoDse of the sensor  or
                  the mechanical linkages  that connect the base  to the top. In this case, rhe  signal we detcct
                  is absolutely related  to the  position  ofrhe base. We are rcading rhe  actual eror at the
                  base. What we do with the sigml is up to us, and how we design rhe ljnkages  1() level
                  thetableis  also up to us. This is not  the best way to do it in mostcases,  but this method
                  may be  the only one available to  us in some situarions.
                    Ifwe  mount  the sensor to the  top table, the signal we get  will be a neasure ofhow
                  far the  table has tilted. We can  make the table come  back !o horizonral if we keeo
                   mahng  an inlegicring cnrreclion  !ill rh< rlrble  becnmec hori,/onnl: ue 5rup \r hen the  enor
                  signal  goes  to zero. It is an integntive  process  over time.  (If we wanred ro know  how
                  large the coffection \'r'as,  we would have Io keep track of how far we had moved the
                  table to get it back to horizontal, bur we do not need rhis information in an inlegraring
                  systern.)
                     Simply stated: it is better to mount  lhe deiector. to the actual  table because rhat is the
                  sudace we are interested in keeping  level. It is besr ro ger  the  error signal as directly as
                  possibler  at the soulce.



                   Setting            the    Hardware
                                Up
                                                               Connections
                  The instnrment/controller
                                         we will create needs to read two inputs  ftom the sensor and
                  put out two oulputs to the servos. Thc inputs are in the form ot two fiequencies we
                  will read  ftom the X-Out and Y-Out  conneciors ofthe sensor, and our ouiputs are rhe
                  two L to 2 millisecond  pulses  wc will output to rhe radio  conrol hobby servos_  See
                  Figure  19.2.
                    The PBP language has  a conrmand  (PULSOUT) that lets us outpur appropriate  pulses
                  on PORTC.O and PORTC.l  on the LAB,X l. but in this exercise we  will create our own
                  pulses  with the PAUSEUS command.  However, we are srill ried !o PORTC.0 and
                  PORTC.
                          I because that is how the  circuify lbr rhe LAB-X I is  laid out. The servo ourpur
                  pins  on the LAB  Xl  are hard wired ro PORTC.o and PORTC.I.  The seNos are fed from
                  these  lwo  pins.Ifwe  were laying  out a new board, we  could choose ro use any free  por,
                  pins.
                    We will use a  ten-pin connector P2  on thc LAB Xl  for all our connections  because
                  that is the connector  that has PORTC.0  and PORTC.I on ir. This  will atlow us ro use
                  PORTC.2and  PORTC.3 as the inputs  aom fte gravity  sensorand  so all the connecrions
                  can  be on one fbur-pin cable. The  se  os can  plug  into the  standard selvo connectors at
                  J? and J8- The  circuitry for this is shown in Figure 19.2.
                    First, leas  write a program  to get  a feel fbr wbar kind  of pulses  we are  going  ro be
                  getting  from the Memsic sensor  (we are interested in the  pulse  width, the frequency, and
                  the range).  To do this, we need  to read the  pulses  from  just  one of the outputs  and dis-
                  play  them on the LCD as we move one axis rhough  I 80 degrees. Ler's arbirrarily  decide
                  on the x axis output and write a  program  ro rcad  it. See Program I 9. I _
   267   268   269   270   271   272   273   274   275   276   277