Spi ADC Issues.

Thread Starter


Joined Feb 8, 2012
I've been trying to get this adc to work for the past 2 weeks, without any luck. I found some code for mikroc for pic that works with the ltc2400 http://www.kmitl.ac.th/~kswichit/PICprojectboard/PICProjectBoard.c, but I've been having a devil of a time getting it to work. here is the code I've been trying to work. Anyone have an idea why I'm getting nothing from the adc.

Rich (BB code):
// PIC Project Board
// PIC18F2550 + LTC2400 + LCD + USB
// Sample code demonstrates the use of sigma-delta converter.
// The program prints analog input 0-2.5V on LCD in micro Volts unit
// source code was compiled with Mikro-C compiler
// Copyright 2006 Wichit Sirichote, kswichit@kmitl.ac.th

//#define ADC_CS1 PORTC.F0   // output bit
//#define ADC_SDO PORTC.F1  // input bit
//#define ADC_SCK PORTC.F2  // output bit
sbit ADC_CS1 at LATB3_bit;
sbit ADC_SDO at LATG7_bit;
sbit ADC_SCK at LATG6_bit;
sbit ADC_CS1_Direction_bit at TRISB3_bit;
sbit ADC_SDO_Direction_bit at TRISG7_bit;
sbit ADC_SCK_Direction_bit at TRISG6_bit;

char *text = "PICProject Board";
char buffer[20];
long d;

unsigned long x1,x2,x3,x4,x5;

/* read 32-bit data from LTC2400 */

unsigned long read_ADC1(void)
   char k;
   long n;
   n= 0;
   ADC_CS1 = 0;
   for(k=0; k<32; k++)
         n<<= 1;
     ADC_SCK = 1;
     n |= ADC_SDO;
         ADC_SCK = 0;
        ADC_CS1 = 1;
         n&=0x01fffffff; // maskout sign bit
         n>>=4;   // get 24-bit conversion result
     return n;

/* 5-point moving average */
// return data that scaled with reference voltage in uV unit
unsigned long filter_ADC(void)
    x5 = x4;
    x4 = x3;
    x3 = x2;
    x2 = x1;
    x1 = read_ADC1();
    return ((((x1+x2+x3+x4+x5)/5)*148)/100); // x 149 E-9 convert to 2.479V

void main() {
TRISB3_bit = 0;
TRISG6_bit = 0;
TRISG7_bit = 1;
CHECON = 0x32;

  //PORTC.F7 ^= 1;
  d = filter_ADC();
  sprintl(buffer,"%08ld x0.1%cV",d,0xe4);


Last edited by a moderator:


Joined Dec 23, 2011
I've used this chip before. What sorts of results are you getting? I know the data had to be shifted once retrieved.