An88 – Cirrus Logic AN88 User Manual

Page 2

Advertising
background image

AN88

2

AN88Rev2

a block diagram overview. While reading this ap-
plication note, please refer to the Appendix for the
code listing.

Initialize

Initialize is a subroutine that configures Port A
(RA) on the PIC16F84 and places the CS5525/6/9
in the command-state. First, RA’s data direction is
configured as depicted in Figure 1 (for more infor-
mation on configuring ports refer to Microchip’s
PIC16F8X Data Sheet). After configuring the port,
the controller enters a delay state to allow time for
the CS5525/6/9’s power-on-reset and oscillator to
start-up (oscillator start-up time is typically 500
ms). The last step is to reinitialize the serial port on
the ADC (reinitializing the serial port is unneces-
sary here, it was added for demonstration purposes
only). This is implemented by sending the convert-
er sixteen bytes of logic 1’s followed by one final
byte, with its LSB logic 0. Once sent, the sequence
places the serial port of the ADC into the com-
mand-state, where it awaits a valid command.

After returning to main, the software demonstrates
how to calibrate the converter’s offset.

Self-Offset Calibration

Calibrate is a subroutine that calibrates the con-
verter’s offset. Calibrate first sends 0x000001
(Hex) to the configuration register. This instructs
the converter to perform a self-offset calibration.
Then the Done Flag (DF) bit in the configuration
register is polled until set. Once DF is set, it indi-
cates that a valid calibration was performed. To
minimize digital noise (while performing a calibra-
tion or a conversion), many system designers may
find it advantageous to add a software delay equiv-
alent 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 ac-
complished by the MOVLW and MOVWF op-
codes. The subroutine write_register uses these
variables to set the contents of the gain register 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 additional times for the 24 bits 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 transferred one bit at a time, MSB (most
significant bit) first, by placing an information bit
on RA1 (SDI) and then pulsing RA3 (SCLK). This
process is repeated eight times. Figure 3 depicts the
timing diagram for the write-cycle in the CS5525/
6/9’s serial port. This algorithm demonstrates how
to write to the gain register. It does not perform a
gain calibration. To perform a gain calibration, fol-
low the procedures outlined in the data sheet.

To verify if 0x800000 (HEX) was written to the
gain register, read_register is called. It duplicates
the read-cycle timing diagram depicted in Figure 4.
Read_register first asserts CS and then calls
send_spi once to transfer the command-byte to the
CS5525/6/9. This places the converter into the

START

INITIALIZE

SELF-OFFSET CAL.

MODIFY GAIN

ACQUIRE CONVERSION

MICROCONTROLLER/CS5525/6/9

Figure 2. CS5525/6/9 Software Flowchart

Advertising