Page 118 - PDA Robotics Using Your Personal Digital Assistant to Control Your Robot
P. 118

PDA 05  5/30/03  11:35 AM  Page 94
                               •
                                    Set GIE bit.
                               •    Set PEIE bit.    PDA Robotics
                            3. Wait for the required acquisition time.
                            4. Start conversion:
                               •    Set GO/DONE bit (ADCON0).

                            5. Wait for A/D conversion to complete, by either:
                               •    Polling for the GO/DONE bit to be cleared (with interrupts
                                    enabled); or
                               •    Waiting for the A/D interrupt.

                            6. Read A/D result register pair (ADRESH:ADRESL); clear bit ADIF
                               if required.

                            7.  For the next conversion, go to step 1 or step 2, as required. The
                               A/D conversion time per bit is defined as TAD. A minimum wait
                               of 2TAD is required before the next acquisition starts.

                          Once again, the C compiler we are using in this project takes care of
                          the preceding steps in a few simple lines of code!


                          Timer0 Module.    The Timer0 module timer/counter has the follow-
                          ing features:

                          •    8-bit timer/counter

                          •    Readable and writable

                          •    8-bit software programmable prescaler
                          •    Internal or external clock select
                          •    Interrupt on overflow from FFh to 00h

                          •    Edge select for external clock

                          Figure 5.40 is a block diagram of the Timer0 module and the prescaler
                          shared with the WDT.
                          Timer  mode  is  selected  by  clearing  bit  T0CS  (OPTION_REG<5>).  In
                          Timer mode, the Timer0 module will increment every instruction cycle
                          (without prescaler). If the TMR0 register is written, the increment is

                          94
   113   114   115   116   117   118   119   120   121   122   123