Page 256 - Mechatronics with Experiments
P. 256

242   MECHATRONICS
                              PIC 18F4431 Microcontroller      The PIC 18F4431 version of the PIC 18Fxxxx
                              family microcontrollers has a quadrature encoder interface at the following pins for an
                              incremental encoder interface:
                                  RA2, RA3, RA4 for Index (INDX), Channel A (QEA), Channel B (QEB), respec-

                                  tively.
                              It also supports 8 channels of PWM output via the following pins:
                                  RB3:0, pins 0 through 3, can be configured for PWM0, PWM1, PWM2, PWM3,

                                  respectively.
                                  RB4 and RB5 pin can be configured for PWM5 and PWM4 output signals,
                                  respectively.
                                  RD6 and RD7 pins can be configured for PWM6 and PWM7 output.

                                   Interrupts on-change-of-state for pins RB pins 4 through 7 (RB7:4) are effective only
                              if these pins are configured as input. If any of these pins is configured for output, the
                              interrupt for that pin is disabled.
                                   Timers on PIC 18F4431 are TIMER0, TIMER1, TIMER2, and TIMER5. The timer
                              control register for each timer (T0CON, T1CON, T2CON, T5CON) is an 8-bit register
                              which is used to configure (control) the operation of the timer. The bits allows us to:
                              enable/disable timer mode or counter mode, 8-bit or 16-bit mode, clock source (internal or
                              external), pre-scaler/post-scaler values. Timer 2 and Timer 5 have PR2 and PR5 re-registers
                              which define the maximum value to which the timer is to count, then roll-over and generate
                              interrupt. Timer 1 and CCP1 compare configurations that can be used to trigger a periodic
                              “ADC conversion start” trigger to the ADC module. Timer 2 can be used as the source to
                              define the period (base frequency) of the PWM output pin. Other timers generate interrupt
                              when the counting from 00h to FFh is complete and overflow to 00h occurs. For counter
                              operation, an external source should be selected. In this mode, pre and post-scaling values
                              are used. In timer mode, pre and post-scaler values are ignored and timers are incremented
                              every instruction cycle. For each timer, if the interrupt is enabled via the corresponding
                              interrupt enabled bit on the corresponding timer control register, when a timer interrupt
                              occurs, the corresponding timer interrupt flag is set.
                                   Motion feedback module (MFM) has a quadrature encoder interface (EQI), which
                              is used to interface to an incremental encoder for position feedback. Once the position
                              feedback is available, the microcontroller can perform closed loop position control in any
                              actuated motion control system, that is electric or electro-hydraulic or pneumatic. The QEI
                              interface has three pins: QEA, QEB, INDX which are to be connected to the A, B, and
                              Index channels of an incremental encoder (the Index channel of an incremental encoder is
                              sometimes referred as Index C or Z). Using the pulses on Channel A and B, and the phase
                              relationships between them, the module keeps track of position information using a 16-bit
                              up/down counter register. An INDX pin can also be connected to another external digital
                              input other than the Encoder’s Index channel, that is a registration sensor (see Chapter 10
                              for registration applications and possible use of these).
                                   The following registers are used in the configuration and use of the MFM (QEI)
                              module:


                              QEICON    8-bit   configuration register
                              POSCNT    16-bit up/down counter: position register

                              MAXCNT    16-bit maximum count register
   251   252   253   254   255   256   257   258   259   260   261