Datasheet

Table Of Contents
2010 Microchip Technology Inc. Preliminary DS39979A-page 289
PIC18F87J72 FAMILY
Example 22-1 provides a general outline for imple-
menting a driver routine for the AFE. Example 22-2
through Example 22-5 show the details for each step.
The example shown here assumes the following
loopback connections:
RC4 (SDI) to SDOA
RC5 (SDO) to SDIA
RC3 (SCK) to SCKA
RD0 to ARESET
RD7 to CSA
RC2 (CCP1) to CLKIA
RB0 (INT0) to DR
Aside from the SPI, which is determined by the
microcontroller’s single MSSP module, the other
connections may change based on the particular appli-
cation’s requirements. For example, the AFE clock on
CLKIA is generated from the PWM of CCP1 in this
demonstration; other clock sources may be available.
Users should modify the individual code segments
accordingly.
EXAMPLE 22-1: OVERALL STRUCTURE FOR USING THE AFE
///////////////////////////////////////////////////////////////////////////////////////////////
// Outline of a typical driver routine for the dual-channel AFE.
///////////////////////////////////////////////////////////////////////////////////////////////
#include "p18F87J72.h"
void main(void)
{
///////////////////////////////////////////////////////////////////////////////////
// STEP 1:Initialize MSSP (Example 22-2)
////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
// STEP 2: Issue Reset to AFE (Example 22-2)
/////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
// STEPS 3: Disable all Chip Selects on all SPI devices (Example 22-2)
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// STEP 4: Write to AFE registers; read back (optionally) to confirm settings (Example 22-4)
////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
// STEP 5: Configure CCP1 to serve as AFE clock source (Example 22-3)
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
///STEP 6: Configure Interrupt INT0 for use with DR pin (Example 22-3)
/////////////////////////////////////////////////////////////////////////////////////////////
while(1);
}
/////////////////////////////////////////////////////////////////////////////////////////////
//STEP 7: ISR for reading AFE data (Example 22-5)
////////////////////////////////////////////////////////////////////////////////////////////