Spi ADC Issues.

Discussion in 'Embedded Systems and Microcontrollers' started by house91320, Feb 11, 2012.

  1. house91320

    Thread Starter New Member

    Feb 8, 2012
    5
    0
    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.

    Code ( (Unknown Language)):
    1.  
    2. // PIC Project Board
    3. // PIC18F2550 + LTC2400 + LCD + USB
    4. // Sample code demonstrates the use of sigma-delta converter.
    5. // The program prints analog input 0-2.5V on LCD in micro Volts unit
    6. // source code was compiled with Mikro-C compiler
    7. // Copyright 2006 Wichit Sirichote, [email]kswichit@kmitl.ac.th[/email]
    8.  
    9. //#define ADC_CS1 PORTC.F0   // output bit
    10. //#define ADC_SDO PORTC.F1  // input bit
    11. //#define ADC_SCK PORTC.F2  // output bit
    12. sbit ADC_CS1 at LATB3_bit;
    13. sbit ADC_SDO at LATG7_bit;
    14. sbit ADC_SCK at LATG6_bit;
    15. sbit ADC_CS1_Direction_bit at TRISB3_bit;
    16. sbit ADC_SDO_Direction_bit at TRISG7_bit;
    17. sbit ADC_SCK_Direction_bit at TRISG6_bit;
    18.  
    19. char *text = "PICProject Board";
    20. char buffer[20];
    21. long d;
    22.  
    23. unsigned long x1,x2,x3,x4,x5;
    24.  
    25.  
    26.  
    27. /* read 32-bit data from LTC2400 */
    28.  
    29. unsigned long read_ADC1(void)
    30. {
    31.    char k;
    32.    long n;
    33.    n= 0;
    34.    ADC_CS1 = 0;
    35.    for(k=0; k<32; k++)
    36.    {
    37.          n<<= 1;
    38.      ADC_SCK = 1;
    39.      n |= ADC_SDO;
    40.          ADC_SCK = 0;
    41.     }
    42.         ADC_CS1 = 1;
    43.          n&=0x01fffffff; // maskout sign bit
    44.          n>>=4;   // get 24-bit conversion result
    45.      return n;
    46. }
    47.  
    48. /* 5-point moving average */
    49. // return data that scaled with reference voltage in uV unit
    50. unsigned long filter_ADC(void)
    51. {
    52.     x5 = x4;
    53.     x4 = x3;
    54.     x3 = x2;
    55.     x2 = x1;
    56.     x1 = read_ADC1();
    57.     return ((((x1+x2+x3+x4+x5)/5)*148)/100); // x 149 E-9 convert to 2.479V
    58. }
    59.  
    60.  
    61. void main() {
    62. UART1_Init(9600);
    63. TRISB3_bit = 0;
    64. TRISG6_bit = 0;
    65. TRISG7_bit = 1;
    66. CHECON = 0x32;
    67. AD1PCFG = 0xFFFF;
    68. UART_Write_Text(text);
    69.  
    70.   while(1)
    71.   {
    72.   //PORTC.F7 ^= 1;
    73.   d = filter_ADC();
    74.   sprintl(buffer,"%08ld x0.1%cV",d,0xe4);
    75.   UART_Write_text(buffer);
    76.   Delay_ms(200);
    77.  
    78.   }
    79.  
    80. }
    81.  
     
    Last edited by a moderator: Feb 11, 2012
  2. PaulEE

    Member

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