This applica tion note details the interfac e of Crys-
tal Semiconductor’s CS5525/6/9 Analog-to-Digital Converter (ADC) to the Microchip PIC16
microcontroller series. This note takes the reader
through a sim ple e xa mpl e desc ribin g h ow to co mmunicate w ith the ADC. All algo rithms discussed
are included in the Appendix at the end of this
note.
ADC DIGITAL INTERFACE
The CS5525/6/9 interfaces to the PIC16F84
through either a three-wire or a four-wire interface.
Figure 1 depict s the inte rface be tween the two devices. Though this software was written to interface to Port A (RA) on th e PIC16F 84 with a four wire interfa ce, the algorit hms can be easily modified to work with the three-wire format.
The ADC’s serial port consists of four control
lines: CS
CS
, SCLK, SDI, and SDO.
, Chip S elect, is the contro l line w hich e nables
access to the serial port.
SCLK, Serial Clock, is the bit-clock which controls
the shifting of data to or from the ADC’s serial
port.
SDI, Serial Data In, is the data signal used to transfer data from the PIC16F84 to the ADC.
SDO, Serial Data Out, is the data signal used to
transfer output data from the ADC to the
PIC16F84.
SOFTWARE DESCRIPTION
This note presents algorithms to initialize the
PIC16F84 and the CS5525/6/9, perform a se l f-offset calibratio n, modi fy the C S5525/ 6/9 gai n register, and then acquire a conversion. Figure 2 depicts
CS5525/6/9PIC16F84
CS
SDI
SDO
SCLK
Cirrus Logic, Inc.
Crystal Semiconductor Products Division
a block diagra m overview. While readi ng this application note, please refer to the Appendix for the
code listing.
Initialize
Initialize is a subroutine that configures Port A
(RA) on the PIC1 6F84 a nd place s the C S5525/ 6/9
in the command-state. First, RA’s data direction is
configured as dep ic te d i n Figure 1 (for more infor mation on configuring ports refer to Microchip’s
PIC16F8X Data Sheet). After configuring the port,
the control ler en te rs a de lay st ate t o al low tim e fo r
the CS5525/6 /9’s power-on-re set and oscillato r to
start-up (oscillator start-up time is typically 500
ms). The last step is to reinitialize the serial port on
the ADC (r einitializing t he serial port is unnecessary here, it was added for demonstration purposes
only). This is implemented by sending the converter sixteen byte s of logic 1’s foll owed by one fin al
byte, with its LSB logic 0. Once sent, the sequence
places the serial port of the ADC into the command-state, where it aw aits a valid command.
After returning to main, the software demo nstrates
how to calibra te the convert er’s offset.
START
INITIALIZE
MICROCONTROLLER/CS5525/6/9
SELF-OFFSET CAL.
MODIFY GAIN
ACQUIRE CONVERSION
Figure 2. CS5525/6/9 Software Flowchart
Self-Offset Calib r ation
Calibrate is a subroutine that calibrates the converter’s offset. Calibrate first sends 0x000001
(Hex) to the conf iguration register. This i nstructs
the converter to perform a self-offset calibration.
Then the Done Flag (D F) bit in th e configuration
register i s polled until set. Onc e DF is set, it indicates that a valid calibration was performed. To
minimize digital noise (while performing a calibration or a c onver sion ), ma ny sy ste m d esigners may
find it advantageous to add a software delay equivalent to a conversion or calibration cycle before
polling the DF bit.
Read/Write Gain Register
To modify the gain register the command-byte and
data-byte variables are first initialized. This is accomplished by the MOVLW and MOVWF opcodes. The subroutine write_register uses these
variables to set th e conten ts of the gain regi ster in
the CS5525/6/9 to 0x800000 (HEX). To do this,
write_register first asserts CS
and then it calls
send_spi four times (once for the command-byte
and three a dditional times for t he 24 bit s of data).
Send_spi is a subroutine used to ‘bit-bang’ a byte of
information from the PIC16F84 to the CS5525/6/9.
A byte is tra nsferre d one bit at a time , MSB (most
significan t bit) first, by placing an info rmation b it
on RA1 (SDI) and then pulsing RA3 (SCLK). This
process is repeated eight times. Figure 3 depicts the
timing diag ram for t he write-c ycle in the CS5525/
6/9’s serial port. Th is al gorit hm de mo nstrat es how
to write to the g ain register . It doe s not pe rform a
gain calibration. To perform a gain calibration, follow the procedu r es ou tlined in the data shee t.
To verify if 0x800000 (HEX) was written to the
gain register, read_register is call ed. It dup licates
the read-cycle timing diagram depicted in Figure 4.
Read_register first asserts CS
and then calls
send_spi once to transfe r the com ma nd- byte to the
CS5525/6/9. This places the converter into the
2AN88Rev2
AN88
data-state where it wa its unt il data is rea d from its
serial port. To re ceiv e th e da ta, read_register ca ll s
receive_spi th ree times. Receive_sp i is a subroutine
used to ‘bit-ba ng’ a byte of informa tion from the
ADC to the PIC16F84. Similar to send_spi,receive_spi acquires this information one bit at a
time MSB first. When the transfer is complete, the
variables high byte, midbyte, and lowbyte contain
the CS5525/6/ 9’s 24-bit gain registe r.
Acquire Conversion
To acquire a c onversion the subroutine convert is
called. Convert se nds the command-byte 0x0 C to
the convert er. This instructs the converter to perform a single conversion. Then the Done Flag (DF)
bit in the configuration register is polled. When set,
DF indicates that a conversion was performed.
Once DF is s et, the cont roller reads the conve rs ion
data register to acquire the conversion.Figure 6 depicts how 16-bit and 2 0-bit conversion words are
stored in th e microcontroller.
An alternate m ethod ca n be used to acquire a conversion. By se tting the Port Flag bit (PF, the fifth
bit in the configuration register), SDO’s function is
modified to fall to logic 0 when a conversion is
complete (refer to Fi gure 5). By tying SDO t o the
controller’s interrupt pin, conversions can be acquired via an interrupt service routine.
Figure 3. Write-Cycle Timing
Figure 4. Read-Cycle Timing
AN88Rev23
SCLK
SDI
*
t
ommand Time
C
8SCLKs
DO
S
td = XIN/OWR clock cycles for each conversion except the
*
first conversion whichwilltakeXIN/OWR+ 7 clockcycles
Figure 5. Conversion/Acquisition Cycle with the PF Bit Asserted
d
Data SDO Continuous Conversion Read (PF bit = 1)
SCLKs Clear SDO Flag
8
AN88
IN/OWR
X
Clock Cycles
SB
M
ataTime
D
24 SCLKs
SB
L
MSBHigh-Byte
D19D18D17D16D15D14D13D12
Mid-Byte
D11D10D9D8D7D6D5D4
Low-Byte
D3D2D1D000ODOF
A) 20-Bit Conversion Data Word
MSB High-Byte
D15D14D13D12D11D10D9D8
Mid-Byte
D7D6D5D4D3D2D1D0
Low-Byte
111100ODOF
B) 16-Bit Conversion Data Word
0- always zero, 1
OD - Oscillation Detect, OF - Overflow
Figure 6. Bit Representation/Storage in PIC16F84
- always one,
MAXIMUM SCLK RATE
A machine cyc le in the PIC16F84 c onsists 4 oscil-
lator periods o r 400 ns i f the mic rocontrol ler’s os cillator frequency is 10 MHz. Sinc e the CS5525/6/
9’s maximum SCLK ra te is 2MHz, additiona l no
operation (NOP) delays may be necessary to reduce the tr ansfer rate if the micro controller s ys tem
requires higher ra te oscillators.
SERIAL PERIPHERAL INTERFACE
The Serial Peripheral Interface (SPI) developed for
Microchip’s controllers wasn’t designed to be as
flexible as the SPI port on Motorola’s 68HC05. To
get the Micr ochip’s SPI port to functi on with the
CS5525/6/9, th e port n ee ds to be ini tia lized t o id le
high, and th e CS55 25/6/9’s se rial po rt needs to be
reset anytime information is transmitted between
the microcontroller and th e c onverter.
DEVELOPMENT TOOL DESCRIPTION
The code in this a ppl ication note was developed
TM
using MPLAB
development pa cka ge from Microchip, Inc .
4AN88Rev2
, an integrated software
AN88
CONCLUSION
This applicat ion note prese nts an example of how
to interface t he CS5525/6/9 to the PIC16 F84. It is
divided into two main sec ti ons: har dware and software. The hardware section illustrates both a threewire and a four-wire interface. The three-wire is
TM
SPI
and MICROWIRE
ware, develope d w ith dev elopme nt to ols fro m Microchip, Inc., illustrates how to initialize the
converter and microcontroller, calibrate the con-
TM
compat ible. The soft-
verters offset, write to and read from the ADC’s internal register, and acquire a conversion. The
software is modularized and illustrates important
subroutines, e .g. wr ite_ regi ste r and read _register.
The softwa re described in the no te is included in
the Appendix at the end of this do cument.
SPITM is a trademark of Motorola.
MICROWIRE
MPLAB
TM
is a trademark of National Semiconductor.
TM
is a trademark of Microchip.
AN88Rev25
Loading...
+ 9 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.