
LTC2435/LTC2435-1
38
24351fc
applicaTions inForMaTion
// Basic data collection program for the LTC2435 using the
// PIC16F73 microcontroller. Collects data as fast as possible
// and sends it out the serial port at 57600 baud as six
// hexadecimal characters, followed by a carriage return.
// This can be captured with a terminal program and analyzed
// with a spreadsheet using the HEX2DEC function (in Excel.)
//
// Written for the CCS compiler, version 3.049.
////////////////////////////////////////////////////////////////////
#include <16F73.h>
#byte SSPCON = 0x14
// Synchronous serial port control
#byte SSPSTAT = 0x94
// registers.
#bit CKE = SSPSTAT.6
#bit CKP = SSPCON.4
#bit SSPEN = SSPCON.5
#fuses HS,NOWDT,PUT
#use delay(clock=10000000)
// For baud rate calculation.
#use rs232(baud=57600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
// Serial data is sent on pin C6.
#define CS_ PIN_C2
// Chip select connected to pin C2
#define CLOCK PIN_C
// Clock connected to pin C3
#define SDO PIN_C4
// SDO on the LTC2435 connected to pin C4
// (this is SDI on the PIC;
// Master In, Slave Out (MISO) is less ambiguous)
void main() {
// Basic configuration, no bearing on operation of LTC2435
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
// LTC2435 is connected to the processor’s hardware SPI port.
// This sets the port such that data is shifted on clock falling edges and
// valid on rising edges. For a 10 MHz master clock, the SPI clock frequency
// will be 2.5 MHz.
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4|SPI_SS_DISABLED);
CKP = 0; // Set up clock edges - clock idles low, data changes on
CKE = 1; // falling edges, valid on rising edges.
while(1)
{
output_low(CS_);
// Enable LTC2435
while(input(SDO)) { /* Wait for SDO to fall, indicating end of conversion.*/ }
printf(“%2X”,spi_read(0));
// Read first byte, send 2 hex characters.
printf(“%2X”,spi_read(0));
// Read second byte, send 2 hex characters.
printf(“%2X”,spi_read(0));
/ Read third byte, send 2 hex characters.
printf(“\r”);
// Send carriage return.
output_high(CS_);
// Conversion actually started after last data byte was read,
// but raising CS_ ensures the loop will never lock up waiting for
// a low on SDO if a clock pulse is missed for some reason.
}
Figure 43. A Sample Program for Data Collection from the LTC2435/LTC2435-1
Using the PIC16F73 Microcontroller.