MCP3901 ADC Evaluation Board
for 16-Bit MCUs User’s Guide
2010 Microchip Technology Inc.
DS51845B
Note the following details of the code protection feature on Microchip devices:
•
Microchip products meet the specification contained in their particular Microchip Data Sheet.
•
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•
Microchip is willing to work with the customer who is concerned about the integrity of their code.
•
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR
WARRANTIES OF ANY KIND WHETHER EXPRESS OR
IMPLIED, WRITTEN OR ORAL, STATUTORY OR
OTHERWISE, RELATED TO THE INFORMATION,
INCLUDING BUT NOT LIMITED TO ITS CONDITION,
QUALITY, PERFORMANCE, MERCHANTABILITY OR
FITNESS FOR PURPOSE. Microchip disclaims all liability
arising from this information and its use. Use of Microchip
devices in life support and/or safety applications is entirely at
the buyer’s risk, and the buyer agrees to defend, indemnify and
hold harmless Microchip from any and all damages, claims,
suits, or expenses resulting from such use. No licenses are
conveyed, implicitly or otherwise, under any Microchip
intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, dsPIC,
KEELOQ, KEELOQ logo, MPLAB, PIC, PICmicro, PICSTART,
PIC32 logo, rfPIC and UNI/O are registered trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
FilterLab, Hampshire, HI-TECH C, Linear Active Thermistor,
MXDEV, MXLAB, SEEVAL and The Embedded Control
Solutions Company are registered trademarks of Microchip
Technology Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, CodeGuard,
dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN,
ECONOMONITOR, FanSense, HI-TIDE, In-Circuit Serial
Programming, ICSP, Mindi, MiWi, MPASM, MPLAB Certified
logo, MPLIB, MPLINK, mTouch, Omniscient Code
Generation, PICC, PICC-18, PICDEM, PICDEM.net, PICkit,
PICtail, REAL ICE, rfLAB, Select Mode, Total Endurance,
TSHARC, UniWinDriver, WiperLock and ZENA are
trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
© 2010, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.
ISBN: 978-1-60932-571-8
Microchip received ISO/TS-16949:2002 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Company’s quality system processes and procedures
are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
DS51845B-page 2
2010 Microchip Technology Inc.
MCP3901 ADC EVALUATION BOARD
FOR 16-BIT MCUs USER’S GUIDE
Table of Contents
Preface ........................................................................................................................... 5
Introduction............................................................................................................ 5
Document Layout .................................................................................................. 5
Conventions Used in this Guide ............................................................................ 6
Recommended Reading........................................................................................ 7
The Microchip Web Site ........................................................................................ 7
Customer Support ................................................................................................. 7
Document Revision History ................................................................................... 7
Chapter 1. Hardware Description
1.1 Overview ........................................................................................................ 9
1.2 PIM Module/MCP3901 Connection and Peripheral Usage Overview .......... 11
1.3 MCP3901 Delta-Sigma Sampling/MCLK Options ........................................ 12
1.4 Analog Input Structure .................................................................................. 13
1.5 Universal Serial Bus (USB) .......................................................................... 13
Chapter 2. Firmware
2.1 DSPIC33 Firmware Description ................................................................... 15
2.2 Data Acquisition ........................................................................................... 16
2.3 UART Communication Protocol ................................................................... 18
Chapter 3. MCP3901 PC Software Tool
3.1 Software Overview ....................................................................................... 21
3.2 Setting the Configuration of the ADC ........................................................... 22
3.3 Connectivity and Recording Length ............................................................. 22
3.4 Scope Plot Window - Time Domain Analysis ............................................... 22
3.5 Histogram Window – Noise Analysis ............................................................ 22
3.6 FFT Window – Frequency Domain Analysis ................................................ 23
2010 Microchip Technology Inc.
DS51845B-page 3
MCP3901 ADC Evaluation Board for 16-Bit MCUs User’s Guide
Appendix A. Schematics and Layouts
A.1 Introduction .................................................................................................. 25
A.2 Schematic – Analog ..................................................................................... 26
A.3 Schematic – LCD and UART ...................................................................... 27
A.4 Schematic – USB and Memory .................................................................... 28
A.5 Schematic – Microcontroller (MCU) ............................................................. 29
A.6 Schematic – PIM Module ............................................................................. 30
A.7 Schematic – Power ...................................................................................... 31
A.8 Board – Top Trace and Top Silk .................................................................. 32
A.9 Board – Bottom Trace and Bottom Silk ........................................................ 32
A.10 Board – Layer #2 VDD .............................................................................. 33
A.11 Board – Layer #3 GND .............................................................................. 33
A.12 Board – Top Silk and Pads ........................................................................ 34
A.13 Board – Bottom Top Silk and Pads ............................................................ 34
Appendix B. Bill Of Materials (BOM)
Worldwide Sales and Service .....................................................................................38
DS51845B-page 4
2010 Microchip Technology Inc.
MCP3901 ADC EVALUATION BOARD
FOR 16-BIT MCUs USER’S GUIDE
Preface
NOTICE TO CUSTOMERS
All documentation becomes dated, and this manual is no exception. Microchip tools and
documentation are constantly evolving to meet customer needs, so some actual dialogs
and/or tool descriptions may differ from those in this document. Please refer to our web site
(www.microchip.com) to obtain the latest documentation available.
Documents are identified with a “DS” number. This number is located on the bottom of each
page, in front of the page number. The numbering convention for the DS number is
“DSXXXXXA”, where “XXXXX” is the document number and “A” is the revision level of the
document.
For the most up-to-date information on development tools, see the MPLAB® IDE on-line help.
Select the Help menu, and then Topics to open a list of available on-line help files.
INTRODUCTION
This chapter contains general information that will be useful to know before using the
MCP3901 ADC Evaluation Board for 16-Bit MCUs. Items discussed in this chapter
include:
•
•
•
•
•
•
Document Layout
Conventions Used in this Guide
Recommended Reading
The Microchip Web Site
Customer Support
Document Revision History
DOCUMENT LAYOUT
This document describes how to use the MCP3901 ADC Evaluation Board for 16-Bit
MCUs as a development tool to emulate and debug firmware on a target board. The
manual layout is as follows:
• Chapter 1. “Hardware Description”– Provides important information about the
MCP3901 ADC Evaluation Board for 16-Bit MCUs hardware.
• Chapter 2. “Firmware”– Describes the MCP3901 ADC Evaluation Board for
16-Bit MCUs firmware.
• Chapter 3. “MCP3901 PC Software Tool” – Provides detailed information about
board’s PC software tool.
• Appendix A. “Schematics and Layouts”– Shows the schematic and board
layouts for the MCP3901 ADC Evaluation Board for 16-Bit MCUs.
• Appendix B. “Bill Of Materials (BOM)” – Lists the parts used to build the
MCP3901 ADC Evaluation Board for 16-Bit MCUs.
2010 Microchip Technology Inc.
DS51845B-page 5
MCP3901 ADC Evaluation Board for 16-Bit MCUs User’s Guide
CONVENTIONS USED IN THIS GUIDE
This manual uses the following documentation conventions:
DOCUMENTATION CONVENTIONS
Description
Arial font:
Italic characters
Initial caps
Quotes
Underlined, italic text with
right angle bracket
Bold characters
N‘Rnnnn
Text in angle brackets < >
Courier New font:
Plain Courier New
Represents
Referenced books
Emphasized text
A window
A dialog
A menu selection
A field name in a window or
dialog
A menu path
MPLAB® IDE User’s Guide
...is the only compiler...
the Output window
the Settings dialog
select Enable Programmer
“Save project before build”
A dialog button
A tab
A number in verilog format,
where N is the total number of
digits, R is the radix and n is a
digit.
A key on the keyboard
Click OK
Click the Power tab
4‘b0010, 2‘hF1
Italic Courier New
Sample source code
Filenames
File paths
Keywords
Command-line options
Bit values
Constants
A variable argument
Square brackets [ ]
Optional arguments
Curly brackets and pipe
character: { | }
Ellipses...
Choice of mutually exclusive
arguments; an OR selection
Replaces repeated text
Represents code supplied by
user
DS51845B-page 6
Examples
File>Save
Press ,
#define START
autoexec.bat
c:\mcc18\h
_asm, _endasm, static
-Opa+, -Opa0, 1
0xFF, ‘A’
file.o, where file can be
any valid filename
mcc18 [options] file
[options]
errorlevel {0|1}
var_name [,
var_name...]
void main (void)
{ ...
}
2010 Microchip Technology Inc.
Preface
RECOMMENDED READING
This user's guide describes how to use MCP3901 ADC Evaluation Board for 16-Bit
MCUs. Other useful documents are listed below. The following Microchip document is
available and recommended as supplemental reference resources:
MCP3901 Data Sheet - “Two Channel Delta Sigma A/D Converter”, DS22192
THE MICROCHIP WEB SITE
Microchip provides online support via our web site at www.microchip.com. This web
site is used as a means to make files and information easily available to customers.
Accessible by using your favorite Internet browser, the web site contains the following
information:
• Product Support – Data sheets and errata, application notes and sample
programs, design resources, user’s guides and hardware support documents,
latest software releases and archived software
• General Technical Support – Frequently Asked Questions (FAQs), technical
support requests, online discussion groups, Microchip consultant program
member listing
• Business of Microchip – Product selector and ordering guides, latest Microchip
press releases, listing of seminars and events, listings of Microchip sales offices,
distributors and factory representatives
CUSTOMER SUPPORT
Users of Microchip products can receive assistance through several channels:
•
•
•
•
Distributor or Representative
Local Sales Office
Field Application Engineer (FAE)
Technical Support
Customers should contact their distributor, representative or field application engineer
(FAE) for support. Local sales offices are also available to help customers. A listing of
sales offices and locations is included in the back of this document.
Technical support is available through the web site at: http://support.microchip.com.
DOCUMENT REVISION HISTORY
Revision A (July 2009)
• Initial Release of this Document.
Revision B (October 2010)
• Minor grammatical changes throughout document. No technical information has
changed.
2010 Microchip Technology Inc.
DS51845B-page 7
MCP3901 ADC Evaluation Board for 16-Bit MCUs User’s Guide
NOTES:
DS51845B-page 8
2010 Microchip Technology Inc.
MCP3901 ADC EVALUATION BOARD
FOR 16-BIT MCUs USER’S GUIDE
Chapter 1. Hardware Description
1.1
OVERVIEW
The MCP3901 ADC Evaluation Board for 16-Bit MCUs system provides the ability to
evaluate the performance of the MCP3901 dual channel ADC. It also provides a
development platform for 16-bit PIC® MCU-based applications, using existing 100-pin
Plug-in Module (PIM) systems compatible with the Explorer 16 and other high pin count
PIC MCU demo boards. The system comes with programmed dsPIC33FJ256GP710
PIM modules that communicate with the LabVIEW™ software GUI for data exchange
and ADC setup.
1.1.1
Feature Highlights
• Dual ADC MCP3901 output display using serial communication to PC software
interface
• Simultaneous 4 ksps at 90 dB SINAD and top speed of 55 ksps performance on
dual MCP3901 channels
• System and ADC performance analysis through graphical PC tools showing noise
histogram, frequency domain (FFT), time domain scope plot, and statistical
numerical analysis
• Robust hardware design with analog grounding and analog/digital separation,
allowing low noise evaluation of MCP3901 devices. Separate power supplies and
power planes – 4 layer board
• PICtail™ Plus connectors for Explorer 16 daughter board compatibility
2010 Microchip Technology Inc.
DS51845B-page 9
MCP3901 ADC Evaluation Board for 16-Bit MCUs User’s Guide
CH0+
GND
CH0-
G
CH1+
GND
CH1-
+ MCP3901
G
-
+
-
+
-
EXT +5V
Serial Connector
EXT +5V
+9V IN
USB
PIM RESET
MCP3901
Digital I/O
SW2
SW3
SW4
RA9
USB
+3V
REG
PWR LED
(Blue)
PIC18F86J65
PIC18 AUX I/O
SRAM
PICtail™ Plus
PIC18 ICD
PIC18 ICD
9V EXT. IN
+5V
REG
RA10
PIM (100-PIN)
PIC18 EXTERNAL I/O
MCP3901 ADC Evaluation Board for 16-Bit MCUs
FIGURE 1-1:
DS51845B-page 10
MCP3901 ADC Evaluation Board for 16-Bit MCUs.
2010 Microchip Technology Inc.
Hardware Description
1.2
PIM MODULE/MCP3901 CONNECTION AND PERIPHERAL USAGE
OVERVIEW
The MCP3901 ADC Evaluation Board for 16-Bit MCUs contains a 100-pin PIM socket
compatible with Microchip’s PIM modules. The system comes with 2 PIM modules: the
PIC24FJ128GA010 and dsPIC33FJ256GA710.
A complete description of the firmware programmed with these two modules is
available in Chapter 1. “Hardware Description”.
D6 D7
RA9/10
RB8/9/10
(Green)
CONTROL SWITCHES (X3)
RF2/U1RX
UART SERIAL TO PC COMMUNICATION
RF3/U1TX
OC1/RD0
AGND
DGND
MDAT0
MDAT1
IC4/RD11
IC3/RD10
OSC2
DVDD
Modulator
Output
Translation
Block
RA4
SCK1/RF6
SDI1/RF7
SDO1/RF8
PIM Module
FIGURE 1-2:
CS
SCK
SDO
SDI
SPI Serial
Interface
SINC3
Digital Filter
INT3/RA4
DR
SINC3
Digital Filter
RESET
AVDD
Clock Generation/
Phase Correction
Current Boost
Circuit
RA5
OSC1
INT
VREF
CH0+
Delta Sigma
Multi-Level
Modulator
+
PGA
-
CH0-
Delta Sigma
Multi-Level
Modulator
+
PGA
CH1+
-
CH1-
MCP3901
Digital Connection Overview PIM/MCP3901 Connections.
Ports A, B, and D are used for signals such as push buttons, output LEDs, CS and
MCLR (for MCP3901 data mode setting). Output Capture 1 is used for MCP3901’s
clock generation. Serial communication is achieved through the MSSP module 1.
2010 Microchip Technology Inc.
DS51845B-page 11
MCP3901 ADC Evaluation Board for 16-Bit MCUs User’s Guide
1.3
MCP3901 DELTA-SIGMA SAMPLING/MCLK OPTIONS
The MCP3901 device is an ADC with a second order modulator and a third order sync
filter. This Delta-Sigma A/D converter has an adjustable oversampling ratio. The CLKIN
pin of the MCP3901 is the oversampling clock (MCLK) input. The MCP3901 ADC
Evaluation Board for 16-Bit MCUs offers two different options for the MCP3901 master
clock (MCLK).
1.3.1
Using the Crystal X2
The MCP3901 ADC Evaluation Board for 16-Bit MCUs is populated with a 3.58 MHz
crystal, which is used as a clock source by placing jumpers in the following position on
the MCP3901 Digital I/O header block:
CLKOUT
CLKIN
CLKIN
FIGURE 1-3:
1.3.2
XTAL
XTAL
PIM OC1
ADC Clock Selection Jumpers – External Crystal.
Driving the Clock with the PIM Module
The PIC MCU can be used to generate the CLKIN (MCLK) signal for the MCP3901,
setting the ADC sample rate through the use of the output compare module OC1. To
use this, make the following jumper change to the MCP3901 Digital I/O header block:
CLKOUT
CLKIN
CLKIN
FIGURE 1-4:
XTAL
XTAL
PIM OC1
ADC Clock Selection Jumpers – Clock from MCU.
The frequency of the OC1 output is based on the PR1 bits settings in the firmware
(for both PIC24 and dsPIC33 PIM modules supplied with this system). The signal
frequency from OC1 can be changed by the user from the PS software by changing the
value in the sampling rate control box. A low number will generate a high frequency signal. The value of the sampling rate, which is directly proportional with the clock
frequency from OC1, is indicated in the sampling speed indicator box in the PC
software (see Figure 3-1).
DS51845B-page 12
2010 Microchip Technology Inc.
Hardware Description
1.4
ANALOG INPUT STRUCTURE
Two differential input paths allow external signal sources to be easily connected to the
MCP3901 input. Edge connectors JP1 and JP2 are 3-pin connectors that act both as
crew type and clip on post connectors.
Note:
To use an edge connector as a post connector, pull up the blue plastic top
to access posts.
JP1 and JP2 can be used to force either channel from a differential to single-ended
configuration. R3 and R4 (on CH0), and R1 and R2 (on CH2) act as locations for
burden resistor connectors for any current transformer inputs.
1.5
UNIVERSAL SERIAL BUS (USB)
The MCP3901 ADC Evaluation Board for 16-Bit MCUs also contains a USB connection
for higher speed sampling and data collection. The circuit includes a 512x8 SRAM for
data collection. Figure 1-5 summarizes the connections between the ADC, the two
microcontrollers and memory.
Note:
For the MCP3901 ADC Evaluation Board for 16-Bit MCUs release, no USB
firmware is supplied. The PIC18F86J55 is blank and only included for
development purposes.
SRAM
512x8
USB
PIC18F86J55
8
RD6/SCK2
2010 Microchip Technology Inc.
SCK2/RG6
RF6/SCK1
SCK
RD4/SDO2
SDI2/RG7
RF7/SDI1
SDO
RD5/SDI2
SDO2/RG8
RF8/SDO1
SDI
RD7/SS2
SS2/RG9
USB
FIGURE 1-5:
MCP3901
ADC
I
SERIAL
USB Block Diagram.
DS51845B-page 13
MCP3901 ADC Evaluation Board for 16-Bit MCUs User’s Guide
NOTES:
DS51845B-page 14
2010 Microchip Technology Inc.
MCP3901 ADC EVALUATION BOARD
FOR 16-BIT MCUs USER’S GUIDE
Chapter 2. Firmware
2.1
DSPIC33 FIRMWARE DESCRIPTION
2.1.1
Reset and Initialization
After reset, the global variables ConfigHValue, ConfigLValue, GainValue, and
StatusComValue are written to 0x00. These variables will be written with values
received from the PC, to set up the MCP3901 as required. Next, the Initialization()
function is called to set up the dsPIC33. First, interrupt nesting is configured in order to
disable the user interrupts by putting the MCU priority at 7 (maximum). External interrupt
3 is enabled on the positive edge. The INT3 interrupt is enabled but the priority is set to 6.
Since it is lower than 7, it will not be active until the MCU priority is decreased to less than
6. The MCU uses the FRC (7.37 MHz) with PLL. The clock on the MCU will be 80 MHz,
the maximum frequency for dsPIC33, at which the computing power is 40 MIPS.
Timer2 is placed on the Output Compare 1 pin (OC1), and is used to generate the
master clock (MCLK) for the MCP3901. In addition, some initial values are set up for
the MCP3901 clock frequency. Timer5 is configured (but not active), and the interrupt
is disabled. The user can enable it for different applications. The SPI peripheral is
configured, but the interrupt is disabled. The SPI interrupt will be enabled in code to
establish the communication between MCU and MCP3901. The UART is used to send
and receive data from the PC at a speed of 115200 baud. Timer8 and Timer9 are
configured to create a 32-bit timer that runs at maximum speed. It is used to measure
the time needed to fill the data buffer, so it measures the sampling speed of the
MCP3901.
After the execution of the Initialization() function, the MCP3901 is configured
with values given by a set of functions especially developed for the MCP3901
configuration. In this case, this step is not necessary because the MCP3901 will update
its configuration using data from the PC GUI. These functions are helpful for users to
develop applications that do not involve a PC to configure the MCP3901.
For example, AddressLoop(NONE) is used to select the loop on specific registers
groups and types. DRHIZ(ON) will allow the data ready pulse to be present at the
output of the MCP3901 even if there is no pull-up resistor. SetGain(1,1) configures
the gain of both channels at 1. A list of all configuration functions are found in the
firmware file, main.c, starting at line 345.
It is important to have interrupts disabled during this configuration. Only after the
MCP3901 is configured using the functions described, can the interrupts be enabled.
In this case, it is done by decreasing the CPU priority to 3.
2010 Microchip Technology Inc.
DS51845B-page 15
MCP3901 ADC Evaluation Board for 16-Bit MCUs User’s Guide
2.2
DATA ACQUISITION
The end of a conversion is indicated with a short high pulse on the Data Ready (DR)
pin of the ADC. The DR pin is connected to the External Interrupt 3 pin and is used for
detecting the end of a conversion on MCP3901. In the INT3 interrupt, the SPI interrupt
is activated and the first transmission on the SPI is initiated. The SPI communication
that follows can be a read of the ADC conversion register or the Configuration register.
CCT = 0 is a read of the ADC Conversion register, and CCT = 1 is a read of the
MCP3901 Configuration register. It is possible to read the ADC conversion registers
and MCP3901 configuration registers at the same time, but due to transfer volume and
its impact on speed, this will prevent achieving a high sampling rate. SPI communication is always in 8-bit mode.
External Interrupt 3 Detected
Clear External Interrupt 3 Flag
Disable External Interrupt 3
Enable SPI1 Interrupt
Tight to GND CS to Select MCP3901
Turn ON Red LED
If CCT = 0
(If true, follows the reading of
the ADC results)
YES
Send on SPI 0b00000001
(Read Address 0 – CH0 MSB)
NO
If CCT = 1
(If true, follows the reading of
the ADC configuration
registers)
YES
Send on SPI 0b00001101
(Read Address 6 – ModOut)
Exit External Interrupt 3
FIGURE 2-1:
INT3 Flowchart.
An SPI interrupt takes place after each successful data transfer between master and
slave on the SPI. As with any interrupt, the first thing to do is to clear the interrupt flag;
otherwise, a new interrupt will occur without reason. The CCSPI global value is the
counter that indicates if the SPI transfer that is occuring is the first, the second, etc.
After saving the samples into the MCU, SPI communication is disabled by setting CS
high. If CCT was ‘0’, then the data that comes from the MCP3901 is ADC conversion
data and will be converted from 3 bytes into an unsigned long number. This 24-bit value
will be saved into the current or voltage buffers.
DS51845B-page 16
2010 Microchip Technology Inc.
Firmware
When the first sample is written in the buffer, the 32-bit timer created using Timer8 and
9, begins counting from 0. When the last sample is written into the buffer, the 32-bit
timer is read. The value indicated will be used to compute the sampling speed.
If the CCT is 1, then the data read from the MCP3901 will be the configuration data.
This will be saved in MCU in other global variables, used later to send this info to the
PC GUI.
After the SPI communication completes, the SPI interrupt will be disabled and the
UART TX interrupt will be enabled. The first character sent on UART is char 33; this is
the header of the UART communication protocol that is adopted here.
SPI1 Transfer Interrupt
Clear Flag;
Read SPI1BUF;
Read Address Loop Bits from
Status Registr
YES
If Address Loop =
NONE?
Send 12 transfers on the SPI to read the content of the 6
registers that are holding the ADC result;
Compute the 24-bit value for each channel and save it in
voltage and current buffers;
At the first sample, read start timer 32-bit Timer8:9;
At the read of the last sample, read the Timer8:9 content
(for sampling speed measurement)
NO
Send 6 transfers on the SPI to read the content of the 6
registers that are holding the ADC result;
Compute the 24-bit value for each channel and save it in
voltage and current buffers;
At the first sample read, start timer 32-bit Timer8:9;
At the read of the last sample, read the Timer8:9 content
(for sampling speed measurement)
Read Modulator Output register;
Read Phase register;
Read Gain register;
Read Status register;
Read Configuration High register;
Read Configuration Low register
Read Modulator Output register;
Read Phase register;
Read Gain register;
Read Status register;
Read Configuration High register;
Read Configuration Low register
Disable SPI interrupt;
Enable UART TX interrupt;
Sent the char 0d33 on UART
Exit SPI Interrupt
FIGURE 2-2:
SPI Routine Flowchart.
2010 Microchip Technology Inc.
DS51845B-page 17
MCP3901 ADC Evaluation Board for 16-Bit MCUs User’s Guide
2.3
UART COMMUNICATION PROTOCOL
The MCU uses the UART to send and receive data to the PC. The TX and RX interrupts
are not used simultaneously in this firmware example, but it is possible to do so, if the
user requires it.
As soon as the buffer is filled with data from the ADC, the SPI interrupt is disabled, and
the TX interrupt is enabled. There are more types of data to be sent from the MCU to
the PC. The first to be sent is the data stored in the buffers. Before being sent, each
number is translated to ASCII characters that represent the number stored in the buffer.
The start of the buffer data transmissions is acknowledged by transmitting the
character: “!”.
The numbers in the current buffer are comma delimited, and each row ends with the
characters “0x0D”. After 512 rows, the buffer data transmission is complete, which is
signaled by sending out the character “D”.
Next, the data regarding the MCP3901 configuration and sampling speed is sent out.
After a total of 35 characters are sent, the MCP3901 configuration data is fully transmitted, which is signaled by sending the character “;” to the PC. This character also
signals that the result of an FFT computation will be sent out next.
In the last UART TX interrupt, the TX interrupt is disabled and the RX interrupt is
enabled. Through the RX interrupt, the MCU will receive the configuration for the
MCP3901 desired by the user. The protocol is simple. The first character received must
be “D” from configuration data. Following this character will be the values of 6 registers:
PHASE, GAIN, CONFIGH, CONFIGL, STATUS, PPREG8. The first 5 registers can
hold values from 0 to 255, so they are made up of a maximum 3 characters. If the equivalent number is less than 100, the first character will be the space character (“ ”), not
zero. The PREG8 register is a 16-bit register inside the MCU that controls the frequency of the clock signal from OC1, which controls the sampling speed of the
MCP3901. Since it is a 16-bit register, the number of characters that create the correct
value is 5.
DS51845B-page 18
2010 Microchip Technology Inc.
Firmware
UART TX Interrupt
contrd